Found my old LEL code and got the shell working, so tomorrow I'll try to make it layout some gui element.
This commit is contained in:
parent
8a6b38c1a4
commit
bfd2718cc9
8 changed files with 485 additions and 3 deletions
77
tests/ansi_parser.cpp
Normal file
77
tests/ansi_parser.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#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
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Black, Color::Blue, Color::BlueLight, Color::Cyan, Color::CyanLight, Color::Default, Color::GrayDark, Color::GrayLight, Color::Green, Color::GreenLight, Color::Magenta, Color::MagentaLight, Color::Red, Color::RedLight, Color::White, Color::Yellow, Color::YellowLight, Color::Palette256, ftxui
|
||||
#include <ftxui/screen/color_info.hpp> // for ColorInfo
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <ftxui/screen/terminal.hpp> // for ColorSupport, Color, Palette16, Palette256, TrueColor
|
||||
#include "render.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
using namespace ftxui;
|
||||
|
||||
std::string generate_colors() {
|
||||
SFMLRender::init_terminal();
|
||||
|
||||
REQUIRE(ftxui::Terminal::ColorSupport() == ftxui::Terminal::Color::TrueColor);
|
||||
|
||||
const int max_value = 255;
|
||||
const int value_increment = 8;
|
||||
const int hue_increment = 6;
|
||||
int saturation = max_value;
|
||||
Elements array;
|
||||
int count = 0;
|
||||
|
||||
for (int value = 0; value < max_value; value += 2 * value_increment) {
|
||||
Elements line;
|
||||
for (int hue = 0; hue < max_value; hue += hue_increment) {
|
||||
line.push_back(
|
||||
text("#") //
|
||||
| ftxui::color(Color::HSV(hue, saturation, value)) //
|
||||
| ftxui::bgcolor(Color::HSV(hue, saturation, value + value_increment)));
|
||||
count++;
|
||||
}
|
||||
array.push_back(hbox(std::move(line)));
|
||||
}
|
||||
|
||||
auto true_color_display = vbox({
|
||||
vbox(std::move(array)),
|
||||
});
|
||||
|
||||
auto document = vbox({hbox({
|
||||
true_color_display,
|
||||
})});
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
return screen.ToString();
|
||||
}
|
||||
|
||||
TEST_CASE("test out ragel parser", "[gui]") {
|
||||
SFMLRender::init_terminal();
|
||||
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 ansi(default_fg, default_bg);
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
||||
std::string colors = generate_colors();
|
||||
std::wstring colors_utf = $converter.from_bytes(colors);
|
||||
|
||||
bool good = ansi.parse(colors_utf,
|
||||
[&](sf::Color color[[maybe_unused]], sf::Color bgcolor[[maybe_unused]]){
|
||||
},
|
||||
[&](wchar_t ch) {
|
||||
bool correct_char = ch == '#' || ch == ' ' || ch == '\n' || ch == '\r';
|
||||
REQUIRE(correct_char);
|
||||
});
|
||||
|
||||
REQUIRE(good);
|
||||
}
|
21
tests/lel.cpp
Normal file
21
tests/lel.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "lel.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
#include "ansi_parser.hpp"
|
||||
#include <codecvt>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
TEST_CASE("test basic ops", "[lel]") {
|
||||
LELParser parser;
|
||||
|
||||
bool good = parser.parse(
|
||||
"[ label_1 | label3 ]"
|
||||
"[ (300,300)*text1 | (150)people ]"
|
||||
"[ <label2 | _ ]"
|
||||
"[ message | buttons ]");
|
||||
|
||||
REQUIRE(good);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue