aboutsummaryrefslogtreecommitdiff
path: root/terminal/escape.scm
blob: 8f1b0c2b0fa2af2ab79fd1b85d92e6549b40d743 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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))))  )))