separator.cpp
array
memory
string
utility
ftxui/dom/elements.hpp
ftxui/dom/node.hpp
ftxui/dom/requirement.hpp
ftxui/screen/box.hpp
ftxui/screen/color.hpp
ftxui/screen/pixel.hpp
ftxui/screen/screen.hpp
ftxui/dom/canvas.hpp
ftxui/dom/deprecated.hpp
ftxui/dom/direction.hpp
ftxui/dom/elements.hpp
ftxui/dom/flexbox_config.hpp
ftxui/dom/linear_gradient.hpp
ftxui/dom/node.hpp
ftxui/dom/requirement.hpp
ftxui/dom/selection.hpp
ftxui/screen/box.hpp
ftxui/screen/color.hpp
ftxui/screen/image.hpp
ftxui/screen/pixel.hpp
ftxui/screen/screen.hpp
ftxui/screen/string.hpp
ftxui/screen/terminal.hpp
ftxui/util/autoreset.hpp
ftxui/util/ref.hpp
src/ftxui/dom/separator.cpp
array
cstddef
cstdint
ftxui/dom/take_any_args.hpp
functional
memory
optional
sstream
string
unordered_map
utility
variant
vector
ftxui

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<array>//forarray,array<>::value_type
    #include<memory>//formake_shared,allocator
    #include<string>//forbasic_string,string
    #include<utility>//formove

    #include"ftxui/dom/elements.hpp"//forElement,BorderStyle,LIGHT,separator,DOUBLE,EMPTY,HEAVY,separatorCharacter,separatorDouble,separatorEmpty,separatorHSelector,separatorHeavy,separatorLight,separatorStyled,separatorVSelector
    #include"ftxui/dom/node.hpp"//forNode
    #include"ftxui/dom/requirement.hpp"//forRequirement
    #include"ftxui/screen/box.hpp"//forBox
    #include"ftxui/screen/color.hpp"//forColor
    #include"ftxui/screen/pixel.hpp"//forPixel
    #include"ftxui/screen/screen.hpp"//forPixel,Screen

    namespaceftxui{

    namespace{
    usingCharset=std::array<std::string,2>;//NOLINT
    usingCharsets=std::array<Charset,6>;//NOLINT
    //NOLINTNEXTLINE
    constCharsetscharsets={
    Charset{"│","─"},//LIGHT
    Charset{"╏","╍"},//DASHED
    Charset{"┃","━"},//HEAVY
    Charset{"║","═"},//DOUBLE
    Charset{"│","─"},//ROUNDED
    Charset{"",""},//EMPTY
    };

    classSeparator:publicNode{
    public:
    explicitSeparator(std::stringvalue):value_(std::move(value)){}

    voidComputeRequirement()override{
    requirement_.min_x=1;
    requirement_.min_y=1;
    }

    voidRender(Screen&screen)override{
    for(inty=box_.y_min;y<=box_.y_max;++y){
    for(intx=box_.x_min;x<=box_.x_max;++x){
    Pixel&pixel=screen.PixelAt(x,y);
    pixel.character=value_;
    pixel.automerge=true;
    }
    }
    }

    std::stringvalue_;
    };

    classSeparatorAuto:publicNode{
    public:
    explicitSeparatorAuto(BorderStylestyle):style_(style){}

    voidComputeRequirement()override{
    requirement_.min_x=1;
    requirement_.min_y=1;
    }

    voidRender(Screen&screen)override{
    constboolis_column=(box_.x_max==box_.x_min);
    constboolis_line=(box_.y_min==box_.y_max);

    conststd::stringc=
    charsets[style_][int(is_line&&!is_column)];//NOLINT

    for(inty=box_.y_min;y<=box_.y_max;++y){
    for(intx=box_.x_min;x<=box_.x_max;++x){
    Pixel&pixel=screen.PixelAt(x,y);
    pixel.character=c;
    pixel.automerge=true;
    }
    }
    }

    BorderStylestyle_;
    };

    classSeparatorWithPixel:publicSeparatorAuto{
    public:
    explicitSeparatorWithPixel(Pixelpixel)
    :SeparatorAuto(LIGHT),pixel_(std::move(pixel)){
    pixel_.automerge=true;
    }
    voidRender(Screen&screen)override{
    for(inty=box_.y_min;y<=box_.y_max;++y){
    for(intx=box_.x_min;x<=box_.x_max;++x){
    screen.PixelAt(x,y)=pixel_;
    }
    }
    }

    private:
    Pixelpixel_;
    };
    }//namespace

    ///@briefDrawaverticalorhorizontalseparationinbetweentwoother
    ///elements.
    ///@ingroupdom
    ///@seeseparator
    ///@seeseparatorLight
    ///@seeseparatorDashed
    ///@seeseparatorDouble
    ///@seeseparatorHeavy
    ///@seeseparatorEmpty
    ///@seeseparatorRounded
    ///@seeseparatorStyled
    ///@seeseparatorCharacter
    ///
    ///Addavisualseparationinbetweentwoelements.
    ///
    ///###Example
    ///
    ///```cpp
    /////Use'border'asafunction...
    ///Elementdocument=vbox({
    ///text("up"),
    ///separator(),
    ///text("down"),
    ///});
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///up
    ///────
    ///down
    ///```
    Elementseparator(){
    returnstd::make_shared<SeparatorAuto>(LIGHT);
    }

    ///@briefDrawaverticalorhorizontalseparationinbetweentwoother
    ///elements.
    ///@paramstylethestyleoftheseparator.
    ///@ingroupdom
    ///@seeseparator
    ///@seeseparatorLight
    ///@seeseparatorDashed
    ///@seeseparatorDouble
    ///@seeseparatorHeavy
    ///@seeseparatorEmpty
    ///@seeseparatorRounded
    ///@seeseparatorStyled
    ///@seeseparatorCharacter
    ///
    ///Addavisualseparationinbetweentwoelements.
    ///
    ///###Example
    ///
    ///```cpp
    /////Use'border'asafunction...
    ///Elementdocument=vbox({
    ///text("up"),
    ///separatorStyled(DOUBLE),
    ///text("down"),
    ///});
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///up
    ///════
    ///down
    ///```
    ElementseparatorStyled(BorderStylestyle){
    returnstd::make_shared<SeparatorAuto>(style);
    }

    ///@briefDrawaverticalorhorizontalseparationinbetweentwoother
    ///elements,usingtheLIGHTstyle.
    ///@ingroupdom
    ///@seeseparator
    ///@seeseparatorLight
    ///@seeseparatorDashed
    ///@seeseparatorDouble
    ///@seeseparatorHeavy
    ///@seeseparatorEmpty
    ///@seeseparatorRounded
    ///@seeseparatorStyled
    ///@seeseparatorCharacter
    ///
    ///Addavisualseparationinbetweentwoelements.
    ///
    ///###Example
    ///
    ///```cpp
    /////Use'border'asafunction...
    ///Elementdocument=vbox({
    ///text("up"),
    ///separatorLight(),
    ///text("down"),
    ///});
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///up
    ///────
    ///down
    ///```
    ElementseparatorLight(){
    returnstd::make_shared<SeparatorAuto>(LIGHT);
    }

    ///@briefDrawaverticalorhorizontalseparationinbetweentwoother
    ///elements,usingtheDASHEDstyle.
    ///@ingroupdom
    ///@seeseparator
    ///@seeseparatorLight
    ///@seeseparatorDashed
    ///@seeseparatorDouble
    ///@seeseparatorHeavy
    ///@seeseparatorEmpty
    ///@seeseparatorRounded
    ///@seeseparatorStyled
    ///@seeseparatorCharacter
    ///
    ///Addavisualseparationinbetweentwoelements.
    ///
    ///###Example
    ///
    ///```cpp
    /////Use'border'asafunction...
    ///Elementdocument=vbox({
    ///text("up"),
    ///separatorLight(),
    ///text("down"),
    ///});
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///up
    ///╍╍╍╍
    ///down
    ///```
    ElementseparatorDashed(){
    returnstd::make_shared<SeparatorAuto>(DASHED);
    }

    ///@briefDrawaverticalorhorizontalseparationinbetweentwoother
    ///elements,usingtheHEAVYstyle.
    ///@ingroupdom
    ///@seeseparator
    ///@seeseparatorLight
    ///@seeseparatorDashed
    ///@seeseparatorDouble
    ///@seeseparatorHeavy
    ///@seeseparatorEmpty
    ///@seeseparatorRounded
    ///@seeseparatorStyled
    ///@seeseparatorCharacter
    ///
    ///Addavisualseparationinbetweentwoelements.
    ///
    ///###Example
    ///
    ///```cpp
    /////Use'border'asafunction...
    ///Elementdocument=vbox({
    ///text("up"),
    ///separatorHeavy(),
    ///text("down"),
    ///});
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///up
    ///━━━━
    ///down
    ///```
    ElementseparatorHeavy(){
    returnstd::make_shared<SeparatorAuto>(HEAVY);
    }

    ///@briefDrawaverticalorhorizontalseparationinbetweentwoother
    ///elements,usingtheDOUBLEstyle.
    ///@ingroupdom
    ///@seeseparator
    ///@seeseparatorLight
    ///@seeseparatorDashed
    ///@seeseparatorDouble
    ///@seeseparatorHeavy
    ///@seeseparatorEmpty
    ///@seeseparatorRounded
    ///@seeseparatorStyled
    ///@seeseparatorCharacter
    ///
    ///Addavisualseparationinbetweentwoelements.
    ///
    ///###Example
    ///
    ///```cpp
    /////Use'border'asafunction...
    ///Elementdocument=vbox({
    ///text("up"),
    ///separatorDouble(),
    ///text("down"),
    ///});
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///up
    ///════
    ///down
    ///```
    ElementseparatorDouble(){
    returnstd::make_shared<SeparatorAuto>(DOUBLE);
    }

    ///@briefDrawaverticalorhorizontalseparationinbetweentwoother
    ///elements,usingtheEMPTYstyle.
    ///@ingroupdom
    ///@seeseparator
    ///@seeseparatorLight
    ///@seeseparatorDashed
    ///@seeseparatorDouble
    ///@seeseparatorHeavy
    ///@seeseparatorEmpty
    ///@seeseparatorRounded
    ///@seeseparatorStyled
    ///@seeseparatorCharacter
    ///
    ///Addavisualseparationinbetweentwoelements.
    ///
    ///###Example
    ///
    ///```cpp
    /////Use'border'asafunction...
    ///Elementdocument=vbox({
    ///text("up"),
    ///separator(),
    ///text("down"),
    ///});
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///up
    ///
    ///down
    ///```
    ElementseparatorEmpty(){
    returnstd::make_shared<SeparatorAuto>(EMPTY);
    }

    ///@briefDrawaverticalorhorizontalseparationinbetweentwoother
    ///elements.
    ///@paramvaluethecharactertofilltheseparatorarea.
    ///@ingroupdom
    ///@seeseparator
    ///@seeseparatorLight
    ///@seeseparatorDashed
    ///@seeseparatorDouble
    ///@seeseparatorHeavy
    ///@seeseparatorEmpty
    ///@seeseparatorRounded
    ///@seeseparatorStyled
    ///@seeseparatorCharacter
    ///
    ///Addavisualseparationinbetweentwoelements.
    ///
    ///###Example
    ///
    ///```cpp
    /////Use'border'asafunction...
    ///Elementdocument=vbox({
    ///text("up"),
    ///separator(),
    ///text("down"),
    ///});
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///up
    ///────
    ///down
    ///```
    ElementseparatorCharacter(std::stringvalue){
    returnstd::make_shared<Separator>(std::move(value));
    }

    ///@briefDrawaseparatorinbetweentwoelementfilledwithagivenpixel.
    ///@ingroupdom
    ///@seeseparator
    ///@seeseparatorLight
    ///@seeseparatorDashed
    ///@seeseparatorHeavy
    ///@seeseparatorDouble
    ///@seeseparatorStyled
    ///
    ///###Example
    ///
    ///```cpp
    ///Pixelempty;
    ///Elementdocument=vbox({
    ///text("Up"),
    ///separator(empty),
    ///text("Down"),
    ///})
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///Up
    ///
    ///Down
    ///```
    Elementseparator(Pixelpixel){
    returnstd::make_shared<SeparatorWithPixel>(std::move(pixel));
    }

    ///@briefDrawanhorizontalbar,withtheareainbetweenleft/rightcolored
    ///differently.
    ///@paramlefttheleftlimitoftheactivearea.
    ///@paramrighttherightlimitoftheactivearea.
    ///@paramselected_colorthecoloroftheselectedarea.
    ///@paramunselected_colorthecoloroftheunselectedarea.
    ///
    ///###Example
    ///
    ///```cpp
    ///Elementdocument=separatorHSelector(2,5,Color::White,Color::Blue);
    ///```
    ElementseparatorHSelector(floatleft,
    floatright,
    Colorunselected_color,
    Colorselected_color){
    classImpl:publicNode{
    public:
    Impl(floatleft,floatright,Colorselected_color,Colorunselected_color)
    :left_(left),
    right_(right),
    unselected_color_(unselected_color),
    selected_color_(selected_color){}
    voidComputeRequirement()override{
    requirement_.min_x=1;
    requirement_.min_y=1;
    }

    voidRender(Screen&screen)override{
    if(box_.y_max<box_.y_min){
    return;
    }

    //Thisarethetwolocationwithanemptydemi-cell.
    intdemi_cell_left=int(left_*2.F-1.F);//NOLINT
    intdemi_cell_right=int(right_*2.F+2.F);//NOLINT

    constinty=box_.y_min;
    for(intx=box_.x_min;x<=box_.x_max;++x){
    Pixel&pixel=screen.PixelAt(x,y);

    constinta=(x-box_.x_min)*2;
    constintb=a+1;
    constboola_empty=demi_cell_left==a||demi_cell_right==a;
    constboolb_empty=demi_cell_left==b||demi_cell_right==b;

    if(!a_empty&&!b_empty){
    pixel.character="─";
    pixel.automerge=true;
    }else{
    pixel.character=a_empty?"╶":"╴";//NOLINT
    pixel.automerge=false;
    }

    if(demi_cell_left<=a&&b<=demi_cell_right){
    pixel.foreground_color=selected_color_;
    }else{
    pixel.foreground_color=unselected_color_;
    }
    }
    }

    floatleft_;
    floatright_;
    Colorunselected_color_;
    Colorselected_color_;
    };
    returnstd::make_shared<Impl>(left,right,unselected_color,selected_color);
    }

    ///@briefDrawanverticalbar,withtheareainbetweenup/downcolored
    ///differently.
    ///@paramuptheleftlimitoftheactivearea.
    ///@paramdowntherightlimitoftheactivearea.
    ///@paramselected_colorthecoloroftheselectedarea.
    ///@paramunselected_colorthecoloroftheunselectedarea.
    ///
    ///###Example
    ///
    ///```cpp
    ///Elementdocument=separatorHSelector(2,5,Color::White,Color::Blue);
    ///```
    ElementseparatorVSelector(floatup,
    floatdown,
    Colorunselected_color,
    Colorselected_color){
    classImpl:publicNode{
    public:
    Impl(floatup,floatdown,Colorunselected_color,Colorselected_color)
    :up_(up),
    down_(down),
    unselected_color_(unselected_color),
    selected_color_(selected_color){}
    voidComputeRequirement()override{
    requirement_.min_x=1;
    requirement_.min_y=1;
    }

    voidRender(Screen&screen)override{
    if(box_.x_max<box_.x_min){
    return;
    }

    //Thisarethetwolocationwithanemptydemi-cell.
    constintdemi_cell_up=int(up_*2-1);
    constintdemi_cell_down=int(down_*2+2);

    constintx=box_.x_min;
    for(inty=box_.y_min;y<=box_.y_max;++y){
    Pixel&pixel=screen.PixelAt(x,y);

    constinta=(y-box_.y_min)*2;
    constintb=a+1;
    constboola_empty=demi_cell_up==a||demi_cell_down==a;
    constboolb_empty=demi_cell_up==b||demi_cell_down==b;

    if(!a_empty&&!b_empty){
    pixel.character="│";
    pixel.automerge=true;
    }else{
    pixel.character=a_empty?"╷":"╵";//NOLINT
    pixel.automerge=false;
    }

    if(demi_cell_up<=a&&b<=demi_cell_down){
    pixel.foreground_color=selected_color_;
    }else{
    pixel.foreground_color=unselected_color_;
    }
    }
    }

    floatup_;
    floatdown_;
    Colorunselected_color_;
    Colorselected_color_;
    };
    returnstd::make_shared<Impl>(up,down,unselected_color,selected_color);
    }

    }//namespaceftxui