diff --git a/examples/text.qf b/examples/text.qf index 3e18670..42fc7ab 100644 --- a/examples/text.qf +++ b/examples/text.qf @@ -1,5 +1,5 @@ Vertical { - bold BlueLight Text("The given button opens chrome in Linux") + BlueLight bold Text("The given button opens chrome in Linux") str a Red Button { "chrome", @@ -7,9 +7,9 @@ Vertical { Animated, a } - strikethrough Green Text("This text is Green") + Green strikethrough Text("This text is Green") Horizontal { - hyperlink Blue Text("Google", "https://www.google.com/") + Blue hyperlink Text("Google", "https://www.google.com/") } Button { "Exit", diff --git a/examples/text_styles.qf b/examples/text_styles.qf index d7e5a5d..7db6097 100644 --- a/examples/text_styles.qf +++ b/examples/text_styles.qf @@ -1,11 +1,11 @@ Vertical { Text("This is normal") - bold Yellow Text("This is bold, yellow text") + Yellow bold Text("This is bold, yellow text") dim Text("This is dim") underlined Text("Underlined text") - underlinedDouble Magenta Text("Double underlines!!") + Magenta underlinedDouble Text("Double underlines!!") blink Text("This is blinking") - inverted Red Text("This has an inverted look") + Red inverted Text("This has an inverted look") strikethrough Text("This is strikethrough") Red Button { "X", diff --git a/include/quick-ftxui.hpp b/include/quick-ftxui.hpp index e44d417..7621564 100644 --- a/include/quick-ftxui.hpp +++ b/include/quick-ftxui.hpp @@ -180,8 +180,8 @@ struct dropdown { }; struct dom_text { - text_style style = text_style::none; colours color = colours::Default; + text_style style = text_style::none; std::string content = ""; std::string link = ""; }; @@ -295,8 +295,8 @@ BOOST_FUSION_ADAPT_STRUCT(quick_ftxui_ast::dropdown, ) BOOST_FUSION_ADAPT_STRUCT(quick_ftxui_ast::dom_text, - (quick_ftxui_ast::text_style, style) (quick_ftxui_ast::colours, color) + (quick_ftxui_ast::text_style, style) (std::string, content) (std::string, link) ) @@ -954,7 +954,7 @@ struct parser str_var_decl %= qi::lit("str") >> identifier >> -('=' > quoted_string); - text_comp %= -(text_style_kw) >> -(color_kw) >> qi::lit("Text") >> '(' >> + text_comp %= -(color_kw) >> -(text_style_kw) >> qi::lit("Text") >> '(' >> quoted_string >> -(',' >> quoted_string) >> ')'; sep_comp %= -(sep_kw) >> qi::lit("separator"); diff --git a/tests/test1.cpp b/tests/test1.cpp index 54c71d7..e75ae07 100644 --- a/tests/test1.cpp +++ b/tests/test1.cpp @@ -173,3 +173,133 @@ TEST_CASE("Parse Recursive") { }\ }")); } + +TEST_CASE("Parse DOM elements") { + REQUIRE(parse_helper("Vertical {\ + Text(\"Hello World\") \ + separator \ + Paragraph(\"Hello to his paragraph\")\ + HeavyBorder Horizontal { \ + RedLight dim Text(\"amool\") \ + }\ + }")); + + // Parse text and its styles + REQUIRE(parse_helper("Vertical {\ + Blue Text(\"Hello World\") \ + Red bold Text(\"amool\") \ + dim Text(\"bmpp\") \ + underlined Text(\"cmqq\") \ + Magenta underlinedDouble Text(\"dmrr\") \ + blink Text(\"emss\") \ + Red inverted Text(\"This has an inverted look\") \ + strikethrough Text(\"This is strikethrough\") \ + }")); + + REQUIRE(!parse_helper("Vertical {\ + blue Text(\"Hello World\") \ + Bold Red Text(\"amool\") \ + DIM Text(\"bmpp\") \ + underlined Text(cmqq) \ + underlinedDouble Magenta Text(\"dmrr\") \ + blink Text(123) \ + inverted Red Text(\"This has an inverted look\") \ + strikethrough Text(\"This is strikethrough\") \ + }")); + + // Paragraphs, separators and borders + REQUIRE(parse_helper("HeavyBorder Vertical {\ + Paragraph(\"I guess I should have talked before going into the unknown\")\ + separator \ + Paragraph(\"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \ + sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \ + Ut enim ad minim veniam, quis nostrud exercitation ullamco \ + laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure \ + dolor in reprehenderit in voluptate velit esse cillum dolore \ + eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat \ + non proident, sunt in culpa qui officia deserunt mollit anim \ + id est laborum.\") \ + Dashed separator \ + Border Horizontal { \ + Paragraph(\"This is my peace offering.\") \ + }\ + }")); + + REQUIRE(!parse_helper("Heavy Border Vertical {\ + Paragraph(\"I guess I should have talked before going into the unknown\")\ + separator \ + Paragraph(\"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \ + sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \ + Ut enim ad minim veniam, quis nostrud exercitation ullamco \ + laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure \ + dolor in reprehenderit in voluptate velit esse cillum dolore \ + eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat \ + non proident, sunt in culpa qui officia deserunt mollit anim \ + id est laborum.\") \ + dashed separator \ + Paragraph(This is my peace offering) \ + }")); +} + +TEST_CASE("Parse Components and DOM together") { + REQUIRE(parse_helper("HeavyBorder Vertical {\ + int x \ + Blue Slider{ \ + \"amool\", \ + x, \ + 0, \ + 30, \ + 2 \ + } \ + Double separator \ + LightBorder Horizontal { \ + Yellow dim Text(\"bmpp\") \ + } \ + str y \ + Button { \ + \"amool\", \ + System(\"ls -l\"), \ + y \ + } \ + }")); + + REQUIRE(parse_helper("DashedBorder Vertical{\ + int x \ + Blue Dropdown{ \ + [\"amool\", \"bmpp\", \"cmqq\",], \ + x \ + } \ + Light separator \ + RoundedBorder Horizontal { \ + Yellow strikethrough Text(\"dmrr\") \ + } \ + str y \ + Button { \ + \"amool\", \ + System(\"ls -l\"), \ + Animated, \ + y \ + } \ + }")); + + REQUIRE(!parse_helper("Heavy Border Vertical {\ + int x \ + Blue Slider{ \ + \"amool\", \ + x, \ + 0, \ + 30, \ + 2 \ + } \ + Double Separator \ + Horizontal { \ + LightBorder Yellow dim Text(\"bmpp\") \ + } \ + str y \ + Button { \ + \"amool\", \ + System(\"ls -l\"), \ + y \ + } \ + }")); +}