aboutsummaryrefslogtreecommitdiff
path: root/module/vulgar.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-07-30 14:35:10 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-07-30 14:35:10 +0200
commit77c76949e5998b6914e71aae97c953b8ac796f57 (patch)
treea10af691df8b2b839a3f4abe2b5d28f1869529fd /module/vulgar.scm
parentAdd stream-paginate. (diff)
downloadcalp-77c76949e5998b6914e71aae97c953b8ac796f57.tar.gz
calp-77c76949e5998b6914e71aae97c953b8ac796f57.tar.xz
vulgar fixups.
Diffstat (limited to 'module/vulgar.scm')
-rw-r--r--module/vulgar.scm22
1 files changed, 14 insertions, 8 deletions
diff --git a/module/vulgar.scm b/module/vulgar.scm
index 80bff5f6..5c98d719 100644
--- a/module/vulgar.scm
+++ b/module/vulgar.scm
@@ -11,13 +11,20 @@
#:export (with-vulgar))
(define-public (cls)
- (display "\x1b[H") ; Move cursor to the origin
- (display "\x1b[J") ; Clear everything after cursor
- )
+ ;; [H]ome, [J]: clear everything after
+ (display "\x1b[H\x1b[J"))
+
+(define-public (set-cursor-pos x y)
+ (format #t "\x1b[~a;~aH"
+ (1+ y) (1+ x)))
+
(define-syntax with-vulgar
(syntax-rules ()
((_ thunk)
+ (with-vulgar (bitwise-not (bitwise-ior ECHO ICANON))
+ thunk))
+ ((_ bits thunk)
(let* ((ifd (current-input-port))
(ofd (current-output-port))
(iattr (make-termios))
@@ -29,12 +36,11 @@
(tcgetattr! oattr ofd)
;; Store current settings to enable resetting the terminal later
- (set! iattr* (copy-termios iattr))
- (set! oattr* (copy-termios oattr))
+ (set! iattr* (copy-termios iattr)
+ 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)))
+ (lflag iattr) (bitwise-and bits (lflag iattr))
+ (lflag oattr) (bitwise-and bits (lflag oattr)))
(tcsetattr! iattr ifd)
(tcsetattr! oattr ofd))