Skip to content

Commit

Permalink
fixup: Add 24bit color support
Browse files Browse the repository at this point in the history
  • Loading branch information
xs5871 committed Nov 23, 2024
1 parent 05a7b23 commit 40ffa57
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions test/color.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -179,25 +179,22 @@ 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 'f<b>o</b>o' -> '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");
t.is (Color::colorize ("foo", "red on 0x0a1b2c"), std::string ("\033[38;2;128;0;0;48;2;10;27;44mfoo\033[0m"), "red on 0x0a1b2c -> ^[[38;2;128;0;0;48;2;10;27;44m");
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 grey23"), std::string ("\033[38;2;16;16;16;48;2;240;240;240mfoo\033[0m"), "0x101010 on grey23 -> ^[[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 'f<b>o</b>o' -> '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;
Expand Down

0 comments on commit 40ffa57

Please sign in to comment.