summaryrefslogtreecommitdiff
path: root/world/tty-commands.scm
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-01-15 19:56:23 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-01-18 22:48:57 +0100
commit42f3c3b9493e39d20ec43a7643f8e6900da331c1 (patch)
treef134a4195fe6acd4c8d81a0bd5320dc45130b09e /world/tty-commands.scm
parent6cbfd6331287827fc14791e387c48e97656445c1 (diff)
world: reorganize and start the magic
Diffstat (limited to 'world/tty-commands.scm')
-rw-r--r--world/tty-commands.scm33
1 files changed, 33 insertions, 0 deletions
diff --git a/world/tty-commands.scm b/world/tty-commands.scm
new file mode 100644
index 0000000..90d896e
--- /dev/null
+++ b/world/tty-commands.scm
@@ -0,0 +1,33 @@
+;; https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
+
+;; Clear the screen better:
+;; https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
+
+(define csi-lead "\x1b[")
+
+(define (str-csi . args)
+ (apply string-append csi-lead args))
+
+(define (csi-command! . args)
+ (write-string (apply str-csi args))
+ (flush-output-port))
+
+; These are xterm things, but they are widely adopted
+(define (enable-alternate-buffer!)
+ (csi-command! "?1049h"))
+(define (disable-alternate-buffer!)
+ (csi-command! "?1049l"))
+
+(define (erase-screen!) (csi-command! "2J"))
+
+(define (move-cursor! x y)
+ "Also valid with CSI<L>;<C>f being <L> and <C> line number and column
+ number respectively. In ttys, cursor starts at 1,1"
+ (csi-command! (number->string (+ y 1)) ";" (number->string (+ 1 x)) "H"))
+
+(define (ui-initialize!)
+ (enable-alternate-buffer!)
+ (move-cursor! 0 0))
+
+(define (ui-deinitialize!)
+ (disable-alternate-buffer!))