From: Tim Vaughan Date: Sun, 12 Jun 2016 01:25:03 +0000 (+1200) Subject: Moved ansi colour words to distinct file. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=ab2c14cdd02f93d17f8784e790415de0e6d7b996;p=scheme.forth.jl.git Moved ansi colour words to distinct file. --- diff --git a/scheme.4th b/scheme.4th index 5fe8b3e..65c64a8 100644 --- a/scheme.4th +++ b/scheme.4th @@ -3,6 +3,8 @@ vocabulary scheme scheme definitions +include term-colours.4th + \ Cons cell memory 1000 constant memsize create car memsize allot @@ -133,31 +135,6 @@ variable parse-str \ ---- 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 @@ -166,7 +143,7 @@ create repl-buffer 161 allot cr begin - green ." => " white + bold fg green ." => " reset-term repl-buffer 1+ 160 expect cr span @ repl-buffer ! diff --git a/term-colours.4th b/term-colours.4th new file mode 100644 index 0000000..97582dc --- /dev/null +++ b/term-colours.4th @@ -0,0 +1,40 @@ +\ 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 )