\ ANSI Terminal codes \ Copyright (C) 2000 Alex Malyshev (alexript@mail.ru) \ This is free software; you can redistribute it and/or \ modify it under the terms of the GNU General Public License \ as published by the Free Software Foundation; either version 2 \ of the License, or (at your option) any later version. \ This program is distributed in the hope that it will be useful, \ but WITHOUT ANY WARRANTY; without even the implied warranty of \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \ GNU General Public License for more details. \ You should have received a copy of the GNU General Public License \ along with this program; if not, write to the Free Software \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. \ needed vt100.fs uses StartUp uses Ext.const uses Ext.tools uses Ext.comment uses TTY.terminal base @ decimal CONSTS Terminal Colors ANSI:Black 30 ANSI:Red 31 ANSI:Green 32 ANSI:Yellow 33 ANSI:Blue 34 ANSI:Brown 35 ANSI:Cyan 36 ANSI:White 37 ; CONSTS Terminal Attributes ANSI:Normal 0 ANSI:Bold 1 ANSI:Underline 4 ANSI:Italic 3 ANSI:Blink 5 ANSI:FastBlink 6 ANSI:Invers 7 ANSI:Shadow 8 ; base ! create [attr] 0 c, 0 c, 0 c, : ANSI:saveattr ( fg bg attr --- ) [attr] 2+ c! [attr] 1+ c! [attr] c! ; : ANSI:restattr ( -- fg bg attr ) [attr] c@ [attr] 1+ c@ [attr] 2+ c@ ; : ANSI:CurPos ( x y -- ) \ cursor position at-xy ; : ANSI:SaveCurPos ( -- ) ESC[ [char] s emit ; : ANSI:RestoreCurPos ( -- ) ESC[ [char] u emit ; : ANSI:CursorUp ( Pn -- ) \ cursor up ESC[ pn [char] A emit ; : ANSI:CursorDown ( Pn -- ) \ cursor down ESC[ pn [char] B emit ; : ANSI:CursorForward ( Pn -- ) \ cursor forward ESC[ pn [char] C emit ; : ANSI:CursorBack ( Pn -- ) \ cursor back ESC[ pn [char] D emit ; : ANSI:CRLF ( Pn -- ) ESC[ pn [char] E emit ; : ANSI:ReverseCRLF ( Pn -- ) ESC[ pn [char] F emit ; : ANSI:nEL ( Pn -- ) \ erase line ESC[ pn [char] K emit ; : ANSI:EraseLine \ Erase Line 0 ANSI:nEL ; : ANSI:DeleteTC \ Deletes current cursor position to beginning of line 1 ANSI:nEL ; : ANSI:DeleteLine \ Deletes current line containing cursor 2 ANSI:nEL ; : ANSI:nEC ESC[ pn [char] J emit ; : ANSI:EraseCE \ Erase from cursor to end of screen 0 ANSI:nEC ; : ANSI:EraseBC \ Erase from beginning of screen to cursor 1 ANSI:nEC ; : ANSI:EraseDisplay \ Erase Display page ; : ANSI:InsSPACES ( n -- ) ESC[ pn [char] @ emit ; : ANSI:DelCHARS ( n -- ) ESC[ pn [char] P emit ; : ANSI:InsLINES ( n -- ) ESC[ pn [char] L emit ; : ANSI:DelLINES ( n -- ) ESC[ pn [char] M emit ; : ANSI:InsMode ( f -- ) ESC[ [char] 4 emit IF [char] h emit ELSE [char] l emit THEN ; : BG ( color -- color+10 ) base @ swap 10 + swap base ! ; : ANSI:SetColor ( color -- ) ESC[ pn [char] m emit ; : ANSI:SetFG ( color -- ) dup [attr] c! ANSI:SetColor ; : ANSI:SetBG ( color -- ) BG dup [attr] 1+ c! ANSI:SetColor ; : ANSI:SetFGBG ( FGcolor BGcolor -- ) BG 2dup [attr] 1+ c! [attr] c! ESC[ pn ;pn [char] m emit ; : ANSI:SetAttr ( attr -- ) [attr] 2+ c@ OR DUP [attr] 2+ c! ANSI:SetColor ; : ANSI:UnSetAttr ( attr -- ) [attr] 2+ c@ XOR DUP [attr] 2+ c! ANSI:SetColor ; CREATE ANSI:DEFATTR ANSI:White C, ANSI:Black BG C, ANSI:Normal C, : ANSI:GetDefAttr ANSI:DEFATTR C@ ANSI:DEFATTR 1+ C@ ANSI:DEFATTR 2+ C@ ; : ANSI:SetDefAttr ANSI:DEFATTR 2+ C! ANSI:DEFATTR 1+ C! ANSI:DEFATTR C! ; : ANSI:.DefAttr ANSI:GetDefAttr 3DUP ANSI:saveattr ESC[ pn ;pn ;pn [char] m emit ; : ANSI:.Attr 3dup ANSI:saveattr ANSI:DEFATTR 2+ c@ ESC[ pn ;pn ;pn ;pn [char] m emit ; : ANSI:.AttrString ( addr u fg bg attr -- ) SWAP BG SWAP ANSI:restattr { fg bg attr } ANSI:.Attr TYPE fg bg attr ANSI:.Attr ; : ANSI:TTYClose ANSI:GetDefAttr ANSI:saveattr ANSI:.DefAttr ANSI:EraseDisplay TerminalInit ; : ANSI:Init TerminalInit ['] ANSI:Black IS Black ['] ANSI:Red IS Red ['] ANSI:Green IS Green ['] ANSI:Yellow IS Yellow ['] ANSI:Blue IS Blue ['] ANSI:Brown IS Brown ['] ANSI:Cyan IS Cyan ['] ANSI:White IS White ['] ANSI:Normal IS Normal ['] ANSI:Bold IS Bold ['] ANSI:Underline IS Underline ['] ANSI:Italic IS Italic ['] ANSI:Blink IS Blink ['] ANSI:FastBlink IS FastBlink ['] ANSI:Invers IS Invers ['] ANSI:Shadow IS Shadow ['] ANSI:CurPos IS CurPos ['] ANSI:SaveCurPos IS SaveCurPos ['] ANSI:RestoreCurPos IS RestoreCurPos ['] ANSI:CursorUp IS CursorUp ['] ANSI:CursorDown IS CursorDown ['] ANSI:CursorForward IS CursorForward ['] ANSI:CursorBack IS CursorBack ['] ANSI:CRLF IS .CR ['] ANSI:ReverseCRLF IS ReverseCR ['] ANSI:EraseLine IS EraseLine ['] ANSI:DeleteTC IS DeleteTC ['] ANSI:DeleteLine IS DeleteLine ['] ANSI:EraseCE IS EraseCE ['] ANSI:EraseBC IS EraseBC ['] ANSI:EraseDisplay IS EraseDisplay ['] ANSI:InsSpaces IS InsSpaces ['] ANSI:DelChars IS DelChars ['] ANSI:InsLines IS InsLines ['] ANSI:DelLines IS DelLines ['] ANSI:InsMode IS InsMode ['] ANSI:SetBG IS SetBG ['] ANSI:SetFG IS SetFG ['] ANSI:SetFGBG IS SetFGBG ['] ANSI:SetAttr IS SetAttr ['] ANSI:UnSetAttr IS UnSetAttr ['] ANSI:GetDefAttr IS GetDefAttr ['] ANSI:SetDefAttr IS SetDefAttr ['] ANSI:.DefAttr IS .DefAttr ['] ANSI:.AttrString IS .AttrString ['] ANSI:TTYClose IS TTYClose ANSI:GetDefAttr ANSI:saveattr ANSI:.DefAttr ANSI:EraseDisplay ; /* : test EraseDisplay 20 10 CurPos Blue Green SetFGBG Bold Blink OR SetAttr ." Hello, World!" .DefAttr CR ; ANSI:Init test */
Make your own free website on Tripod.com