Split out utils so that we don't need SRFI.

This commit is contained in:
Dominik Pantůček 2023-03-14 23:13:26 +01:00
parent 98a772cee9
commit 5b32f3a30a
3 changed files with 66 additions and 18 deletions

View file

@ -35,7 +35,8 @@
(import scheme
(chicken base)
(chicken string)
testing)
testing
utils)
;; Only basic ANSI colors and bold attribute support.
(define colors
@ -50,18 +51,6 @@
(#:default . 0)
(#:bold . 1)))
;; Returns a list with elements matching pred? predicate.
(define (filter pred? lst)
(let loop ((lst lst)
(res '()))
(if (null? lst)
(reverse res)
(if (pred? (car lst))
(loop (cdr lst)
(cons (car lst) res))
(loop (cdr lst)
res)))))
;; Returns ANSI sequence changing color and/or bold attribute.
(define (ansi . args)
(let ((argsl
@ -81,8 +70,6 @@
(define (ansi-tests!)
(run-tests
ansi
(test-equal? filter (filter odd? '(1 2 3 4)) '(1 3))
(test-equal? filter (filter odd? '(2 4)) '())
(test-equal? ansi (ansi #:red) "\x1b[31m")
(test-equal? ansi (ansi #:nonsense) "")
(test-equal? ansi (ansi #:default) "\x1b[0m")