77#include < boost/variant/apply_visitor.hpp>
88#include < boost/variant/recursive_variant.hpp>
99
10+ #include " ftxui/component/component.hpp" // for Input, Renderer, Vertical
11+ #include " ftxui/component/component_base.hpp" // for ComponentBase
12+ #include " ftxui/component/component_options.hpp" // for InputOption
13+ #include " ftxui/component/mouse.hpp" // for ftxui
14+ #include " ftxui/component/screen_interactive.hpp"
15+ #include " ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border
16+ #include " ftxui/screen/screen.hpp"
17+ #include " ftxui/util/ref.hpp" // for Ref
18+
1019#include < iostream>
1120#include < string>
1221
@@ -21,9 +30,10 @@ namespace quick_ftxui_ast {
2130struct nil {};
2231struct button ;
2332struct expression ;
24- // struct function ;
33+ struct input ;
2534
2635typedef boost::variant<nil, boost::recursive_wrapper<button>,
36+ boost::recursive_wrapper<input>,
2737 boost::recursive_wrapper<expression>>
2838 node;
2939
@@ -32,6 +42,12 @@ struct button {
3242 std::string func;
3343};
3444
45+ struct input {
46+ std::string placeholder;
47+ std::string temp;
48+ std::string option;
49+ };
50+
3551struct expression {
3652 button first;
3753 std::list<node> rest;
@@ -49,6 +65,13 @@ inline std::ostream &operator<<(std::ostream &out, button b) {
4965 return out;
5066}
5167
68+ // print function for debugging
69+ inline std::ostream &operator <<(std::ostream &out, input b) {
70+ out << " Placeholder: " << b.placeholder << " | Temp: " << b.temp
71+ << " | Options: " << b.option ;
72+ return out;
73+ }
74+
5275} // namespace quick_ftxui_ast
5376} // namespace client
5477
@@ -58,6 +81,11 @@ BOOST_FUSION_ADAPT_STRUCT(client::quick_ftxui_ast::button,
5881 (std::string, func)
5982)
6083
84+ BOOST_FUSION_ADAPT_STRUCT(client::quick_ftxui_ast::input,
85+ (std::string, placeholder)
86+ (std::string, temp)
87+ (std::string, option)
88+ )
6189
6290BOOST_FUSION_ADAPT_STRUCT(client::quick_ftxui_ast::expression,
6391 (client::quick_ftxui_ast::button, first)
@@ -80,24 +108,43 @@ void tab(int indent) {
80108 std::cout << ' ' ;
81109}
82110
111+ struct component_meta_data {
112+ ftxui::ScreenInteractive *screen;
113+ ftxui::Components components;
114+ };
115+
83116struct ast_printer {
84- ast_printer (int indent = 0 ) : indent(indent) {}
117+ ast_printer (component_meta_data *data_, int indent = 0 )
118+ : indent(indent), data(data_) {}
119+ ast_printer (component_meta_data *data_) : data(data_) {}
85120
86121 void operator ()(quick_ftxui_ast::expression const &) const ;
87122
88123 int indent;
124+
125+ component_meta_data *data;
89126};
90127
91128struct node_printer : boost::static_visitor<> {
92- node_printer (int indent = 0 ) : indent(indent) {}
129+ node_printer (component_meta_data *data_, int indent = 0 )
130+ : indent(indent), data(data_) {}
93131
94132 void operator ()(client::quick_ftxui_ast::expression const &expr) const {
95- ast_printer (indent + tabsize)(expr);
133+ ast_printer (data, indent + tabsize)(expr);
96134 }
97135
98136 void operator ()(quick_ftxui_ast::button const &text) const {
99137 tab (indent + tabsize);
100138 std::cout << " button: " << text << std::endl;
139+ if (text.func == " Exit" ) {
140+ data->components .push_back (ftxui::Button (
141+ text.placeholder , data->screen ->ExitLoopClosure ()));
142+ }
143+ }
144+
145+ void operator ()(quick_ftxui_ast::input const &text) const {
146+ tab (indent + tabsize);
147+ std::cout << " input: " << text << std::endl;
101148 }
102149
103150 void operator ()(quick_ftxui_ast::nil const &text) const {
@@ -106,18 +153,19 @@ struct node_printer : boost::static_visitor<> {
106153 }
107154
108155 int indent;
156+ component_meta_data *data;
109157};
110158
111159void ast_printer::operator ()(
112160 client::quick_ftxui_ast::expression const &expr) const {
113161 tab (indent);
114162 std::cout << " tag: "
115- << " Button " << std::endl;
163+ << " Node " << std::endl;
116164 std::cout << ' {' << std::endl;
117- node_printer (indent).operator ()(expr.first );
165+ node_printer (data, indent).operator ()(expr.first );
118166
119167 for (quick_ftxui_ast::node const &node : expr.rest ) {
120- boost::apply_visitor (node_printer (indent), node);
168+ boost::apply_visitor (node_printer (data, indent), node);
121169 }
122170
123171 tab (indent);
@@ -162,7 +210,10 @@ struct parser
162210 button_comp %= qi::lit (" Button" ) >> ' {' >> quoted_string >> ' ,' >>
163211 quoted_string >> ' }' ;
164212
165- node = button_comp | expression;
213+ input_comp %= qi::lit (" Input" ) >> ' {' >> quoted_string >> ' ,' >>
214+ quoted_string >> ' ,' >> quoted_string >> ' }' ;
215+
216+ node = button_comp | input_comp | expression;
166217
167218 expression = ' {' >> button_comp >> *node >> ' }' ;
168219
@@ -177,6 +228,7 @@ struct parser
177228 qi::rule<Iterator, quick_ftxui_ast::node(), ascii::space_type> node;
178229 qi::rule<Iterator, quick_ftxui_ast::button(), ascii::space_type>
179230 button_comp;
231+ qi::rule<Iterator, quick_ftxui_ast::input(), ascii::space_type> input_comp;
180232 qi::rule<Iterator, std::string(), ascii::space_type> quoted_string;
181233};
182234} // namespace quick_ftxui_parser
0 commit comments