|
49 | 49 |
|
50 | 50 | (define (open-terminfo-file name)
|
51 | 51 | (let loop ((dirs *terminfo-directories*))
|
52 |
| - (if (not (null? dirs)) |
53 |
| - (let* ((basedir (car dirs)) |
54 |
| - (initial (terminfo-directory-prefix name)) |
55 |
| - (file (path-list->file-name (list basedir initial name)))) |
56 |
| - (cond ((file-not-exists? file) |
57 |
| - (error "Cannot find terminfo named " name)) |
58 |
| - ((file-readable? file) (open-input-file file)) |
59 |
| - (else (loop (cdr dirs)))))))) |
| 52 | + (unless (null? dirs) |
| 53 | + (let* ((basedir (car dirs)) |
| 54 | + (initial (terminfo-directory-prefix name)) |
| 55 | + (file (path-list->file-name (list basedir initial name)))) |
| 56 | + (cond ((file-not-exists? file) |
| 57 | + (error "Cannot find terminfo named " name)) |
| 58 | + ((file-readable? file) (open-input-file file)) |
| 59 | + (else (loop (cdr dirs)))))))) |
60 | 60 |
|
61 | 61 | (define (read-short . args)
|
62 | 62 | (let-optionals args ((s (current-input-port)))
|
|
89 | 89 | (else (loop (+ 1 j)))))))
|
90 | 90 |
|
91 | 91 | (define (read-padding s lines)
|
92 |
| - (if (not (and (char=? #\$ (string-ref s 0)) |
93 |
| - (char=? #\< (string-ref s 1)))) |
94 |
| - (error "Invalid input")) |
| 92 | + (unless (and (char=? #\$ (string-ref s 0)) |
| 93 | + (char=? #\< (string-ref s 1))) |
| 94 | + (error "Invalid input")) |
95 | 95 | (let loop ((time 0)
|
96 | 96 | (force #f)
|
97 | 97 | (i 2))
|
|
119 | 119 | (with-current-output-port output-port
|
120 | 120 | (let loop ((i 0)
|
121 | 121 | (len (string-length s)))
|
122 |
| - (if (< i len) |
123 |
| - (let ((c (string-ref s i))) |
124 |
| - (cond |
125 |
| - ((and (char=? c #\$) (number? (string-index s #\>))) |
126 |
| - (let ((substr (substring s i (+ 1 (string-index s #\>)))) |
127 |
| - (rate (baud-rate output-port))) |
128 |
| - (let-values (((time force) |
129 |
| - (read-padding substr lines-affected))) |
130 |
| - (if (or force (eq? #t (xon-xoff))) |
131 |
| - (if (eq? #t (no-pad-char)) |
132 |
| - (sleep (/ time 10000.0)) |
133 |
| - (do ((i 0 (+ i 1))) |
134 |
| - ((>= i (ceiling (/ (* rate time) 100000)))) |
135 |
| - (write-char (char-padding)) |
136 |
| - (loop (+ 1 i) len))) |
137 |
| - (loop (+ 1 i) len))))) |
138 |
| - (else (begin |
139 |
| - (write-char c) |
140 |
| - (loop (+ 1 i) len)))))))))) |
| 122 | + (when (< i len) |
| 123 | + (let ((c (string-ref s i))) |
| 124 | + (cond |
| 125 | + ((and (char=? c #\$) (number? (string-index s #\>))) |
| 126 | + (let ((substr (substring s i (+ 1 (string-index s #\>)))) |
| 127 | + (rate (baud-rate output-port))) |
| 128 | + (let-values (((time force) |
| 129 | + (read-padding substr lines-affected))) |
| 130 | + (if (or force (eq? #t (xon-xoff))) |
| 131 | + (if (eq? #t (no-pad-char)) |
| 132 | + (sleep (/ time 10000.0)) |
| 133 | + (do ((i 0 (+ i 1))) |
| 134 | + ((>= i (ceiling (/ (* rate time) 100000)))) |
| 135 | + (write-char (char-padding)) |
| 136 | + (loop (+ 1 i) len))) |
| 137 | + (loop (+ 1 i) len))))) |
| 138 | + (else (begin |
| 139 | + (write-char c) |
| 140 | + (loop (+ 1 i) len)))))))))) |
141 | 141 |
|
142 | 142 | ;;;
|
143 | 143 | ;;; See Table 7.3, _Unix_Curses_Explained_, p.101
|
|
377 | 377 | (numbers (make-vector sznumbers -1))
|
378 | 378 | (strings (make-vector szstrings -1))
|
379 | 379 | (stringtable (make-string szstringtable)))
|
380 |
| - (if (not (= magic #o432)) |
381 |
| - (error "This is not well-formed")) |
| 380 | + (unless (= magic #o432) |
| 381 | + (error "This is not well-formed")) |
382 | 382 | (do ((i 0 (+ i 1))) ((>= i szbooleans))
|
383 | 383 | (vector-set! booleans i (not (zero? (read-byte)))))
|
384 |
| - (if (odd? (+ sznames szbooleans)) |
385 |
| - (read-byte)) |
| 384 | + (when (odd? (+ sznames szbooleans)) |
| 385 | + (read-byte)) |
386 | 386 | (do ((i 0 (+ i 1))) ((>= i sznumbers))
|
387 | 387 | (vector-set! numbers i (read-short)))
|
388 | 388 | (do ((i 0 (+ i 1))) ((>= i szstrings))
|
389 | 389 | (vector-set! strings i (read-short)))
|
390 | 390 | (do ((i 0 (+ i 1))) ((>= i szstringtable))
|
391 | 391 | (string-set! stringtable i (read-char)))
|
392 | 392 | (do ((i 0 (+ i 1))) ((>= i szstrings))
|
393 |
| - (if (positive? (vector-ref strings i)) |
394 |
| - (let* ((start (vector-ref strings i)) |
395 |
| - (end (string-index stringtable |
396 |
| - (integer->char 0) |
397 |
| - start szstringtable)) |
398 |
| - (substr (substring stringtable start end))) |
399 |
| - (vector-set! strings i substr)))) |
| 393 | + (when (positive? (vector-ref strings i)) |
| 394 | + (let* ((start (vector-ref strings i)) |
| 395 | + (end (string-index stringtable |
| 396 | + (integer->char 0) |
| 397 | + start szstringtable)) |
| 398 | + (substr (substring stringtable start end))) |
| 399 | + (vector-set! strings i substr)))) |
400 | 400 | (make-terminal console-output-port names booleans numbers strings))))
|
401 | 401 |
|
402 | 402 | (define (setup-terminal . args)
|
|
0 commit comments