#include <memory>
#include <string>
int main() {
std::string first_name;
std::string last_name;
std::string password;
std::string phoneNumber;
Component input_first_name = Input(&first_name,
"first name");
Component input_last_name = Input(&last_name,
"last name");
Component input_password = Input(&password,
"password", password_option);
Component input_phone_number = Input(&phoneNumber,
"phone number");
input_phone_number |= CatchEvent([&](
Event event) {
return event.is_character() && !std::isdigit(event.
character()[0]);
});
input_phone_number |= CatchEvent([&](
Event event) {
return event.is_character() && phoneNumber.size() > 10;
});
auto component = Container::Vertical({
input_first_name,
input_last_name,
input_password,
input_phone_number,
});
auto renderer = Renderer(component, [&] {
return vbox({
hbox(text(" First name : "), input_first_name->Render()),
hbox(text(" Last name : "), input_last_name->Render()),
hbox(text(" Password : "), input_password->Render()),
hbox(text(" Phone num : "), input_phone_number->Render()),
separator(),
text("Hello " + first_name + " " + last_name),
text("Your password is " + password),
text("Your phone number is " + phoneNumber),
}) |
border;
});
auto screen = ScreenInteractive::TerminalOutput();
screen.Loop(renderer);
}
std::shared_ptr< ComponentBase > Component
Represent an event. It can be key press event, a terminal resize, or more ...
std::string character() const