Skip to content

Commit

Permalink
Added text styles, which are:
Browse files Browse the repository at this point in the history
* bold
* dim
* underlined
* underlinedDouble
* inverted
* blink
* strikethrough

Signed-off-by: Vedant <[email protected]>
  • Loading branch information
vrnimje committed Sep 15, 2023
1 parent a91de38 commit 847a952
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/text.qf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Vertical {
Blue Text("The given button opens chrome in Linux")
bold BlueLight Text("The given button opens chrome in Linux")
str a
Red Button {
"chrome",
System("/usr/bin/google-chrome-stable"),
Animated,
a
}
Green Text("This text is Green")
strikethrough Green Text("This text is Green")
Button {
"Exit",
"Exit"
Expand Down
14 changes: 14 additions & 0 deletions examples/text_styles.qf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Vertical {
Text("This is normal")
bold Yellow Text("This is bold, yellow text")
dim Text("This is dim")
underlined Text("Underlined text")
underlinedDouble Magenta Text("Double underlines!!")
blink Text("This is blinking")
inverted Red Text("This has an inverted look")
strikethrough Text("This is strikethrough")
Red Button {
"X",
"Exit"
}
}
95 changes: 89 additions & 6 deletions include/quick-ftxui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ enum menu_option {
HorizontalAnimated,
VerticalAnimated
};
enum text_style {
none,
bold,
dim,
inverted,
underlined,
underlinedDouble,
blink,
strikethrough
};

enum colours {
Default,
Expand Down Expand Up @@ -160,6 +170,7 @@ struct dropdown {
};

struct dom_text {
text_style style = text_style::none;
colours color = colours::Default;
std::string content = "";
};
Expand Down Expand Up @@ -272,6 +283,7 @@ 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)
(std::string, content)
)
Expand Down Expand Up @@ -598,10 +610,67 @@ struct node_printer : boost::static_visitor<> {
void operator()(quick_ftxui_ast::dom_text const &text) const {
// tab(indent + tabsize);
// std::cout << "nil: \"" << text << '"' << std::endl;
data->components.push_back(ftxui::Renderer([&] {
return (ftxui::text(text.content) |
ftxui::color(quick_ftxui_ast::resolveColour(text.color)));
}));
switch (text.style) {
case quick_ftxui_ast::text_style::none:
data->components.push_back(ftxui::Renderer([&] {
return (ftxui::text(text.content) |
ftxui::color(quick_ftxui_ast::resolveColour(text.color)));
}));
break;

case quick_ftxui_ast::text_style::bold:
data->components.push_back(ftxui::Renderer([&] {
return (ftxui::text(text.content) | ftxui::bold |
ftxui::color(quick_ftxui_ast::resolveColour(text.color)));
}));
break;

case quick_ftxui_ast::text_style::blink:
data->components.push_back(ftxui::Renderer([&] {
return (ftxui::text(text.content) | ftxui::blink |
ftxui::color(quick_ftxui_ast::resolveColour(text.color)));
}));
break;

case quick_ftxui_ast::text_style::underlined:
data->components.push_back(ftxui::Renderer([&] {
return (ftxui::text(text.content) | ftxui::underlined |
ftxui::color(quick_ftxui_ast::resolveColour(text.color)));
}));
break;

case quick_ftxui_ast::text_style::underlinedDouble:
data->components.push_back(ftxui::Renderer([&] {
return (ftxui::text(text.content) | ftxui::underlinedDouble |
ftxui::color(quick_ftxui_ast::resolveColour(text.color)));
}));
break;

case quick_ftxui_ast::text_style::dim:
data->components.push_back(ftxui::Renderer([&] {
return (ftxui::text(text.content) | ftxui::dim |
ftxui::color(quick_ftxui_ast::resolveColour(text.color)));
}));
break;

case quick_ftxui_ast::text_style::inverted:
data->components.push_back(ftxui::Renderer([&] {
return (ftxui::text(text.content) | ftxui::inverted |
ftxui::color(quick_ftxui_ast::resolveColour(text.color)));
}));
break;

case quick_ftxui_ast::text_style::strikethrough:
data->components.push_back(ftxui::Renderer([&] {
return (ftxui::text(text.content) | ftxui::strikethrough |
ftxui::color(quick_ftxui_ast::resolveColour(text.color)));
}));
break;

default:
throw std::runtime_error("Should not reach here");
break;
}
}

void operator()(quick_ftxui_ast::separator const &text) const {
Expand Down Expand Up @@ -637,6 +706,7 @@ struct node_printer : boost::static_visitor<> {
}

void operator()(quick_ftxui_ast::paragraph const &text) const {

data->components.push_back(ftxui::Renderer([&] {
return (ftxui::paragraph(text.content) |
ftxui::color(quick_ftxui_ast::resolveColour(text.color)));
Expand Down Expand Up @@ -772,6 +842,17 @@ struct parser
("Double", quick_ftxui_ast::sep_style::Double)
("Dashed", quick_ftxui_ast::sep_style::Dashed)
;
text_style_kw
.add
("bold", quick_ftxui_ast::text_style::bold)
("underlined", quick_ftxui_ast::text_style::underlined)
("underlinedDouble", quick_ftxui_ast::text_style::underlinedDouble)
("dim", quick_ftxui_ast::text_style::dim)
("inverted", quick_ftxui_ast::text_style::inverted)
("blink", quick_ftxui_ast::text_style::blink)
("strikethrough", quick_ftxui_ast::text_style::strikethrough)
;

// clang-format on

quoted_string %= qi::lexeme['"' >> +(char_ - '"') >> '"'];
Expand Down Expand Up @@ -807,15 +888,16 @@ struct parser

str_var_decl %= qi::lit("str") >> identifier >> -('=' > quoted_string);

text_comp %= -(color_kw) >> qi::lit("Text") >> '(' >> quoted_string >> ')';
text_comp %= -(text_style_kw) >> -(color_kw) >> qi::lit("Text") >> '(' >>
quoted_string >> ')';

sep_comp %= -(sep_kw) >> qi::lit("separator");

para_comp %=
-(color_kw) >> qi::lit("Paragraph") >> '(' >> quoted_string >> ')';

node = button_comp | input_comp | slider_comp | menu_comp | toggle_comp |
drpdwn_comp | int_var_decl | str_var_decl | text_comp | sep_comp |
drpdwn_comp | text_comp | int_var_decl | str_var_decl | sep_comp |
para_comp | expression;

expression = alignment_kw >> '{' >> *node >> '}';
Expand Down Expand Up @@ -852,6 +934,7 @@ struct parser
qi::symbols<char, quick_ftxui_ast::menu_option> menuopt_kw;
qi::symbols<char, quick_ftxui_ast::colours> color_kw;
qi::symbols<char, quick_ftxui_ast::sep_style> sep_kw;
qi::symbols<char, quick_ftxui_ast::text_style> text_style_kw;
};

void parse_qf(std::string source_code) {
Expand Down

0 comments on commit 847a952

Please sign in to comment.