diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-04-05 18:21:40 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-04-05 18:36:34 +0200 |
commit | 70cc83b953d3be80dc708a5d8d7529e6f6c81271 (patch) | |
tree | ad1bdb4020ffadc70f228ad7ebc3b8b751e85171 /module/terminal/escape.scm | |
parent | Add extra case to let*. (diff) | |
download | calp-70cc83b953d3be80dc708a5d8d7529e6f6c81271.tar.gz calp-70cc83b953d3be80dc708a5d8d7529e6f6c81271.tar.xz |
Move termios bindings to scheme code.
Diffstat (limited to '')
-rw-r--r-- | module/terminal/escape.scm | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/module/terminal/escape.scm b/module/terminal/escape.scm index 8f1b0c2b..a16df594 100644 --- a/module/terminal/escape.scm +++ b/module/terminal/escape.scm @@ -3,6 +3,7 @@ (define-module (terminal escape) #:use-module (srfi srfi-60) #:use-module (terminal termios) + #:use-module (util) #:export (with-vulgar)) (define-public (cls) @@ -15,14 +16,27 @@ (define-syntax with-vulgar (syntax-rules () ((_ thunk) - (let ((ifd (fileno (current-input-port))) - (ofd (fileno (current-output-port)))) + (let* ((ifd (current-input-port)) + (ofd (current-output-port)) + (iattr (make-termios)) + (oattr (make-termios)) + iattr* oattr*) (dynamic-wind (lambda () - (let ((bits (bitwise-ior ECHO ICANON))) - (c-lflags-disable! ifd bits) - (c-lflags-disable! ofd bits))) + (tcgetattr! iattr ifd) + (tcgetattr! oattr ofd) + + ;; Store current settings to enable resetting the terminal later + (set! iattr* (copy-termios iattr)) + (set! oattr* (copy-termios oattr)) + + (let ((bits (bitwise-not (bitwise-ior ECHO ICANON)))) + (set! (lflag iattr) (bitwise-and (lflag iattr) bits)) + (set! (lflag oattr) (bitwise-and (lflag oattr) bits))) + + (tcsetattr! iattr ifd) + (tcsetattr! oattr ofd)) thunk (lambda () - (c-lflag-restore! ifd) - (c-lflag-restore! ofd)))) ))) + (tcsetattr! iattr* ifd) + (tcsetattr! oattr* ofd))))))) |