From 0b6ea73485be175e7c3614e9adb5a864662e7e82 Mon Sep 17 00:00:00 2001 From: xs5871 Date: Sat, 23 Nov 2024 20:18:29 +0000 Subject: [PATCH] fixup: Add 24bit color support --- test/color.t.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/test/color.t.cpp b/test/color.t.cpp index f77be08..2bef66d 100644 --- a/test/color.t.cpp +++ b/test/color.t.cpp @@ -31,7 +31,7 @@ //////////////////////////////////////////////////////////////////////////////// int main (int, char**) { - UnitTest t (40 + 256 + 256 + 6*6*6 + 6*6*6 + 1 + 24 + 24 + 5); + UnitTest t (40 + 256 + 256 + 6*6*6 + 6*6*6 + 1 + 24 + 24 + 7 + 6); // Names matched to values. t.is ((int) Color (""), (int) Color (Color::nocolor), "'' == Color::nocolor"); @@ -179,15 +179,6 @@ int main (int, char**) t.is (Color::colorize ("foo", color), std::string (codes), description); } - // std::string Color::strip (const std::string&); - t.is (Color::strip (""), "", "Color::strip '' -> ''"); - t.is (Color::strip ("foo"), "foo", "Color::strip 'foo' -> 'foo'"); - t.is (Color::strip ("f\033[1mo\033[0mo"), "foo", "Color::strip 'foo' -> 'foo'"); - - // std::string Color::code () const; - t.is (Color ("rgb012 on bright yellow").code (), "", "Color::code 'rgb0123 on bright yellow' --> ^[[38;5;24m^[[48;5;11m"); - - // 24-bit color t.is (Color::colorize ("foo", "0x0a1b2c"), std::string ("\033[38;2;10;27;44mfoo\033[0m"), "0x0a1b2c -> ^[[38;2;10;27;44m"); t.is (Color::colorize ("foo", "0x0a1b2c on color127"), std::string ("\033[38;2;10;27;44;48;2;126;0;126mfoo\033[0m"), "0x0a1b2c on color127 -> ^[[38;2;10;27;44;48;2;126;0;126m"); @@ -195,9 +186,15 @@ int main (int, char**) t.is (Color::colorize ("foo", "bold red on 0x0a1b2c"), std::string ("\033[1;38;2;128;0;0;48;2;10;27;44mfoo\033[0m"), "bold on 0x0a1b2c -> ^[[1;38;2;255;0;0;48;2;10;27;44m"); t.is (Color::colorize ("foo", "0x0a1b2c on bright red"), std::string ("\033[38;2;10;27;44;48;2;255;0;0mfoo\033[0m"), "0x0a1b2c on bright red -> ^[[38;2;10;27;44;48;2;255;0;0m"); t.is (Color::colorize ("foo", "0x010101 on grey0"), std::string ("\033[38;2;1;1;1;48;2;10;10;10mfoo\033[0m"), "0x0101010 on grey0 -> ^[[38;2;1;1;1;48;2;10;10;10m"); - t.is (Color::colorize ("foo", "0x101010 on grey23"), std::string ("\033[38;2;16;16;16;48;2;240;240;240mfoo\033[0m"), "0x101010 on grey0 -> ^[[38;2;16;16;16;48;2;240;240;240m"); + t.is (Color::colorize ("foo", "0x101010 on grey0"), std::string ("\033[38;2;16;16;16;48;2;240;240;240mfoo\033[0m"), "0x101010 on grey0 -> ^[[38;2;16;16;16;48;2;240;240;240m"); + // std::string Color::strip (const std::string&); + t.is (Color::strip (""), "", "Color::strip '' -> ''"); + t.is (Color::strip ("foo"), "foo", "Color::strip 'foo' -> 'foo'"); + t.is (Color::strip ("f\033[1mo\033[0mo"), "foo", "Color::strip 'foo' -> 'foo'"); + // std::string Color::code () const; + t.is (Color ("rgb012 on bright yellow").code (), "", "Color::code 'rgb0123 on bright yellow' --> ^[[38;5;24m^[[48;5;11m"); t.is (Color ("0x0F1E2D").code (), "", "Color::code '0x0F1E2D' --> ^[[38;2;15;30;45m"); // std::string Color::end () const;