diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-03-12 19:06:54 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-03-12 19:06:54 +0100 |
commit | 5bf50b03a3d5a5d8888021b4f3722031958367d3 (patch) | |
tree | 8ae79d1e8751a7f74d51869df38a93c609579fb5 /terminal/escape.scm | |
parent | Add some more time utils. (diff) | |
download | calp-5bf50b03a3d5a5d8888021b4f3722031958367d3.tar.gz calp-5bf50b03a3d5a5d8888021b4f3722031958367d3.tar.xz |
Add a bunch of terminal control modules.
Diffstat (limited to 'terminal/escape.scm')
-rw-r--r-- | terminal/escape.scm | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/terminal/escape.scm b/terminal/escape.scm new file mode 100644 index 00000000..8f1b0c2b --- /dev/null +++ b/terminal/escape.scm @@ -0,0 +1,28 @@ +;;; Module for terminal (ANSI) escape codes. + +(define-module (terminal escape) + #:use-module (srfi srfi-60) + #:use-module (terminal termios) + #:export (with-vulgar)) + +(define-public (cls) + (display "\x1b[H") ; Move cursor to the origin + (display "\x1b[J") ; Clear everything after cursor + ) + +;;; I don't curse, I'm just vulgar. + +(define-syntax with-vulgar + (syntax-rules () + ((_ thunk) + (let ((ifd (fileno (current-input-port))) + (ofd (fileno (current-output-port)))) + (dynamic-wind + (lambda () + (let ((bits (bitwise-ior ECHO ICANON))) + (c-lflags-disable! ifd bits) + (c-lflags-disable! ofd bits))) + thunk + (lambda () + (c-lflag-restore! ifd) + (c-lflag-restore! ofd)))) ))) |