Now have more test for the base functionality but need to push render tests and find a way to test the GUI. I've also brought in sol2 for lua integration but not sure what to do with it.
parent
d0d62836e3
commit
e86d474c7c
@ -0,0 +1,17 @@ |
||||
#define SOL_ALL_SAFETIES_ON 1 |
||||
#include <sol/sol.hpp> |
||||
|
||||
#include <iostream> |
||||
|
||||
int main(int, char*[]) { |
||||
std::cout << "=== opening a state ===" << std::endl; |
||||
|
||||
sol::state lua; |
||||
// open some common libraries
|
||||
lua.open_libraries(sol::lib::base, sol::lib::package); |
||||
lua.script("print('bark bark bark!')"); |
||||
|
||||
std::cout << std::endl; |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,75 @@ |
||||
#include <catch2/catch_test_macros.hpp> |
||||
#include <fmt/core.h> |
||||
#include <ftxui/screen/terminal.hpp> // for ColorSupport, Color, Palette16, Palette256, TrueColor |
||||
#include <ftxui/dom/elements.hpp> // for hflow, paragraph, separator, hbox, vbox, filler, operator|, border, Element |
||||
#include "panel.hpp" |
||||
#include "ansi_parser.hpp" |
||||
|
||||
using namespace ftxui; |
||||
using namespace fmt; |
||||
using std::string; |
||||
|
||||
void test_ansi_parsing(Panel &panel) { |
||||
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); |
||||
|
||||
bool good = ansi.parse(panel.to_string(), |
||||
[&](sf::Color color, sf::Color bgcolor){ |
||||
// ignore color
|
||||
}, |
||||
[&](wchar_t ch) { |
||||
// ignore char
|
||||
}); |
||||
|
||||
REQUIRE(good == true); |
||||
} |
||||
|
||||
TEST_CASE("can render a simple text panel", "[panel]") { |
||||
ftxui::Terminal::SetColorSupport(ftxui::Terminal::Color::TrueColor); |
||||
|
||||
Panel text_panel(0, 0, 20, 5); |
||||
|
||||
bool show_modal = false; |
||||
|
||||
auto buttons = Container::Horizontal({ |
||||
Button("OK", [&]{ show_modal = false; }), |
||||
Button("CANCEL", [&]{ show_modal = false; }), |
||||
}); |
||||
|
||||
auto text_box = Renderer([buttons]{ |
||||
return hbox({ |
||||
hflow( |
||||
vbox(text("I AM TEXT")), |
||||
buttons->Render() |
||||
)}); |
||||
}); |
||||
|
||||
text_panel.set_renderer(text_box); |
||||
text_panel.add(buttons); |
||||
|
||||
text_panel.resize(10,10); |
||||
text_panel.render(); |
||||
test_ansi_parsing(text_panel); |
||||
|
||||
const Screen &screen = text_panel.screen(); |
||||
REQUIRE(screen.dimx() == 10); |
||||
REQUIRE(screen.dimx() == 10); |
||||
} |
||||
|
||||
TEST_CASE("can render a simple grid panel", "[panel]") { |
||||
Terminal::SetColorSupport(Terminal::Color::TrueColor); |
||||
|
||||
Panel grid_panel(20, 20, 20, 5, true); |
||||
|
||||
auto text_box = Renderer([]{ |
||||
return hbox({ |
||||
hflow(vbox(text("I AM TEXT")))}); |
||||
}); |
||||
|
||||
grid_panel.set_renderer(text_box); |
||||
grid_panel.resize(10,10); |
||||
grid_panel.render(); |
||||
test_ansi_parsing(grid_panel); |
||||
} |
@ -0,0 +1,38 @@ |
||||
#include <catch2/catch_test_macros.hpp> |
||||
#include <fmt/core.h> |
||||
#include "render.hpp" |
||||
#include "panel.hpp" |
||||
|
||||
using namespace ftxui; |
||||
using namespace fmt; |
||||
using std::string; |
||||
|
||||
void run_renderer(SFMLRender &renderer, Panel &panel) { |
||||
panel.render(); |
||||
renderer.display(); |
||||
REQUIRE(renderer.is_open() == true); |
||||
renderer.clear(); |
||||
renderer.draw(panel); |
||||
} |
||||
|
||||
TEST_CASE("can render a text or grid panel", "[render]") { |
||||
SFMLRender renderer; |
||||
|
||||
Panel panel(0, 0, 20, 5); |
||||
Panel grid(200, 200, 20, 5, true); |
||||
|
||||
auto text_box = Renderer([]{ |
||||
return hbox({ |
||||
hflow( |
||||
vbox(text("I AM TEXT")) |
||||
)}); |
||||
}); |
||||
|
||||
panel.set_renderer(text_box); |
||||
grid.set_renderer(text_box); |
||||
|
||||
run_renderer(renderer, panel); |
||||
run_renderer(renderer, grid); |
||||
|
||||
renderer.close(); |
||||
} |
@ -0,0 +1,14 @@ |
||||
[wrap-file] |
||||
directory = lua-5.4.6 |
||||
source_url = https://www.lua.org/ftp/lua-5.4.6.tar.gz |
||||
source_filename = lua-5.4.6.tar.gz |
||||
source_hash = 7d5ea1b9cb6aa0b59ca3dde1c6adcb57ef83a1ba8e5432c0ecd06bf439b3ad88 |
||||
patch_filename = lua_5.4.6-5_patch.zip |
||||
patch_url = https://wrapdb.mesonbuild.com/v2/lua_5.4.6-5/get_patch |
||||
patch_hash = 755ec591b6b4739650ba6bb11b4feca2d221ab7f80f024dd625f50c8932ad76f |
||||
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/lua_5.4.6-5/lua-5.4.6.tar.gz |
||||
wrapdb_version = 5.4.6-5 |
||||
|
||||
[provide] |
||||
lua-5.4 = lua_dep |
||||
lua = lua_dep |
@ -0,0 +1,11 @@ |
||||
[wrap-git] |
||||
url = https://github.com/ThePhD/sol2.git |
||||
revision = v3.3.1 |
||||
depth = 1 |
||||
method = meson |
||||
# patch_filename = |
||||
# patch_hash = |
||||
|
||||
|
||||
[provide] |
||||
sol2 = sol2_dep |
Loading…
Reference in new issue