examples/component/selection.cpp

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

    #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

    usingnamespaceftxui;

    ElementLoremIpsum(){
    returnvbox({
    text("FTXUI:Apowerfullibraryforbuildinguserinterfaces."),
    text("Enjoyarichsetofcomponentsandadeclarativestyle."),
    text("CreatebeautifulandresponsiveUIswithminimaleffort."),
    text("JointhecommunityandexperiencethepowerofFTXUI."),
    });
    }

    intmain(){
    autoscreen=ScreenInteractive::TerminalOutput();

    autoquit=
    Button("Quit",screen.ExitLoopClosure(),ButtonOption::Animated());

    intselection_change_counter=0;
    std::stringselection_content="";
    screen.SelectionChange([&]{
    selection_change_counter++;
    selection_content=screen.GetSelection();
    });

    //Thecomponents:
    autorenderer=Renderer(quit,[&]{
    returnvbox({
    text("Selectchanged:"+std::to_string(selection_change_counter)+
    "times"),
    text("Currentlyselected:"),
    paragraph(selection_content)|vscroll_indicator|frame|border|
    size(HEIGHT,EQUAL,10),
    window(text("Horizontalsplit"),hbox({
    LoremIpsum(),
    separator(),
    LoremIpsum(),
    separator(),
    LoremIpsum(),
    })),
    window(text("Verticalsplit"),vbox({
    LoremIpsum(),
    separator(),
    LoremIpsum(),
    separator(),
    LoremIpsum(),
    })),
    window(text("Gridsplitwithdifferentstyle"),
    vbox({
    hbox({
    LoremIpsum(),
    separator(),
    LoremIpsum()//
    |selectionBackgroundColor(Color::Yellow)//
    |selectionColor(Color::Black)//
    |selectionStyleReset,
    separator(),
    LoremIpsum()|selectionColor(Color::Blue),
    }),
    separator(),
    hbox({
    LoremIpsum()|selectionColor(Color::Red),
    separator(),
    LoremIpsum()|selectionStyle([](Pixel&pixel){
    pixel.underlined_double=true;
    }),
    separator(),
    LoremIpsum(),
    }),
    })),
    quit->Render(),
    });
    });

    screen.Loop(renderer);
    }