examples/component/input.cpp

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<memory>//forallocator,__shared_ptr_access
    #include<string>//forchar_traits,operator+,string,basic_string

    #include"ftxui/component/captured_mouse.hpp"//forftxui
    #include"ftxui/component/component.hpp"//forInput,Renderer,Vertical
    #include"ftxui/component/component_base.hpp"//forComponentBase
    #include"ftxui/component/component_options.hpp"//forInputOption
    #include"ftxui/component/screen_interactive.hpp"//forComponent,ScreenInteractive
    #include"ftxui/dom/elements.hpp"//fortext,hbox,separator,Element,operator|,vbox,border
    #include"ftxui/util/ref.hpp"//forRef

    intmain(){
    usingnamespaceftxui;

    //Thedata:
    std::stringfirst_name;
    std::stringlast_name;
    std::stringpassword;
    std::stringphoneNumber;

    //Thebasicinputcomponents:
    Componentinput_first_name=Input(&first_name,"firstname");
    Componentinput_last_name=Input(&last_name,"lastname");

    //Thepasswordinputcomponent:
    InputOptionpassword_option;
    password_option.password=true;
    Componentinput_password=Input(&password,"password",password_option);

    //Thephonenumberinputcomponent:
    //Weareusing`CatchEvent`tofilteroutnon-digitcharacters.
    Componentinput_phone_number=Input(&phoneNumber,"phonenumber");
    input_phone_number|=CatchEvent([&](Eventevent){
    returnevent.is_character()&&!std::isdigit(event.character()[0]);
    });
    input_phone_number|=CatchEvent([&](Eventevent){
    returnevent.is_character()&&phoneNumber.size()>10;
    });

    //Thecomponenttree:
    autocomponent=Container::Vertical({
    input_first_name,
    input_last_name,
    input_password,
    input_phone_number,
    });

    //Tweakhowthecomponenttreeisrendered:
    autorenderer=Renderer(component,[&]{
    returnvbox({
    hbox(text("Firstname:"),input_first_name->Render()),
    hbox(text("Lastname:"),input_last_name->Render()),
    hbox(text("Password:"),input_password->Render()),
    hbox(text("Phonenum:"),input_phone_number->Render()),
    separator(),
    text("Hello"+first_name+""+last_name),
    text("Yourpasswordis"+password),
    text("Yourphonenumberis"+phoneNumber),
    })|
    border;
    });

    autoscreen=ScreenInteractive::TerminalOutput();
    screen.Loop(renderer);
    }