vocabulary scheme
scheme definitions
+include term-colours.4th
+
\ Cons cell memory
1000 constant memsize
create car memsize allot
\ ---- REPL ----
-: escape 27 emit [char] [ emit ;
-: escape-end [char] m emit ;
-
-: set-term-colour
- escape [char] 3 emit [char] 0 + emit escape-end
-;
-
-: reset-term
- escape [char] 0 escape-end
-;
-
-: colour
- create ,
-does>
- @ set-term-colour
-;
-
-1 colour red
-2 colour green
-3 colour yellow
-4 colour blue
-5 colour magenta
-6 colour cyan
-7 colour white
-
create repl-buffer 161 allot
: repl
cr
begin
- green ." => " white
+ bold fg green ." => " reset-term
repl-buffer 1+ 160 expect cr
span @ repl-buffer !
--- /dev/null
+\ Words for controlling terminal colours via ANSI escape sequences
+
+: escape 27 emit [char] [ emit ;
+: escape-end [char] m emit ;
+
+: fg [char] 3 ;
+: bg [char] 4 ;
+
+: set-term-colour
+ escape emit [char] 0 + emit escape-end
+;
+
+: reset-term
+ escape [char] 0 escape-end
+;
+
+: bold
+ escape [char] 1 emit escape-end
+;
+
+: colour
+ create ,
+does>
+ @ swap
+ set-term-colour
+;
+
+1 colour red
+2 colour green
+3 colour yellow
+4 colour blue
+5 colour magenta
+6 colour cyan
+7 colour white
+
+\ Example usage:
+\ fg red ( set fg colour to red )
+\ bg green ( set bg colour to green )
+\ bold ( use a bold font )
+\ reset-term ( return everything to normal )