hello,
I'm using gnu-forth currently as interpreter,
I use escape sequences for coloration of strings in terminal with a
decimal
27 constant ESC \ to manage escape sequences used as colorations
: COLORIZE ESC EMIT ." [" base @ >R 0 <# #S #> type R> base ! ." m" ; \ ASCII TERMINAL
so I can use it as
31 colorize ." print something" 0 colorize
for example.
is this a good method for my xterm compatibles ascii-terminals ?
is there a better way to do so ?
hello,
I'm using gnu-forth currently as interpreter,
I use escape sequences for coloration of strings in terminal with a
decimal
27 constant ESC \ to manage escape sequences used as colorations
: COLORIZE ESC EMIT ." [" base @ >R 0 <# #S #> type R> base ! ." m" ; \ ASCII TERMINAL
so I can use it as
31 colorize ." print something" 0 colorize
for example.
is this a good method for my xterm compatibles ascii-terminals ?
is there a better way to do so ?
gobli...@gmail.com schrieb am Mittwoch, 3. Mai 2023 um 20:48:33 UTC+2:
hello,
I'm using gnu-forth currently as interpreter,
I use escape sequences for coloration of strings in terminal with a
decimal
27 constant ESC \ to manage escape sequences used as colorations
: COLORIZE ESC EMIT ." [" base @ >R 0 <# #S #> type R> base ! ." m" ; \ ASCII TERMINAL
so I can use it as
31 colorize ." print something" 0 colorize
for example.
is this a good method for my xterm compatibles ascii-terminals ?This is a rather subjective question. If it is good enough for you, it is good.
is there a better way to do so ?
FWIW sometimes I use
\ : BOUNDS over + swap ;
\ : ESC[ 27 emit '[' emit ;
VARIABLE _VT \ Virtual/ANSI terminal enabled flag
-1 _VT !
: __VTSET \ ( n..1 a u -- ) set VT through string (^=ESC[, ~=number)
base @ >r decimal bounds ?DO i c@
dup '^' = IF drop esc[ ELSE
dup '~' = IF drop 0 .r ELSE
emit THEN THEN
LOOP r> base ! ;
: PAGE \ ( -- ) 10.6.1.2005 clear terminal screen
_vt @ IF s" ^2J^H" __vtset THEN ;
: AT-XY \ ( col row -- ) 10.6.1.0742 set text cursor coordinates
_vt @ IF 1+ swap 1+ swap s" ^~;~f" __vtset THEN ;
: SAVE-XY \ ( -- ) MF save cursor coordinates to memory
_vt @ IF esc[ 's' emit THEN ;
: RESTORE-XY \ ( -- ) MF restore cursor coordinates from memory
_vt @ IF esc[ 'u' emit THEN ;
: __VTCHAR \ ( n -- ) MF set terminal character attribute
_vt @ IF s" ^~m" __vtset ELSE drop THEN ;
\ text attributes
: VTNORMAL 0 __vtchar ; \ ( -- ) MF
: VTBRIGHT 1 __vtchar ; \ ( -- ) MF
: VTUNDERLINE 4 __vtchar ; \ ( -- ) MF
: VTREVERSE 7 __vtchar ; \ ( -- ) MF
: VTHIDDEN 8 __vtchar ; \ ( -- ) MF
\ text colors
: VTBLACK 30 __vtchar ; \ ( -- ) MF
: VTRED 31 __vtchar ; \ ( -- ) MF
: VTGREEN 32 __vtchar ; \ ( -- ) MF
: VTYELLOW 33 __vtchar ; \ ( -- ) MF
: VTBLUE 34 __vtchar ; \ ( -- ) MF
: VTMAGENTA 35 __vtchar ; \ ( -- ) MF
: VTCYAN 36 __vtchar ; \ ( -- ) MF
: VTWHITE 37 __vtchar ; \ ( -- ) MF
\ move cursor
: VTUP _vt @ IF s" ^~A" __vtset THEN ; \ ( n -- ) MF
: VTDOWN _vt @ IF s" ^~B" __vtset THEN ; \ ( n -- ) MF
: VTRIGHT _vt @ IF s" ^~C" __vtset THEN ; \ ( n -- ) MF
: VTLEFT _vt @ IF s" ^~D" __vtset THEN ; \ ( n -- ) MF
\ test
CR vtcyan vtbright ." !! BELLA ITALIA !!" vtreverse
CR vtgreen 18 spaces
CR vtwhite 18 spaces
CR vtred 18 spaces
CR vtwhite vtnormal
hello,
I'm using gnu-forth currently as interpreter,
I use escape sequences for coloration of strings in terminal with a
decimal
27 constant ESC \ to manage escape sequences used as colorations
: COLORIZE ESC EMIT ." [" base @ >R 0 <# #S #> type R> base ! ." m" ; \ ASCII TERMINAL
so I can use it as
31 colorize ." print something" 0 colorize
for example.
is this a good method for my xterm compatibles ascii-terminals ?
is there a better way to do so ?
regards.
I created a kind of "markup" for the VT100 commands
These might provide some ideas for you.
https://github.com/bfox9900/CAMEL99-ITC/blob/master/LIB.ITC/VT100.FTH https://github.com/bfox9900/CAMEL99-ITC/blob/master/LIB.ITC/VT100COLR.FTH
On Wednesday, May 3, 2023 at 2:48:33=E2=80=AFPM UTC-4, gobli...@gmail.com w= >rote:
decimal=20Maybe I'm missing something, or don't understand BASE. I thought it is the=
27 constant ESC \ to manage escape sequences used as colorations=20
: COLORIZE ESC EMIT ." [" base @ >R 0 <# #S #> type R> base ! ." m" ; \ A= ...
address where the number conversion base is stored. You save it on the re=
turn stack, then restore it after printing the number, but I don't see wher= >e you change it. So why save and restore if you are not going to change it= >?=20
Also, at the very beginning, you change the value stored at BASE to 10 with=
the word decimal. Is that intentional? the word decimal is not going to =
have any impact if BASE is changed elsewhere in the code, before colorize i= >s called.=20
What am I missing?=20
hello,
I'm using gnu-forth currently as interpreter,
I use escape sequences for coloration of strings in terminal with a
decimal
27 constant ESC \ to manage escape sequences used as colorations
: COLORIZE ESC EMIT ." [" base @ >R 0 <# #S #> type R> base ! ." m" ; \ ASCII TERMINAL
so I can use it as
31 colorize ." print something" 0 colorize
for example.
is this a good method for my xterm compatibles ascii-terminals ?
is there a better way to do so ?
hello,
I'm using gnu-forth currently as interpreter,
I use escape sequences for coloration of strings in terminal with a
decimal
27 constant ESC \ to manage escape sequences used as colorations
: COLORIZE ESC EMIT ." [" base @ >R 0 <# #S #> type R> base ! ." m" ; \
ASCII TERMINAL
so I can use it as
31 colorize ." print something" 0 colorize
for example.
is this a good method for my xterm compatibles ascii-terminals ?
is there a better way to do so ?
regards.
On 4/05/2023 10:30 am, Brian Fox wrote:
Aren't the XY coords for VT100/ANSI 1-based rather than 0-based?
Aren't the XY coords for VT100/ANSI 1-based rather than 0-based?
Lorem Ipsum <gnuarm.del...@gmail.com> writes:
On Wednesday, May 3, 2023 at 2:48:33=E2=80=AFPM UTC-4, gobli...@gmail.com w=...
rote:
decimal=20
27 constant ESC \ to manage escape sequences used as colorations=20
: COLORIZE ESC EMIT ." [" base @ >R 0 <# #S #> type R> base ! ." m" ; \ A=
Maybe I'm missing something, or don't understand BASE. I thought it is the=
address where the number conversion base is stored. You save it on the re=
turn stack, then restore it after printing the number, but I don't see wher=
e you change it. So why save and restore if you are not going to change it= >?=20
Yes, the BASE saving and restoring is unnecessary here.
Also, at the very beginning, you change the value stored at BASE to 10 with=
the word decimal. Is that intentional? the word decimal is not going to =
have any impact if BASE is changed elsewhere in the code, before colorize i=
s called.=20
What am I missing?=20
DECIMAL ensures that the "27" is converted using decimal base.
An alternative (Forth-2012) way to ensure this is to write
#27 constant ESC
instead.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 37:30:21 |
Calls: | 6,707 |
Files: | 12,241 |
Messages: | 5,353,507 |