diff options
Diffstat (limited to 'yolk.common.ss')
-rw-r--r-- | yolk.common.ss | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/yolk.common.ss b/yolk.common.ss new file mode 100644 index 0000000..00aa91e --- /dev/null +++ b/yolk.common.ss | |||
@@ -0,0 +1,39 @@ | |||
1 | ;;; (yolk common) --- common stuff for ansi things | ||
2 | |||
3 | (import (scheme base) | ||
4 | (scheme write)) | ||
5 | |||
6 | (define (->string x) | ||
7 | (let ((str (open-output-string))) | ||
8 | (display x str) | ||
9 | (close-output-port str) | ||
10 | (get-output-string str))) | ||
11 | |||
12 | (define (esc . xs) | ||
13 | (apply string-append (string #\escape) | ||
14 | (map ->string xs))) | ||
15 | |||
16 | (define (csi . xs) | ||
17 | (apply esc "[" xs)) | ||
18 | |||
19 | (define (dcs . xs) | ||
20 | (apply esc "P" xs)) | ||
21 | |||
22 | (define (ocs . xs) | ||
23 | (apply esc "]" xs)) | ||
24 | |||
25 | (define-syntax define-esc-alt-wrapper | ||
26 | (syntax-rules () | ||
27 | ((_ wrapper-proc-name param-name (default-proc args ...)) | ||
28 | (begin | ||
29 | (define param-name | ||
30 | (make-parameter default-proc | ||
31 | (parameter-assert procedure? "Must be a procedure"))) | ||
32 | (define (wrapper-proc-name args ...) | ||
33 | ((param-name) args ...)))))) | ||
34 | |||
35 | (define (parameter-assert predicate error-message) | ||
36 | (lambda (x) | ||
37 | (if (predicate x) | ||
38 | x | ||
39 | (error error-message x)))) | ||