Commit0fac4fa4Recorded25 Feb 2026Repositorysigil-ansi
Add procedure specs to args, ansi, process, and hooks modules
Message
sigil-args: 5 specs (parse-args, run-command, generate-help, print-help, find-subcommand)
sigil-ansi: 43 specs (16 foreground colors, 8 background colors, 9 text styles, 12 cursor/screen controls, strip-ansi, ansi-enabled?, with-ansi-disabled)
sigil process: 17 specs (14 native, 3 Scheme utilities)
sigil-hooks: 8 specs (make-hook, hook?, hook-empty?, add-hook!, remove-hook!, clear-hook!, run-hook, run-hook-with-args)
Changed
src/sigil/ansi.sgl | 80 ++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
1 file changed, 48 insertions(+), 32 deletions(-)Diff
src/sigil/ansi.sglmodified
@@ -85,6 +85,7 @@
85
;;; (ansi-enabled?) ; => #t 86
;;; ``` 87
(define (ansi-enabled?)+88
(: -> boolean?) 89
*ansi-enabled*) 90
91
;;; Execute a thunk with ANSI codes disabled.@@ -97,6 +98,7 @@
98
;;; (a:red "text"))) ; => "text" (no escape codes) 99
;;; ``` 100
(define (with-ansi-disabled thunk)+101
(: procedure? -> any?) 102
(let ((was-enabled *ansi-enabled*)) 103
(set! *ansi-enabled* #f) 104
(let ((result (thunk)))@@ -112,107 +114,108 @@
114
;; ========== Foreground Colors ========== 115
116
;;; Apply black foreground color.−115
(define (a:black text) (ansi-wrap "30" "39" text))+117
(define (a:black text) (: string? -> string?) (ansi-wrap "30" "39" text)) 118
119
;;; Apply red foreground color.−118
(define (a:red text) (ansi-wrap "31" "39" text))+120
(define (a:red text) (: string? -> string?) (ansi-wrap "31" "39" text)) 121
122
;;; Apply green foreground color.−121
(define (a:green text) (ansi-wrap "32" "39" text))+123
(define (a:green text) (: string? -> string?) (ansi-wrap "32" "39" text)) 124
125
;;; Apply yellow foreground color.−124
(define (a:yellow text) (ansi-wrap "33" "39" text))+126
(define (a:yellow text) (: string? -> string?) (ansi-wrap "33" "39" text)) 127
128
;;; Apply blue foreground color.−127
(define (a:blue text) (ansi-wrap "34" "39" text))+129
(define (a:blue text) (: string? -> string?) (ansi-wrap "34" "39" text)) 130
131
;;; Apply magenta foreground color.−130
(define (a:magenta text) (ansi-wrap "35" "39" text))+132
(define (a:magenta text) (: string? -> string?) (ansi-wrap "35" "39" text)) 133
134
;;; Apply cyan foreground color.−133
(define (a:cyan text) (ansi-wrap "36" "39" text))+135
(define (a:cyan text) (: string? -> string?) (ansi-wrap "36" "39" text)) 136
137
;;; Apply white foreground color.−136
(define (a:white text) (ansi-wrap "37" "39" text))+138
(define (a:white text) (: string? -> string?) (ansi-wrap "37" "39" text)) 139
140
;;; Apply bright black (gray) foreground color.−139
(define (a:bright-black text) (ansi-wrap "90" "39" text))+141
(define (a:bright-black text) (: string? -> string?) (ansi-wrap "90" "39" text)) 142
143
;;; Apply bright red foreground color.−142
(define (a:bright-red text) (ansi-wrap "91" "39" text))+144
(define (a:bright-red text) (: string? -> string?) (ansi-wrap "91" "39" text)) 145
146
;;; Apply bright green foreground color.−145
(define (a:bright-green text) (ansi-wrap "92" "39" text))+147
(define (a:bright-green text) (: string? -> string?) (ansi-wrap "92" "39" text)) 148
149
;;; Apply bright yellow foreground color.−148
(define (a:bright-yellow text) (ansi-wrap "93" "39" text))+150
(define (a:bright-yellow text) (: string? -> string?) (ansi-wrap "93" "39" text)) 151
152
;;; Apply bright blue foreground color.−151
(define (a:bright-blue text) (ansi-wrap "94" "39" text))+153
(define (a:bright-blue text) (: string? -> string?) (ansi-wrap "94" "39" text)) 154
155
;;; Apply bright magenta foreground color.−154
(define (a:bright-magenta text) (ansi-wrap "95" "39" text))+156
(define (a:bright-magenta text) (: string? -> string?) (ansi-wrap "95" "39" text)) 157
158
;;; Apply bright cyan foreground color.−157
(define (a:bright-cyan text) (ansi-wrap "96" "39" text))+159
(define (a:bright-cyan text) (: string? -> string?) (ansi-wrap "96" "39" text)) 160
161
;;; Apply bright white foreground color.−160
(define (a:bright-white text) (ansi-wrap "97" "39" text))+162
(define (a:bright-white text) (: string? -> string?) (ansi-wrap "97" "39" text)) 163
164
;; ========== Background Colors ========== 165
166
;;; Apply black background color.−165
(define (a:bg-black text) (ansi-wrap "40" "49" text))+167
(define (a:bg-black text) (: string? -> string?) (ansi-wrap "40" "49" text)) 168
169
;;; Apply red background color.−168
(define (a:bg-red text) (ansi-wrap "41" "49" text))+170
(define (a:bg-red text) (: string? -> string?) (ansi-wrap "41" "49" text)) 171
172
;;; Apply green background color.−171
(define (a:bg-green text) (ansi-wrap "42" "49" text))+173
(define (a:bg-green text) (: string? -> string?) (ansi-wrap "42" "49" text)) 174
175
;;; Apply yellow background color.−174
(define (a:bg-yellow text) (ansi-wrap "43" "49" text))+176
(define (a:bg-yellow text) (: string? -> string?) (ansi-wrap "43" "49" text)) 177
178
;;; Apply blue background color.−177
(define (a:bg-blue text) (ansi-wrap "44" "49" text))+179
(define (a:bg-blue text) (: string? -> string?) (ansi-wrap "44" "49" text)) 180
181
;;; Apply magenta background color.−180
(define (a:bg-magenta text) (ansi-wrap "45" "49" text))+182
(define (a:bg-magenta text) (: string? -> string?) (ansi-wrap "45" "49" text)) 183
184
;;; Apply cyan background color.−183
(define (a:bg-cyan text) (ansi-wrap "46" "49" text))+185
(define (a:bg-cyan text) (: string? -> string?) (ansi-wrap "46" "49" text)) 186
187
;;; Apply white background color.−186
(define (a:bg-white text) (ansi-wrap "47" "49" text))+188
(define (a:bg-white text) (: string? -> string?) (ansi-wrap "47" "49" text)) 189
190
;; ========== Text Styles ========== 191
192
;;; Apply bold text style.−191
(define (a:bold text) (ansi-wrap "1" "22" text))+193
(define (a:bold text) (: string? -> string?) (ansi-wrap "1" "22" text)) 194
195
;;; Apply dim (faint) text style.−194
(define (a:dim text) (ansi-wrap "2" "22" text))+196
(define (a:dim text) (: string? -> string?) (ansi-wrap "2" "22" text)) 197
198
;;; Apply italic text style.−197
(define (a:italic text) (ansi-wrap "3" "23" text))+199
(define (a:italic text) (: string? -> string?) (ansi-wrap "3" "23" text)) 200
201
;;; Apply underline text style.−200
(define (a:underline text) (ansi-wrap "4" "24" text))+202
(define (a:underline text) (: string? -> string?) (ansi-wrap "4" "24" text)) 203
204
;;; Apply blinking text style.−203
(define (a:blink text) (ansi-wrap "5" "25" text))+205
(define (a:blink text) (: string? -> string?) (ansi-wrap "5" "25" text)) 206
207
;;; Apply inverse (swap foreground/background) text style.−206
(define (a:inverse text) (ansi-wrap "7" "27" text))+208
(define (a:inverse text) (: string? -> string?) (ansi-wrap "7" "27" text)) 209
210
;;; Apply hidden text style.−209
(define (a:hidden text) (ansi-wrap "8" "28" text))+211
(define (a:hidden text) (: string? -> string?) (ansi-wrap "8" "28" text)) 212
213
;;; Apply strikethrough text style.−212
(define (a:strikethrough text) (ansi-wrap "9" "29" text))+214
(define (a:strikethrough text) (: string? -> string?) (ansi-wrap "9" "29" text)) 215
216
;;; Reset all text attributes. 217
(define (a:reset text)+218
(: string? -> string?) 219
(if *ansi-enabled* 220
(string-append esc "0m" text esc "0m") 221
text))@@ -225,72 +228,84 @@
228
;;; (display (a:clear-screen)) 229
;;; ``` 230
(define (a:clear-screen)+231
(: -> string?) 232
(if *ansi-enabled* 233
(string-append esc "2J" esc "H") 234
"")) 235
236
;;; Clear current line 237
(define (a:clear-line)+238
(: -> string?) 239
(if *ansi-enabled* 240
(string-append esc "2K") 241
"")) 242
243
;;; Move cursor up N lines 244
(define (a:cursor-up n)+245
(: integer? -> string?) 246
(if *ansi-enabled* 247
(string-append esc (number->string n) "A") 248
"")) 249
250
;;; Move cursor down N lines 251
(define (a:cursor-down n)+252
(: integer? -> string?) 253
(if *ansi-enabled* 254
(string-append esc (number->string n) "B") 255
"")) 256
257
;;; Move cursor forward N columns 258
(define (a:cursor-forward n)+259
(: integer? -> string?) 260
(if *ansi-enabled* 261
(string-append esc (number->string n) "C") 262
"")) 263
264
;;; Move cursor back N columns 265
(define (a:cursor-back n)+266
(: integer? -> string?) 267
(if *ansi-enabled* 268
(string-append esc (number->string n) "D") 269
"")) 270
271
;;; Move cursor to home position (1,1) 272
(define (a:cursor-home)+273
(: -> string?) 274
(if *ansi-enabled* 275
(string-append esc "H") 276
"")) 277
278
;;; Move cursor to specific position (row, col) - 1-indexed 279
(define (a:cursor-position row col)+280
(: integer? integer? -> string?) 281
(if *ansi-enabled* 282
(string-append esc (number->string row) ";" (number->string col) "H") 283
"")) 284
285
;;; Hide cursor 286
(define (a:hide-cursor)+287
(: -> string?) 288
(if *ansi-enabled* 289
(string-append esc "?25l") 290
"")) 291
292
;;; Show cursor 293
(define (a:show-cursor)+294
(: -> string?) 295
(if *ansi-enabled* 296
(string-append esc "?25h") 297
"")) 298
299
;;; Save cursor position 300
(define (a:save-cursor)+301
(: -> string?) 302
(if *ansi-enabled* 303
(string-append esc "s") 304
"")) 305
306
;;; Restore cursor position 307
(define (a:restore-cursor)+308
(: -> string?) 309
(if *ansi-enabled* 310
(string-append esc "u") 311
""))@@ -305,6 +320,7 @@
320
;;; (strip-ansi (a:red "hello")) ; => "hello" 321
;;; ``` 322
(define (strip-ansi text)+323
(: string? -> string?) 324
(let ((esc-char (integer->char 27))) 325
(let loop ((chars (string->list text)) 326
(result '())