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 3 weeks 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;
#include <ftxui/screen/terminal.hpp>
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) {

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

@ -6,12 +6,13 @@
using namespace nlohmann;
struct Config {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $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);

@ -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<Player>();
$map_view = Renderer([&] {

@ -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);

@ -2,6 +2,7 @@
#include "ansi_parser.hpp"
#include <cmath>
#include <fmt/core.h>
#include <array>
std::array<sf::Color, 10> 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);

@ -3,7 +3,7 @@
#include <string>
#include "ansi_parser.hpp"
#include <codecvt>
#include <iostream>
#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);

Loading…
Cancel
Save