selection.cpp
ftxui/dom/selection.hpp
algorithm
string
tuple
ftxui/dom/node_decorator.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
ftxui/dom/node_decorator.hpp
src/ftxui/dom/selection.cpp
algorithm
cstddef
cstdint
ftxui/dom/take_any_args.hpp
functional
memory
optional
sstream
string
tuple
unordered_map
utility
variant
vector
ftxui

    //Copyright2024ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.

    #include"ftxui/dom/selection.hpp"//forSelection
    #include<algorithm>//formax,min
    #include<string>//forstring
    #include<tuple>//forignore

    #include"ftxui/dom/node_decorator.hpp"//forNodeDecorator

    namespaceftxui{

    namespace{
    classUnselectable:publicNodeDecorator{
    public:
    usingNodeDecorator::NodeDecorator;

    voidSelect(Selection&ignored)override{
    std::ignore=ignored;
    //Overwritetheselectmethodtodonothing.
    }
    };
    }//namespace

    ///@briefCreateanemptyselection.
    Selection::Selection()=default;

    ///@briefCreateaselection.
    ///@paramstart_xThexcoordinateofthestartoftheselection.
    ///@paramstart_yTheycoordinateofthestartoftheselection.
    ///@paramend_xThexcoordinateoftheendoftheselection.
    ///@paramend_yTheycoordinateoftheendoftheselection.
    Selection::Selection(intstart_x,intstart_y,intend_x,intend_y)
    :start_x_(start_x),
    start_y_(start_y),
    end_x_(end_x),
    end_y_(end_y),
    box_{
    std::min(start_x,end_x),
    std::max(start_x,end_x),
    std::min(start_y,end_y),
    std::max(start_y,end_y),
    },
    empty_(false){}

    Selection::Selection(intstart_x,
    intstart_y,
    intend_x,
    intend_y,
    Selection*parent)
    :start_x_(start_x),
    start_y_(start_y),
    end_x_(end_x),
    end_y_(end_y),
    box_{
    std::min(start_x,end_x),
    std::max(start_x,end_x),
    std::min(start_y,end_y),
    std::max(start_y,end_y),
    },
    parent_(parent),
    empty_(false){}

    ///@briefGettheboxoftheselection.
    ///@returnTheboxoftheselection.
    constBox&Selection::GetBox()const{
    returnbox_;
    }

    ///@briefSaturatetheselectiontobeinsidethebox.
    ///Thisiscalledby`hbox`topropagatetheselectiontoitschildren.
    ///@paramboxTheboxtosaturatetheselectionin.
    ///@returnThesaturatedselection.
    SelectionSelection::SaturateHorizontal(Boxbox){
    intstart_x=start_x_;
    intstart_y=start_y_;
    intend_x=end_x_;
    intend_y=end_y_;

    constboolstart_outside=!box.Contain(start_x,start_y);
    constboolend_outside=!box.Contain(end_x,end_y);
    constboolproperly_ordered=
    start_y<end_y||(start_y==end_y&&start_x<=end_x);
    if(properly_ordered){
    if(start_outside){
    start_x=box.x_min;
    start_y=box.y_min;
    }
    if(end_outside){
    end_x=box.x_max;
    end_y=box.y_max;
    }
    }else{
    if(start_outside){
    start_x=box.x_max;
    start_y=box.y_max;
    }
    if(end_outside){
    end_x=box.x_min;
    end_y=box.y_min;
    }
    }
    return{
    start_x,start_y,end_x,end_y,parent_,
    };
    }

    ///@briefSaturatetheselectiontobeinsidethebox.
    ///Thisiscalledby`vbox`topropagatetheselectiontoitschildren.
    ///@paramboxTheboxtosaturatetheselectionin.
    ///@returnThesaturatedselection.
    SelectionSelection::SaturateVertical(Boxbox){
    intstart_x=start_x_;
    intstart_y=start_y_;
    intend_x=end_x_;
    intend_y=end_y_;

    constboolstart_outside=!box.Contain(start_x,start_y);
    constboolend_outside=!box.Contain(end_x,end_y);
    constboolproperly_ordered=
    start_y<end_y||(start_y==end_y&&start_x<=end_x);

    if(properly_ordered){
    if(start_outside){
    start_x=box.x_min;
    start_y=box.y_min;
    }
    if(end_outside){
    end_x=box.x_max;
    end_y=box.y_max;
    }
    }else{
    if(start_outside){
    start_x=box.x_max;
    start_y=box.y_max;
    }
    if(end_outside){
    end_x=box.x_min;
    end_y=box.y_min;
    }
    }
    return{start_x,start_y,end_x,end_y,parent_};
    }

    voidSelection::AddPart(conststd::string&part,inty,intleft,intright){
    if(parent_!=this){
    parent_->AddPart(part,y,left,right);
    return;
    }
    [&]{
    if(parts_.str().empty()){
    parts_<<part;
    return;
    }

    if(y_!=y){
    parts_<<'\n'<<part;
    return;
    }

    if(x_==left+1){
    parts_<<part;
    return;
    }

    parts_<<part;
    }();
    y_=y;
    x_=right;
    }

    }//namespaceftxui