;; 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;f being and line number and column number respectively" (csi-command! (number->string y) ";" (number->string x) "H")) (define (echo-char) (define table (make-piece-table "hola")) (display "HELO") (enable-alternate-buffer!) (let loop ((char (read-char))) (cond ((char=? #\q char) #f) (else (piece-table-insert! table 4 "hola" 'normal) (move-cursor! 0 0) (erase-screen!) (write-string (piece-table->string table)) (loop (read-char))))) (disable-alternate-buffer!)) (define (start arguments) (with-raw-io (current-input-port) echo-char))