examples/component/with_restored_io.cpp

    //Copyright2022ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<cstdlib>//forsystem,EXIT_SUCCESS
    #include<iostream>//foroperator<<,basic_ostream,basic_ostream::operator<<,cout,endl,flush,ostream,basic_ostream<>::__ostream_type,cin
    #include<memory>//forshared_ptr,__shared_ptr_access,allocator
    #include<string>//forgetline,string

    #include"ftxui/component/captured_mouse.hpp"//forftxui
    #include"ftxui/component/component.hpp"//forButton,Horizontal,Renderer
    #include"ftxui/component/component_base.hpp"//forComponentBase
    #include"ftxui/component/screen_interactive.hpp"//forScreenInteractive
    #include"ftxui/dom/elements.hpp"//foroperator|,filler,Element,borderEmpty,hbox,size,paragraph,vbox,LESS_THAN,border,center,HEIGHT,WIDTH

    intmain(){
    usingnamespaceftxui;

    autoscreen=ScreenInteractive::Fullscreen();

    //Whenpressingthisbutton,"screen.WithRestoredIO"willexecutethe
    //temporarilyuninstalltheterminalhookandexecutetheprovidedcallback
    //function.Thisallowrunningtheapplicationinanon-interactivemode.
    autobtn_run=Button("ExecutewithrestoredIO",screen.WithRestoredIO([]{
    std::cout<<"Thisisachildprogramusingstdin/stdout."<<std::endl;
    for(inti=0;i<10;++i){
    std::cout<<"Pleaseenter10strings("<<i<<"/10)"<<std::flush;
    std::stringinput;
    std::getline(std::cin,input);
    }
    }));

    autobtn_quit=Button("Quit",screen.ExitLoopClosure());

    autolayout=Container::Horizontal({
    btn_run,
    btn_quit,
    });

    autorenderer=Renderer(layout,[&]{
    autoexplanation=paragraph(
    "Afterclickingthisbutton,theScreenInteractivewillbe"
    "suspendedandaccesstostdin/stdoutwilltemporarillybe"
    "restoreforrunningafunction.");
    autoelement=vbox({
    explanation|borderEmpty,
    hbox({
    btn_run->Render(),
    filler(),
    btn_quit->Render(),
    }),
    });

    element=element|borderEmpty|border|size(WIDTH,LESS_THAN,80)|
    size(HEIGHT,LESS_THAN,20)|center;
    returnelement;
    });

    screen.Loop(renderer);
    returnEXIT_SUCCESS;
    }