/* This code is provided by Loîc Berthelot, Scol language developer until 2005 */ /* You can make what you want with this source code, provided "AS IT" without guarantee */ var CONSOLE_HIDE_LINENUM = 0;; var CONSOLE_SHOW_LINENUM = 1;; struct CONSOLE = [ win_CSL : ObjWin, // console window txt_CSL : S, // content objtxt_CSL : ObjText, // 2d text object font_CSL : ObjFont, // font object flag_CSL : I // flag ] mkCONSOLE;; typeof lastcsl = CONSOLE;; // console object var LINECOUNT = 0;; // initial line count = 0 /* When the console window is destroyed, font and text object are destroyed before the window */ fun console_destroy (a, csl) = _DSfont csl.font_CSL; _DStext csl.objtxt_CSL; 1;; fun console_resize (win, csl, w, h) = let _GETtextPositionSize csl.objtxt_CSL -> [x y _ _] in _SIZEtext csl.objtxt_CSL (w-20) (h-20) x y; 1;; fun console_getLineNum () = let if (LINECOUNT < 10) then strcat strcat " " (itoa LINECOUNT) " : " else if (LINECOUNT < 100) then strcat strcat " " (itoa LINECOUNT) " : " else strcat (itoa LINECOUNT) " : " -> linenum in ( set LINECOUNT = LINECOUNT+1; linenum; );; fun console_clear (csl) = let if (csl == nil) then lastcsl else csl -> csl in ( set csl.txt_CSL = ""; _SETtext csl.objtxt_CSL csl.txt_CSL; );; /* print a message in the console */ fun console_print (csl, msg) = let if (csl == nil) then lastcsl else csl -> csl in ( if ((csl.flag_CSL == CONSOLE_SHOW_LINENUM) || (csl.flag_CSL == nil)) then set csl.txt_CSL = strcat strcat strcat csl.txt_CSL "\n" console_getLineNum msg else set csl.txt_CSL = strcat csl.txt_CSL msg; _SETtext csl.objtxt_CSL csl.txt_CSL; _SCROLLtext csl.objtxt_CSL 0 (_GETlineCount csl.objtxt_CSL)-1; ); 1;; /* create the console window : x, y : its position on the screen w, h : its width and its height flag : CONSOLE_HIDE_LINENUM ot CONSOLE_SHOW_LINENUM the new console object is returned */ fun console_create (x, y, w, h, flag) = let mkCONSOLE [nil nil nil nil flag] -> csl in ( set csl.win_CSL = _CRwindow _channel nil x y w h WN_MENU|WN_SIZEBOX|WN_MINBOX "console"; _CBwinDestroy csl.win_CSL @console_destroy csl; _CBwinSize csl.win_CSL @console_resize csl; set csl.font_CSL = _CRfont _channel 12 0 FF_WEIGHT "arial"; set csl.objtxt_CSL = _CRtext _channel csl.win_CSL 10 10 w-20 h-20 ET_AHSCROLL|ET_AVSCROLL|ET_ALIGN_LEFT|ET_BORDER|ET_HSCROLL|ET_VSCROLL nil; set lastcsl = csl; csl; );; fun main ()= _showconsole; console_create 50 50 500 300 CONSOLE_SHOW_LINENUM; let 50 -> counter in while counter >= 0 do ( console_print nil strcat "count : " itoa counter; set counter = counter-1; ); 0;;