From 05521e5e1d6bb0a192826a9b2b5bbdf73a762a4e Mon Sep 17 00:00:00 2001 From: krzygorz Date: Thu, 7 Nov 2019 18:34:41 +0100 Subject: [PATCH 1/3] use string-append for building ansi escape codes --- lib/chibi/show/color.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chibi/show/color.scm b/lib/chibi/show/color.scm index b21222d0..7a324e12 100644 --- a/lib/chibi/show/color.scm +++ b/lib/chibi/show/color.scm @@ -18,7 +18,7 @@ (else "0"))) (define (ansi-escape color) - (each (integer->char 27) "[" (color->ansi color) "m")) + (string-append (string (integer->char 27)) "[" (color->ansi color) "m")) (define (colored new-color . args) (fn (color) From 15fef988afeef11d551e90ea4ad211b1114efda3 Mon Sep 17 00:00:00 2001 From: krzygorz Date: Thu, 7 Nov 2019 22:31:29 +0100 Subject: [PATCH 2/3] add a test for col with unicode and ANSI escapes --- lib/chibi/show-test.sld | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/chibi/show-test.sld b/lib/chibi/show-test.sld index dff1efaa..c57383d5 100644 --- a/lib/chibi/show-test.sld +++ b/lib/chibi/show-test.sld @@ -739,6 +739,10 @@ def | 6 (show #f (with ((pad-char #\〜)) (padded/both 5 "日本語")))) (test "日本語" (show #f (as-unicode (with ((pad-char #\〜)) (padded/both 5 "日本語"))))) + (test "\x1b;[31m1234567\x1b;[0m col: 7" + (show #f (as-unicode (as-red "1234567") (fn ((col)) (each " col: " col))))) + (test "日本語 col: 6" + (show #f (as-unicode "日本語" (fn ((col)) (each " col: " col))))) ;; from-file ;; for reference, filesystem-test relies on creating files under /tmp From 5c43ca772035c18d4e78eac0baff2d38e28c090e Mon Sep 17 00:00:00 2001 From: krzygorz Date: Thu, 7 Nov 2019 22:37:33 +0100 Subject: [PATCH 3/3] move the col+ansi test to color section --- lib/chibi/show-test.sld | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/chibi/show-test.sld b/lib/chibi/show-test.sld index c57383d5..8880ac14 100644 --- a/lib/chibi/show-test.sld +++ b/lib/chibi/show-test.sld @@ -733,14 +733,14 @@ def | 6 (test "\x1B;[31mred\x1B;[0m" (show #f (as-red "red"))) (test "\x1B;[31mred\x1B;[34mblue\x1B;[31mred\x1B;[0m" (show #f (as-red "red" (as-blue "blue") "red"))) + (test "\x1b;[31m1234567\x1b;[0m col: 7" + (show #f (as-unicode (as-red "1234567") (fn ((col)) (each " col: " col))))) ;; unicode (test "〜日本語〜" (show #f (with ((pad-char #\〜)) (padded/both 5 "日本語")))) (test "日本語" (show #f (as-unicode (with ((pad-char #\〜)) (padded/both 5 "日本語"))))) - (test "\x1b;[31m1234567\x1b;[0m col: 7" - (show #f (as-unicode (as-red "1234567") (fn ((col)) (each " col: " col))))) (test "日本語 col: 6" (show #f (as-unicode "日本語" (fn ((col)) (each " col: " col)))))