text.cpp
algorithm
memory
sstream
string
utility
ftxui/dom/deprecated.hpp
ftxui/dom/elements.hpp
ftxui/dom/node.hpp
ftxui/dom/requirement.hpp
ftxui/dom/selection.hpp
ftxui/screen/box.hpp
ftxui/screen/screen.hpp
ftxui/screen/string.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/text.cpp
algorithm
cstddef
cstdint
ftxui/dom/take_any_args.hpp
functional
memory
optional
sstream
string
unordered_map
utility
variant
vector
ftxui

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<algorithm>//formin
    #include<memory>//formake_shared
    #include<sstream>
    #include<string>//forstring,wstring
    #include<utility>//formove

    #include"ftxui/dom/deprecated.hpp"//fortext,vtext
    #include"ftxui/dom/elements.hpp"//forElement,text,vtext
    #include"ftxui/dom/node.hpp"//forNode
    #include"ftxui/dom/requirement.hpp"//forRequirement
    #include"ftxui/dom/selection.hpp"//forSelection
    #include"ftxui/screen/box.hpp"//forBox
    #include"ftxui/screen/screen.hpp"//forPixel,Screen
    #include"ftxui/screen/string.hpp"//forstring_width,Utf8ToGlyphs,to_string

    namespaceftxui{

    namespace{
    usingftxui::Screen;

    classText:publicNode{
    public:
    explicitText(std::stringtext):text_(std::move(text)){}

    voidComputeRequirement()override{
    requirement_.min_x=string_width(text_);
    requirement_.min_y=1;
    has_selection=false;
    }

    voidSelect(Selection&selection)override{
    if(Box::Intersection(selection.GetBox(),box_).IsEmpty()){
    return;
    }

    constSelectionselection_saturated=selection.SaturateHorizontal(box_);

    has_selection=true;
    selection_start_=selection_saturated.GetBox().x_min;
    selection_end_=selection_saturated.GetBox().x_max;

    std::stringstreamss;
    intx=box_.x_min;
    for(constauto&cell:Utf8ToGlyphs(text_)){
    if(cell=="\n"){
    continue;
    }
    if(selection_start_<=x&&x<=selection_end_){
    ss<<cell;
    }
    x++;
    }
    selection.AddPart(ss.str(),box_.y_min,selection_start_,selection_end_);
    }

    voidRender(Screen&screen)override{
    intx=box_.x_min;
    constinty=box_.y_min;

    if(y>box_.y_max){
    return;
    }

    for(constauto&cell:Utf8ToGlyphs(text_)){
    if(x>box_.x_max){
    break;
    }
    if(cell=="\n"){
    continue;
    }
    screen.PixelAt(x,y).character=cell;

    if(has_selection){
    autoselectionTransform=screen.GetSelectionStyle();
    if((x>=selection_start_)&&(x<=selection_end_)){
    selectionTransform(screen.PixelAt(x,y));
    }
    }

    ++x;
    }
    }

    private:
    std::stringtext_;
    boolhas_selection=false;
    intselection_start_=0;
    intselection_end_=-1;
    };

    classVText:publicNode{
    public:
    explicitVText(std::stringtext)
    :text_(std::move(text)),width_{std::min(string_width(text_),1)}{}

    voidComputeRequirement()override{
    requirement_.min_x=width_;
    requirement_.min_y=string_width(text_);
    }

    voidRender(Screen&screen)override{
    constintx=box_.x_min;
    inty=box_.y_min;
    if(x+width_-1>box_.x_max){
    return;
    }
    for(constauto&it:Utf8ToGlyphs(text_)){
    if(y>box_.y_max){
    return;
    }
    screen.PixelAt(x,y).character=it;
    y+=1;
    }
    }

    private:
    std::stringtext_;
    intwidth_=1;
    };

    }//namespace

    ///@briefDisplayapieceofUTF8encodedunicodetext.
    ///@ingroupdom
    ///@seeftxui::to_wstring
    ///
    ///###Example
    ///
    ///```cpp
    ///Elementdocument=text("Helloworld!");
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///Helloworld!
    ///```
    Elementtext(std::stringtext){
    returnstd::make_shared<Text>(std::move(text));
    }

    ///@briefDisplayapieceofunicodetext.
    ///@ingroupdom
    ///@seeftxui::to_wstring
    ///
    ///###Example
    ///
    ///```cpp
    ///Elementdocument=text(L"Helloworld!");
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///Helloworld!
    ///```
    Elementtext(std::wstringtext){//NOLINT
    returnstd::make_shared<Text>(to_string(text));
    }

    ///@briefDisplayapieceofunicodetextvertically.
    ///@ingroupdom
    ///@seeftxui::to_wstring
    ///
    ///###Example
    ///
    ///```cpp
    ///Elementdocument=vtext("Helloworld!");
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///H
    ///e
    ///l
    ///l
    ///o
    ///
    ///w
    ///o
    ///r
    ///l
    ///d
    ///!
    ///```
    Elementvtext(std::stringtext){
    returnstd::make_shared<VText>(std::move(text));
    }

    ///@briefDisplayapieceunicodetextvertically.
    ///@ingroupdom
    ///@seeftxui::to_wstring
    ///
    ///###Example
    ///
    ///```cpp
    ///Elementdocument=vtext(L"Helloworld!");
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///H
    ///e
    ///l
    ///l
    ///o
    ///
    ///w
    ///o
    ///r
    ///l
    ///d
    ///!
    ///```
    Elementvtext(std::wstringtext){//NOLINT
    returnstd::make_shared<VText>(to_string(text));
    }

    }//namespaceftxui