diff --git a/ansi_parser.rl b/ansi_parser.rl index e000928..7ba283f 100644 --- a/ansi_parser.rl +++ b/ansi_parser.rl @@ -82,12 +82,16 @@ using namespace fmt; %% write data; +#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) { diff --git a/config.cpp b/config.cpp index ca36bc1..752036c 100644 --- a/config.cpp +++ b/config.cpp @@ -10,6 +10,7 @@ json &Config::operator[](const std::string &key) { } std::wstring Config::wstring(const std::string main_key, const std::string sub_key) { + std::wstring_convert> $converter; const std::string& str_val = $config[main_key][sub_key]; return $converter.from_bytes(str_val); } diff --git a/config.hpp b/config.hpp index 8c2b504..67edaf9 100644 --- a/config.hpp +++ b/config.hpp @@ -6,12 +6,13 @@ using namespace nlohmann; struct Config { - std::wstring_convert> $converter; json $config; std::string $src_path = "./config.json"; Config(const std::string src_path); - Config(Config &other) = delete; + + Config(json config, std::string src_path) + : $config(config), $src_path(src_path) {} json &operator[](const std::string &key); diff --git a/gui.cpp b/gui.cpp index 0c69e39..51c10f5 100644 --- a/gui.cpp +++ b/gui.cpp @@ -57,6 +57,7 @@ void GUI::resize_map(int new_size) { } void GUI::create_renderer() { + Terminal::SetColorSupport(Terminal::Color::TrueColor); auto player = $world.get_the(); $map_view = Renderer([&] { diff --git a/main.cpp b/main.cpp index e57b6d9..bd4847e 100644 --- a/main.cpp +++ b/main.cpp @@ -52,7 +52,6 @@ void configure_world(DinkyECS::World &world, Map &game_map) { int main() { - Terminal::SetColorSupport(Terminal::Color::TrueColor); DinkyECS::World world; Map game_map(GAME_MAP_X, GAME_MAP_Y); diff --git a/render.cpp b/render.cpp index c1b8f0e..884494b 100644 --- a/render.cpp +++ b/render.cpp @@ -2,6 +2,7 @@ #include "ansi_parser.hpp" #include #include +#include std::array VALUES{ sf::Color{1, 4, 2}, // black @@ -35,6 +36,7 @@ SFMLRender::SFMLRender(Canvas &canvas, Screen &map_screen, Screen &screen) : $default_bg(color(Value::BLACK)), $ansi($default_fg, $default_bg) { + // force true color, but maybe I want to support different color sets $font.loadFromFile("./assets/text.otf"); $ui_text.setFont($font); $ui_text.setPosition(0,0); diff --git a/tests/ansi_parser.cpp b/tests/ansi_parser.cpp index 0c7108a..bea8797 100644 --- a/tests/ansi_parser.cpp +++ b/tests/ansi_parser.cpp @@ -3,7 +3,7 @@ #include #include "ansi_parser.hpp" #include - +#include #include "ftxui/dom/elements.hpp" // for text, bgcolor, color, vbox, hbox, separator, operator|, Elements, Element, Fit, border #include "ftxui/dom/node.hpp" // for Render @@ -53,10 +53,13 @@ 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); ANSIParser parser(default_fg, default_bg); + 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'; REQUIRE(correct_char);