bjoterm: raw mode, key events and escape sequences
- (bjoterm terminal): terminal-open, with-raw-mode, terminal-size, terminal-suspend, read-event and read-event/timeout, and escape sequences for the cursor, clearing, the alternate screen, bracketed paste and styles. Linux only. - glue/Tty.cs: termios, poll on fd 0, SIGWINCH, SIGCONT, SIGTSTP, and restoring the modes at SIGTERM, SIGHUP, SIGQUIT and process exit. - glue/Keys.cs: the decoder of CSI and SS3 keys with modifiers, Alt, UTF-8 and bracketed paste. - Tests: the decoder from bytes, and raw mode on a pseudo-terminal under script. plan.org has the decisions and the phases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
fe42387a4c
12 changed files with 1830 additions and 0 deletions
20
examples/keys.bjo
Normal file
20
examples/keys.bjo
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
;; Prints each key, paste and resize until Ctrl-D.
|
||||
;;
|
||||
;; bjo run examples/keys.bjo
|
||||
|
||||
(import (std prelude))
|
||||
(import (bjoterm terminal))
|
||||
|
||||
(defun (main args)
|
||||
(def (Ok term) (terminal-open) :leave ((Err e) (println (terminal-error-message e)) 1))
|
||||
(print bracketed-paste-on)
|
||||
(println (styled "Press keys, paste text or resize the window. Ctrl-D ends." [StyleBold]))
|
||||
(with-raw-mode term
|
||||
(fun ()
|
||||
(let go ()
|
||||
(match (read-event term)
|
||||
((TermKey (KeyChar #\d) (Mods (ctrl? #t))) unit)
|
||||
(TermEnd unit)
|
||||
(ev (println (event->string ev)) (go))))))
|
||||
(print bracketed-paste-off)
|
||||
0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue