From f223257aada84880adf2662404014d9bd177582a Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 3 Nov 2024 01:21:00 -0500 Subject: [PATCH] Have to tweak when to test that true color is set, and also when to do it for the test. --- ansi_parser.cpp | 18 +++++++++++------- tests/ansi_parser.cpp | 11 ++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ansi_parser.cpp b/ansi_parser.cpp index 7380bc7..49de455 100644 --- a/ansi_parser.cpp +++ b/ansi_parser.cpp @@ -87,12 +87,16 @@ static const int foo_en_main = 19; #line 84 "ansi_parser.rl" +#include ANSIParser::ANSIParser(sf::Color default_fg, sf::Color default_bg) : $default_fg(default_fg), $default_bg(default_bg) { - + // the parser only handles full color so force it + if(ftxui::Terminal::ColorSupport() != ftxui::Terminal::Color::TrueColor) { + ftxui::Terminal::SetColorSupport(ftxui::Terminal::Color::TrueColor); + } } bool ANSIParser::parse(const std::string &screen, WriteCB write) { @@ -112,14 +116,14 @@ bool ANSIParser::parse(std::wstring_view codes, WriteCB write) { sf::Color &target = color; -#line 107 "ansi_parser.cpp" +#line 111 "ansi_parser.cpp" { cs = foo_start; } -#line 110 "ansi_parser.rl" +#line 114 "ansi_parser.rl" -#line 110 "ansi_parser.cpp" +#line 114 "ansi_parser.cpp" { int _klen; unsigned int _trans; @@ -272,7 +276,7 @@ _match: #line 59 "ansi_parser.rl" { } break; -#line 249 "ansi_parser.cpp" +#line 253 "ansi_parser.cpp" } } @@ -292,7 +296,7 @@ _again: #line 59 "ansi_parser.rl" { } break; -#line 267 "ansi_parser.cpp" +#line 271 "ansi_parser.cpp" } } } @@ -300,7 +304,7 @@ _again: _out: {} } -#line 111 "ansi_parser.rl" +#line 115 "ansi_parser.rl" return p - pe == 0; } diff --git a/tests/ansi_parser.cpp b/tests/ansi_parser.cpp index bea8797..e95d6ce 100644 --- a/tests/ansi_parser.cpp +++ b/tests/ansi_parser.cpp @@ -17,6 +17,8 @@ using namespace fmt; using namespace ftxui; std::string generate_colors() { + REQUIRE(ftxui::Terminal::ColorSupport() == Terminal::Color::TrueColor); + const int max_value = 255; const int value_increment = 8; const int hue_increment = 6; @@ -36,8 +38,6 @@ std::string generate_colors() { array.push_back(hbox(std::move(line))); } - println("MADE {} CHARS", count); - auto true_color_display = vbox({ vbox(std::move(array)), }); @@ -52,13 +52,14 @@ std::string generate_colors() { } TEST_CASE("test out ragel parser", "[gui]") { - std::string colors = generate_colors(); - std::cout << colors; sf::Color default_fg(0,0,0); sf::Color default_bg(100,100,100); + + // this sets the Truecolor so need to do it first ANSIParser parser(default_fg, default_bg); + std::string colors = generate_colors(); + std::cout << colors; - REQUIRE(ftxui::Terminal::ColorSupport() == Terminal::Color::TrueColor); bool good = parser.parse(colors, [&](sf::Color bgcolor, sf::Color color, wchar_t ch) { bool correct_char = ch == '#' || ch == ' ' || ch == '\n' || ch == '\r';