Have to force the terminal detected by FTXUI to use full color no matter what it detects in the actual terminal.

main
Zed A. Shaw 10 months ago
parent 0ba789697a
commit 707e9e3d6e
  1. 6
      ansi_parser.rl
  2. 1
      config.cpp
  3. 5
      config.hpp
  4. 1
      gui.cpp
  5. 1
      main.cpp
  6. 2
      render.cpp
  7. 5
      tests/ansi_parser.cpp

@ -82,12 +82,16 @@ using namespace fmt;
%% write data; %% write data;
#include <ftxui/screen/terminal.hpp>
ANSIParser::ANSIParser(sf::Color default_fg, sf::Color default_bg) : ANSIParser::ANSIParser(sf::Color default_fg, sf::Color default_bg) :
$default_fg(default_fg), $default_fg(default_fg),
$default_bg(default_bg) $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) { bool ANSIParser::parse(const std::string &screen, WriteCB write) {

@ -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 Config::wstring(const std::string main_key, const std::string sub_key) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
const std::string& str_val = $config[main_key][sub_key]; const std::string& str_val = $config[main_key][sub_key];
return $converter.from_bytes(str_val); return $converter.from_bytes(str_val);
} }

@ -6,12 +6,13 @@
using namespace nlohmann; using namespace nlohmann;
struct Config { struct Config {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
json $config; json $config;
std::string $src_path = "./config.json"; std::string $src_path = "./config.json";
Config(const std::string src_path); 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); json &operator[](const std::string &key);

@ -57,6 +57,7 @@ void GUI::resize_map(int new_size) {
} }
void GUI::create_renderer() { void GUI::create_renderer() {
Terminal::SetColorSupport(Terminal::Color::TrueColor);
auto player = $world.get_the<Player>(); auto player = $world.get_the<Player>();
$map_view = Renderer([&] { $map_view = Renderer([&] {

@ -52,7 +52,6 @@ void configure_world(DinkyECS::World &world, Map &game_map) {
int main() { int main() {
Terminal::SetColorSupport(Terminal::Color::TrueColor);
DinkyECS::World world; DinkyECS::World world;
Map game_map(GAME_MAP_X, GAME_MAP_Y); Map game_map(GAME_MAP_X, GAME_MAP_Y);

@ -2,6 +2,7 @@
#include "ansi_parser.hpp" #include "ansi_parser.hpp"
#include <cmath> #include <cmath>
#include <fmt/core.h> #include <fmt/core.h>
#include <array>
std::array<sf::Color, 10> VALUES{ std::array<sf::Color, 10> VALUES{
sf::Color{1, 4, 2}, // black sf::Color{1, 4, 2}, // black
@ -35,6 +36,7 @@ SFMLRender::SFMLRender(Canvas &canvas, Screen &map_screen, Screen &screen) :
$default_bg(color(Value::BLACK)), $default_bg(color(Value::BLACK)),
$ansi($default_fg, $default_bg) $ansi($default_fg, $default_bg)
{ {
// force true color, but maybe I want to support different color sets
$font.loadFromFile("./assets/text.otf"); $font.loadFromFile("./assets/text.otf");
$ui_text.setFont($font); $ui_text.setFont($font);
$ui_text.setPosition(0,0); $ui_text.setPosition(0,0);

@ -3,7 +3,7 @@
#include <string> #include <string>
#include "ansi_parser.hpp" #include "ansi_parser.hpp"
#include <codecvt> #include <codecvt>
#include <iostream>
#include "ftxui/dom/elements.hpp" // for text, bgcolor, color, vbox, hbox, separator, operator|, Elements, Element, Fit, border #include "ftxui/dom/elements.hpp" // for text, bgcolor, color, vbox, hbox, separator, operator|, Elements, Element, Fit, border
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
@ -53,10 +53,13 @@ std::string generate_colors() {
TEST_CASE("test out ragel parser", "[gui]") { TEST_CASE("test out ragel parser", "[gui]") {
std::string colors = generate_colors(); std::string colors = generate_colors();
std::cout << colors;
sf::Color default_fg(0,0,0); sf::Color default_fg(0,0,0);
sf::Color default_bg(100,100,100); sf::Color default_bg(100,100,100);
ANSIParser parser(default_fg, default_bg); 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 good = parser.parse(colors, [&](sf::Color bgcolor, sf::Color color, wchar_t ch) {
bool correct_char = ch == '#' || ch == ' ' || ch == '\n' || ch == '\r'; bool correct_char = ch == '#' || ch == ' ' || ch == '\n' || ch == '\r';
REQUIRE(correct_char); REQUIRE(correct_char);