summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkitty <nepeta@canaglie.net>2026-03-07 02:36:47 +1100
committerkitty <nepeta@canaglie.net>2026-03-07 02:36:47 +1100
commita031a0945c01dd1bea2bea6d93d5b57d17cbfe25 (patch)
tree5e35117adf64fa0ae60a116535cdee11b185707f
parent54df6ebd37631d9e083986cace488481b2ecdd1b (diff)
terminal colours!
bit annoying to define 'default' and 'normal' but eh
-rw-r--r--jefs.fs40
1 files changed, 37 insertions, 3 deletions
diff --git a/jefs.fs b/jefs.fs
index 60f6a4a..af08710 100644
--- a/jefs.fs
+++ b/jefs.fs
@@ -251,7 +251,7 @@ decimal
: bytes-free bytes-allocated bytes-used - ;
: brk@ 0 sysbrk ;
-: mark-exec PROT_rwx bytes-allocated herestart @ mprotect .errno ;
+: mark-exec PROT_rwx bytes-allocated herestart @ mprotect errno .errno ;
: grow ( n -- ) brk@ + sysbrk heremax ! mark-exec ; \ todo check error
: .free bytes-free u. ." of " bytes-allocated u. ." bytes free (used " bytes-used (.) say ." )" cr ;
@@ -365,10 +365,44 @@ make line-buffer line-buffer-length allot
source-id >r string-source to source-id interpret r> to source-id ;
: evaluate ( c-addr u -- ) tib @ >r #tib @ >r >in @ >r (evaluate) r> >in ! r> #tib ! r> tib ! ;
+\ TERMINAL CONTROL {{{
+60 constant termios#
+make termios termios# allot
+
+hex
+5401 constant TCGETS
+decimal
+
+: ioctl 16 syscall3 ;
+
+:> 0<> if false else true then ;
+termios TCGETS stdin ioctl ( noname ) swap execute value tty
+
+\ emits are relatively slow (one syscall per char: not good)
+: ESC 27 emit ;
+: CSI ESC [ char [ ] literal emit ;
+
+\ each change uses a different one, which is not too efficient
+\ Pm sequences allow multiple with ;
+: CSIm ( n -- ) CSI (.) say [ char m ] literal emit ;
+
+: foreground 30 + CSIm ;
+: background 40 + CSIm ;
+
+0 constant black 1 constant red 2 constant green
+3 constant yellow 4 constant blue 5 constant magenta
+6 constant cyan 7 constant white 9 constant default
+
+: bold 1 CSIm ; : normal 0 CSIm ;
+\ }}}
+
\ DUMP {{{
+\ it's designed to look like xxd. i like xxd's hex dumps.
+: (dumploc) ( a -- ) (.dword) say ." : " ;
: (d+) ( a -- a+1 ) dup @ .word 1+ ;
-: (dump) ( a -- ) (d+) (d+) (d+) (d+) (d+) (d+) (d+) (d+) drop cr ; \ dump cell of memory at a
-: dump ( n a -- ) swap begin ?dup 0> while swap dup (dump) 16 + swap 1- repeat ; \ dump n lines (of 16 bytes each) of memory starting at a
+: (dumphex) ( a -- a ) (d+) (d+) (d+) (d+) (d+) (d+) (d+) (d+) ;
+: (dump) ( a -- ) dup (dumploc) (dumphex) drop cr ; \ dump cell of memory at a
+: dump ( n a -- ) swap begin ?dup 0> while swap dup (dump) 16 + swap 1- repeat drop ; \ dump n lines (of 16 bytes each) of memory starting at a
\ }}}
0 constant version