Kind | Covered | All | % |
expression | 5 | 271 | 1.8 |
branch | 0 | 2 | 0.0 |
1
;;; ansi.lisp --- ANSI Tests
2
3
;;
4
5
;;; Code:
6
(in-package :cli/tests)
7
(in-suite :cli)
8
9
(defmacro with-ansi-test-io (&body body)
10
"Rebind *STANDARD-OUTPUT* for testing CLI/ANSI."
11
`(istype
12
'string
13
(with-output-to-string (s)
14
(let ((*standard-output* s))
15
,@body))))
16
17
(defmacro defansi-test (name args &body body)
18
`(defun ,name ,args
19
(with-ansi-test-io
20
,@body)))
21
22
(defansi-test ansi-t01 ()
23
(erase)
24
(cursor-position 0 0)
25
(princ "0")
26
(cursor-position 2 2)
27
(princ "1")
28
(cursor-position 5 15)
29
(princ "test")
30
(cursor-position 10 15)
31
(force-output)
32
(with-input-from-string (in (format nil "test~%~%"))
33
(let ((a (read-line in)))
34
(cursor-position 12 15)
35
(princ a)
36
(force-output))))
37
38
(defansi-test ansi-t02 ()
39
(print "normal")
40
(.sgr 1)
41
(print "bold")
42
(.sgr 4)
43
(print "bold underline")
44
(.sgr 7)
45
(print "bold underline reverse")
46
(.sgr 22)
47
(print "underline reverse")
48
(.sgr 24)
49
(print "reverse")
50
(.sgr 27)
51
(print "normal")
52
(.sgr 1 4 7)
53
(print "bold underline reverse")
54
(.sgr 0)
55
(print "normal")
56
(force-output))
57
58
(defansi-test ansi-t03 ()
59
(clear)
60
(loop for i from 0 to 255 do
61
(.sgr 48 5 i)
62
(princ #\space))
63
(terpri)
64
(.sgr 0)
65
(loop for i from 0 to 255 do
66
(.sgr 38 5 i)
67
(princ "X"))
68
(.sgr 0)
69
(force-output)
70
;; (sleep 3)
71
(.ris)
72
(force-output))
73
74
(defansi-test ansi-t04 ()
75
(princ "Cursor visible:")
76
(force-output)
77
;; (sleep 2)
78
(terpri)
79
(princ "Cursor invisible:")
80
(hide-cursor)
81
(force-output)
82
;; (sleep 2)
83
(terpri)
84
(princ "Cursor visible:")
85
(show-cursor)
86
(force-output)
87
;; (sleep 2)
88
)
89
90
(defansi-test ansi-t05 ()
91
(princ "Normal screen buffer. ")
92
(force-output)
93
;; (sleep 2)
94
(.scosc)
95
(use-alternate-screen-buffer)
96
(clear)
97
(princ "Alternate screen buffer.")
98
(force-output)
99
;; (sleep 2)
100
(use-normal-screen-buffer)
101
(.scorc)
102
(princ "Back to Normal screen buffer.")
103
(force-output)
104
;; (sleep 1)
105
)
106
107
(defansi-test ansi-t06 ()
108
(set-tty-mode t :ignbrk nil
109
:brkint nil
110
:parmrk nil
111
:istrip nil
112
:inlcr nil
113
:igncr nil
114
:icrnl nil
115
:ixon nil
116
:opost nil
117
:echo nil
118
:echonl nil
119
:icanon nil
120
:isig nil
121
:iexten nil
122
:csize nil
123
:parenb nil
124
:vmin 1
125
:vtime 0)
126
(erase)
127
(cursor-position 1 1)
128
(force-output)
129
(let ((a (read-char)))
130
(cursor-position 10 5)
131
(princ a)
132
(force-output))
133
134
(set-tty-mode t :echo t
135
:brkint t
136
:ignpar t
137
:istrip t
138
:icrnl t
139
:ixon t
140
:opost t
141
:isig t
142
:icanon t
143
:veol 0))
144
145
(defansi-test ansi-t07 ()
146
(set-tty-mode t :cooked nil)
147
(erase)
148
(cursor-position 1 1)
149
(force-output)
150
(let ((a (read-char)))
151
(cursor-position 3 1)
152
(princ a)
153
(force-output))
154
(set-tty-mode t :raw nil))
155
156
(defansi-test ansi-t08 ()
157
;; (uiop:run-program "stty raw -echo")
158
(erase)
159
(cursor-position 1 1)
160
(force-output)
161
(let ((a (read-char)))
162
(cursor-position 2 1)
163
(princ a)
164
(force-output))
165
;; (uiop:run-program "stty -raw echo" :ignore-error-status t)
166
)
167
168
(defansi-test ansi-t09 ()
169
;; Put the terminal into raw mode so we can read the "user input"
170
;; of the reply char by char
171
;; Turn off the echo or the sequence will be displayed
172
(set-tty-mode t :cooked nil :echo nil)
173
(save-cursor-position)
174
;; Go to the bottom right corner of the terminal by attempting
175
;; to go to some high value of row and column
176
(cursor-position 999 999)
177
(let (chars)
178
;; The terminal returns an escape sequence to the standard input
179
(.dsr)
180
(force-output)
181
;; The reply isnt immediately available, the terminal does need
182
;; some time to answer
183
(sleep 0.1)
184
;; The reply has to be read as if the user typed an escape sequence
185
(loop for i = (read-char-no-hang *standard-input* nil)
186
until (null i)
187
do (push i chars))
188
;; Put the terminal back into its initial cooked state
189
(set-tty-mode t :raw nil :echo t)
190
(restore-cursor-position)
191
;; Return the read sequence as a list of characters.
192
;; (nreverse chars)
193
))
194
195
(deftest ansi ()
196
(with-input-from-string (in (format nil "~%~%"))
197
(ansi-t01)
198
(ansi-t02)
199
(ansi-t03)
200
(ansi-t04)
201
(ansi-t05)))