event.cpp
map
string
utility
ftxui/component/event.hpp
ftxui/component/mouse.hpp
ftxui/screen/string.hpp
ftxui/component/event.hpp
ftxui/component/mouse.hpp
ftxui/screen/string.hpp
src/ftxui/component/event.cpp
map
string
utility
vector
ftxui

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<map>//formap
    #include<string>
    #include<utility>//formove

    #include"ftxui/component/event.hpp"
    #include"ftxui/component/mouse.hpp"//forMouse
    #include"ftxui/screen/string.hpp"//forto_wstring

    //Disablewarningforshadowingvariable,foreverycompilers.Indeed,thereis
    //astaticEventforeveryletterofthealphabet:
    #ifdef__clang__
    #pragmaclangdiagnosticignored"-Wshadow"
    #elif__GNUC__
    #pragmaGCCdiagnosticignored"-Wshadow"
    #elifdefined(_MSC_VER)
    #pragmawarning(disable:6244)
    #pragmawarning(disable:6246)
    #endif

    namespaceftxui{

    ///@briefAneventcorrespondingtoagiventypedcharacter.
    ///@paraminputThecharactertypedbytheuser.
    ///@ingroupcomponent
    //static
    EventEvent::Character(std::stringinput){
    Eventevent;
    event.input_=std::move(input);
    event.type_=Type::Character;
    returnevent;
    }

    ///@briefAneventcorrespondingtoagiventypedcharacter.
    ///@paramcThecharactertypedbytheuser.
    ///@ingroupcomponent
    //static
    EventEvent::Character(charc){
    returnEvent::Character(std::string{c});
    }

    ///@briefAneventcorrespondingtoagiventypedcharacter.
    ///@paramcThecharactertypedbytheuser.
    ///@ingroupcomponent
    //static
    EventEvent::Character(wchar_tc){
    returnEvent::Character(to_string(std::wstring{c}));
    }

    ///@briefAneventcorrespondingtoagiventypedcharacter.
    ///@paraminputThesequenceofcharactersendbytheterminal.
    ///@parammouseThemousestate.
    ///@ingroupcomponent
    //static
    EventEvent::Mouse(std::stringinput,structMousemouse){
    Eventevent;
    event.input_=std::move(input);
    event.type_=Type::Mouse;
    event.data_.mouse=mouse;//NOLINT
    returnevent;
    }

    ///@briefAneventcorrespondingtoaterminalDCS(DeviceControlString).
    //static
    EventEvent::CursorShape(std::stringinput,intshape){
    Eventevent;
    event.input_=std::move(input);
    event.type_=Type::CursorShape;
    event.data_.cursor_shape=shape;//NOLINT
    returnevent;
    }

    ///@briefAncustomeventwhosemeaningisdefinedbytheuserofthelibrary.
    ///@paraminputAnarbitrarysequenceofcharacterdefinedbythedeveloper.
    ///@ingroupcomponent.
    //static
    EventEvent::Special(std::stringinput){
    Eventevent;
    event.input_=std::move(input);
    returnevent;
    }

    ///@internal
    //static
    EventEvent::CursorPosition(std::stringinput,intx,inty){
    Eventevent;
    event.input_=std::move(input);
    event.type_=Type::CursorPosition;
    event.data_.cursor={x,y};//NOLINT
    returnevent;
    }

    ///@briefReturnastringrepresentationoftheevent.
    std::stringEvent::DebugString()const{
    staticstd::map<Event,constchar*>event_to_string={
    //---Arrow---
    {Event::ArrowLeft,"Event::ArrowLeft"},
    {Event::ArrowRight,"Event::ArrowRight"},
    {Event::ArrowUp,"Event::ArrowUp"},
    {Event::ArrowDown,"Event::ArrowDown"},

    //---ArrowCtrl---
    {Event::ArrowLeftCtrl,"Event::ArrowLeftCtrl"},
    {Event::ArrowRightCtrl,"Event::ArrowRightCtrl"},
    {Event::ArrowUpCtrl,"Event::ArrowUpCtrl"},
    {Event::ArrowDownCtrl,"Event::ArrowDownCtrl"},

    //---Other---
    {Event::Backspace,"Event::Backspace"},
    {Event::Delete,"Event::Delete"},
    {Event::Escape,"Event::Escape"},
    {Event::Return,"Event::Return"},
    {Event::Tab,"Event::Tab"},
    {Event::TabReverse,"Event::TabReverse"},

    //---Functionkeys---
    {Event::F1,"Event::F1"},
    {Event::F2,"Event::F2"},
    {Event::F3,"Event::F3"},
    {Event::F4,"Event::F4"},
    {Event::F5,"Event::F5"},
    {Event::F6,"Event::F6"},
    {Event::F7,"Event::F7"},
    {Event::F8,"Event::F8"},
    {Event::F9,"Event::F9"},
    {Event::F10,"Event::F10"},
    {Event::F11,"Event::F11"},
    {Event::F12,"Event::F12"},

    //---Navigationkeys---
    {Event::Insert,"Event::Insert"},
    {Event::Home,"Event::Home"},
    {Event::End,"Event::End"},
    {Event::PageUp,"Event::PageUp"},
    {Event::PageDown,"Event::PageDown"},

    //---Controlkeys---
    {Event::CtrlA,"Event::CtrlA"},
    {Event::CtrlB,"Event::CtrlB"},
    {Event::CtrlC,"Event::CtrlC"},
    {Event::CtrlD,"Event::CtrlD"},
    {Event::CtrlE,"Event::CtrlE"},
    {Event::CtrlF,"Event::CtrlF"},
    {Event::CtrlG,"Event::CtrlG"},
    {Event::CtrlH,"Event::CtrlH"},
    {Event::CtrlI,"Event::CtrlI"},
    {Event::CtrlJ,"Event::CtrlJ"},
    {Event::CtrlK,"Event::CtrlK"},
    {Event::CtrlL,"Event::CtrlL"},
    {Event::CtrlM,"Event::CtrlM"},
    {Event::CtrlN,"Event::CtrlN"},
    {Event::CtrlO,"Event::CtrlO"},
    {Event::CtrlP,"Event::CtrlP"},
    {Event::CtrlQ,"Event::CtrlQ"},
    {Event::CtrlR,"Event::CtrlR"},
    {Event::CtrlS,"Event::CtrlS"},
    {Event::CtrlT,"Event::CtrlT"},
    {Event::CtrlU,"Event::CtrlU"},
    {Event::CtrlV,"Event::CtrlV"},
    {Event::CtrlW,"Event::CtrlW"},
    {Event::CtrlX,"Event::CtrlX"},
    {Event::CtrlY,"Event::CtrlY"},
    {Event::CtrlZ,"Event::CtrlZ"},

    //---Altkeys---
    {Event::AltA,"Event::AltA"},
    {Event::AltB,"Event::AltB"},
    {Event::AltC,"Event::AltC"},
    {Event::AltD,"Event::AltD"},
    {Event::AltE,"Event::AltE"},
    {Event::AltF,"Event::AltF"},
    {Event::AltG,"Event::AltG"},
    {Event::AltH,"Event::AltH"},
    {Event::AltI,"Event::AltI"},
    {Event::AltJ,"Event::AltJ"},
    {Event::AltK,"Event::AltK"},
    {Event::AltL,"Event::AltL"},
    {Event::AltM,"Event::AltM"},
    {Event::AltN,"Event::AltN"},
    {Event::AltO,"Event::AltO"},
    {Event::AltP,"Event::AltP"},
    {Event::AltQ,"Event::AltQ"},
    {Event::AltR,"Event::AltR"},
    {Event::AltS,"Event::AltS"},
    {Event::AltT,"Event::AltT"},
    {Event::AltU,"Event::AltU"},
    {Event::AltV,"Event::AltV"},
    {Event::AltW,"Event::AltW"},
    {Event::AltX,"Event::AltX"},
    {Event::AltY,"Event::AltY"},
    {Event::AltZ,"Event::AltZ"},

    //---CtrlAltkeys---
    {Event::CtrlAltA,"Event::CtrlAltA"},
    {Event::CtrlAltB,"Event::CtrlAltB"},
    {Event::CtrlAltC,"Event::CtrlAltC"},
    {Event::CtrlAltD,"Event::CtrlAltD"},
    {Event::CtrlAltE,"Event::CtrlAltE"},
    {Event::CtrlAltF,"Event::CtrlAltF"},
    {Event::CtrlAltG,"Event::CtrlAltG"},
    {Event::CtrlAltH,"Event::CtrlAltH"},
    {Event::CtrlAltI,"Event::CtrlAltI"},
    {Event::CtrlAltJ,"Event::CtrlAltJ"},
    {Event::CtrlAltK,"Event::CtrlAltK"},
    {Event::CtrlAltL,"Event::CtrlAltL"},
    {Event::CtrlAltM,"Event::CtrlAltM"},
    {Event::CtrlAltN,"Event::CtrlAltN"},
    {Event::CtrlAltO,"Event::CtrlAltO"},
    {Event::CtrlAltP,"Event::CtrlAltP"},
    {Event::CtrlAltQ,"Event::CtrlAltQ"},
    {Event::CtrlAltR,"Event::CtrlAltR"},
    {Event::CtrlAltS,"Event::CtrlAltS"},
    {Event::CtrlAltT,"Event::CtrlAltT"},
    {Event::CtrlAltU,"Event::CtrlAltU"},
    {Event::CtrlAltV,"Event::CtrlAltV"},
    {Event::CtrlAltW,"Event::CtrlAltW"},
    {Event::CtrlAltX,"Event::CtrlAltX"},
    {Event::CtrlAltY,"Event::CtrlAltY"},
    {Event::CtrlAltZ,"Event::CtrlAltZ"},

    //---Custom---
    {Event::Custom,"Event::Custom"},
    };

    staticstd::map<Mouse::Button,constchar*>mouse_button_string={
    {Mouse::Button::Left,".button=Mouse::Left"},
    {Mouse::Button::Middle,".button=Mouse::Middle"},
    {Mouse::Button::Right,".button=Mouse::Right"},
    {Mouse::Button::WheelUp,".button=Mouse::WheelUp"},
    {Mouse::Button::WheelDown,".button=Mouse::WheelDown"},
    {Mouse::Button::None,".button=Mouse::None"},
    {Mouse::Button::WheelLeft,".button=Mouse::WheelLeft"},
    {Mouse::Button::WheelRight,".button=Mouse::WheelRight"},
    };

    staticstd::map<Mouse::Motion,constchar*>mouse_motion_string={
    {Mouse::Motion::Pressed,".motion=Mouse::Pressed"},
    {Mouse::Motion::Released,".motion=Mouse::Released"},
    {Mouse::Motion::Moved,".motion=Mouse::Moved"},
    };

    switch(type_){
    caseType::Character:{
    return"Event::Character(\""+input_+"\")";
    }
    caseType::Mouse:{
    std::stringout="Event::Mouse(\"...\",Mouse{";
    out+=std::string(mouse_button_string[data_.mouse.button]);
    out+=",";
    out+=std::string(mouse_motion_string[data_.mouse.motion]);
    out+=",";
    if(data_.mouse.shift){
    out+=".shift=true,";
    }
    if(data_.mouse.meta){
    out+=".meta=true,";
    }
    if(data_.mouse.control){
    out+=".control=true,";
    }
    out+=".x="+std::to_string(data_.mouse.x);
    out+=",";
    out+=".y="+std::to_string(data_.mouse.y);
    out+="})";
    returnout;
    }
    caseType::CursorShape:
    return"Event::CursorShape("+input_+","+
    std::to_string(data_.cursor_shape)+")";
    caseType::CursorPosition:
    return"Event::CursorPosition("+input_+","+
    std::to_string(data_.cursor.x)+","+
    std::to_string(data_.cursor.y)+")";
    default:{
    autoevent_it=event_to_string.find(*this);
    if(event_it!=event_to_string.end()){
    returnevent_it->second;
    }

    return"";
    }
    }
    return"";
    }

    //clang-formatoff
    //NOLINTBEGIN

    //---Arrow---
    constEventEvent::ArrowLeft=Event::Special("\x1B[D");
    constEventEvent::ArrowRight=Event::Special("\x1B[C");
    constEventEvent::ArrowUp=Event::Special("\x1B[A");
    constEventEvent::ArrowDown=Event::Special("\x1B[B");
    constEventEvent::ArrowLeftCtrl=Event::Special("\x1B[1;5D");
    constEventEvent::ArrowRightCtrl=Event::Special("\x1B[1;5C");
    constEventEvent::ArrowUpCtrl=Event::Special("\x1B[1;5A");
    constEventEvent::ArrowDownCtrl=Event::Special("\x1B[1;5B");
    constEventEvent::Backspace=Event::Special({127});
    constEventEvent::Delete=Event::Special("\x1B[3~");
    constEventEvent::Escape=Event::Special("\x1B");
    constEventEvent::Return=Event::Special({10});
    constEventEvent::Tab=Event::Special({9});
    constEventEvent::TabReverse=Event::Special({27,91,90});

    //Seehttps://invisible-island.net/xterm/xterm-function-keys.html
    //Wefollowxterm-new/vterm-xf86-v4/mgt/screen
    constEventEvent::F1=Event::Special("\x1BOP");
    constEventEvent::F2=Event::Special("\x1BOQ");
    constEventEvent::F3=Event::Special("\x1BOR");
    constEventEvent::F4=Event::Special("\x1BOS");
    constEventEvent::F5=Event::Special("\x1B[15~");
    constEventEvent::F6=Event::Special("\x1B[17~");
    constEventEvent::F7=Event::Special("\x1B[18~");
    constEventEvent::F8=Event::Special("\x1B[19~");
    constEventEvent::F9=Event::Special("\x1B[20~");
    constEventEvent::F10=Event::Special("\x1B[21~");
    constEventEvent::F11=Event::Special("\x1B[23~");
    constEventEvent::F12=Event::Special("\x1B[24~");

    constEventEvent::Insert=Event::Special("\x1B[2~");
    constEventEvent::Home=Event::Special({27,91,72});
    constEventEvent::End=Event::Special({27,91,70});
    constEventEvent::PageUp=Event::Special({27,91,53,126});
    constEventEvent::PageDown=Event::Special({27,91,54,126});
    constEventEvent::Custom=Event::Special({0});

    constEventEvent::a=Event::Character("a");
    constEventEvent::b=Event::Character("b");
    constEventEvent::c=Event::Character("c");
    constEventEvent::d=Event::Character("d");
    constEventEvent::e=Event::Character("e");
    constEventEvent::f=Event::Character("f");
    constEventEvent::g=Event::Character("g");
    constEventEvent::h=Event::Character("h");
    constEventEvent::i=Event::Character("i");
    constEventEvent::j=Event::Character("j");
    constEventEvent::k=Event::Character("k");
    constEventEvent::l=Event::Character("l");
    constEventEvent::m=Event::Character("m");
    constEventEvent::n=Event::Character("n");
    constEventEvent::o=Event::Character("o");
    constEventEvent::p=Event::Character("p");
    constEventEvent::q=Event::Character("q");
    constEventEvent::r=Event::Character("r");
    constEventEvent::s=Event::Character("s");
    constEventEvent::t=Event::Character("t");
    constEventEvent::u=Event::Character("u");
    constEventEvent::v=Event::Character("v");
    constEventEvent::w=Event::Character("w");
    constEventEvent::x=Event::Character("x");
    constEventEvent::y=Event::Character("y");
    constEventEvent::z=Event::Character("z");

    constEventEvent::A=Event::Character("A");
    constEventEvent::B=Event::Character("B");
    constEventEvent::C=Event::Character("C");
    constEventEvent::D=Event::Character("D");
    constEventEvent::E=Event::Character("E");
    constEventEvent::F=Event::Character("F");
    constEventEvent::G=Event::Character("G");
    constEventEvent::H=Event::Character("H");
    constEventEvent::I=Event::Character("I");
    constEventEvent::J=Event::Character("J");
    constEventEvent::K=Event::Character("K");
    constEventEvent::L=Event::Character("L");
    constEventEvent::M=Event::Character("M");
    constEventEvent::N=Event::Character("N");
    constEventEvent::O=Event::Character("O");
    constEventEvent::P=Event::Character("P");
    constEventEvent::Q=Event::Character("Q");
    constEventEvent::R=Event::Character("R");
    constEventEvent::S=Event::Character("S");
    constEventEvent::T=Event::Character("T");
    constEventEvent::U=Event::Character("U");
    constEventEvent::V=Event::Character("V");
    constEventEvent::W=Event::Character("W");
    constEventEvent::X=Event::Character("X");
    constEventEvent::Y=Event::Character("Y");
    constEventEvent::Z=Event::Character("Z");

    constEventEvent::CtrlA=Event::Special("\x01");
    constEventEvent::CtrlB=Event::Special("\x02");
    constEventEvent::CtrlC=Event::Special("\x03");
    constEventEvent::CtrlD=Event::Special("\x04");
    constEventEvent::CtrlE=Event::Special("\x05");
    constEventEvent::CtrlF=Event::Special("\x06");
    constEventEvent::CtrlG=Event::Special("\x07");
    constEventEvent::CtrlH=Event::Special("\x08");
    constEventEvent::CtrlI=Event::Special("\x09");
    constEventEvent::CtrlJ=Event::Special("\x0a");
    constEventEvent::CtrlK=Event::Special("\x0b");
    constEventEvent::CtrlL=Event::Special("\x0c");
    constEventEvent::CtrlM=Event::Special("\x0d");
    constEventEvent::CtrlN=Event::Special("\x0e");
    constEventEvent::CtrlO=Event::Special("\x0f");
    constEventEvent::CtrlP=Event::Special("\x10");
    constEventEvent::CtrlQ=Event::Special("\x11");
    constEventEvent::CtrlR=Event::Special("\x12");
    constEventEvent::CtrlS=Event::Special("\x13");
    constEventEvent::CtrlT=Event::Special("\x14");
    constEventEvent::CtrlU=Event::Special("\x15");
    constEventEvent::CtrlV=Event::Special("\x16");
    constEventEvent::CtrlW=Event::Special("\x17");
    constEventEvent::CtrlX=Event::Special("\x18");
    constEventEvent::CtrlY=Event::Special("\x19");
    constEventEvent::CtrlZ=Event::Special("\x1a");

    constEventEvent::AltA=Event::Special("\x1b""a");
    constEventEvent::AltB=Event::Special("\x1b""b");
    constEventEvent::AltC=Event::Special("\x1b""c");
    constEventEvent::AltD=Event::Special("\x1b""d");
    constEventEvent::AltE=Event::Special("\x1b""e");
    constEventEvent::AltF=Event::Special("\x1b""f");
    constEventEvent::AltG=Event::Special("\x1b""g");
    constEventEvent::AltH=Event::Special("\x1b""h");
    constEventEvent::AltI=Event::Special("\x1b""i");
    constEventEvent::AltJ=Event::Special("\x1b""j");
    constEventEvent::AltK=Event::Special("\x1b""k");
    constEventEvent::AltL=Event::Special("\x1b""l");
    constEventEvent::AltM=Event::Special("\x1b""m");
    constEventEvent::AltN=Event::Special("\x1b""n");
    constEventEvent::AltO=Event::Special("\x1b""o");
    constEventEvent::AltP=Event::Special("\x1b""p");
    constEventEvent::AltQ=Event::Special("\x1b""q");
    constEventEvent::AltR=Event::Special("\x1b""r");
    constEventEvent::AltS=Event::Special("\x1b""s");
    constEventEvent::AltT=Event::Special("\x1b""t");
    constEventEvent::AltU=Event::Special("\x1b""u");
    constEventEvent::AltV=Event::Special("\x1b""v");
    constEventEvent::AltW=Event::Special("\x1b""w");
    constEventEvent::AltX=Event::Special("\x1b""x");
    constEventEvent::AltY=Event::Special("\x1b""y");
    constEventEvent::AltZ=Event::Special("\x1b""z");

    constEventEvent::CtrlAltA=Event::Special("\x1b\x01");
    constEventEvent::CtrlAltB=Event::Special("\x1b\x02");
    constEventEvent::CtrlAltC=Event::Special("\x1b\x03");
    constEventEvent::CtrlAltD=Event::Special("\x1b\x04");
    constEventEvent::CtrlAltE=Event::Special("\x1b\x05");
    constEventEvent::CtrlAltF=Event::Special("\x1b\x06");
    constEventEvent::CtrlAltG=Event::Special("\x1b\x07");
    constEventEvent::CtrlAltH=Event::Special("\x1b\x08");
    constEventEvent::CtrlAltI=Event::Special("\x1b\x09");
    constEventEvent::CtrlAltJ=Event::Special("\x1b\x0a");
    constEventEvent::CtrlAltK=Event::Special("\x1b\x0b");
    constEventEvent::CtrlAltL=Event::Special("\x1b\x0c");
    constEventEvent::CtrlAltM=Event::Special("\x1b\x0d");
    constEventEvent::CtrlAltN=Event::Special("\x1b\x0e");
    constEventEvent::CtrlAltO=Event::Special("\x1b\x0f");
    constEventEvent::CtrlAltP=Event::Special("\x1b\x10");
    constEventEvent::CtrlAltQ=Event::Special("\x1b\x11");
    constEventEvent::CtrlAltR=Event::Special("\x1b\x12");
    constEventEvent::CtrlAltS=Event::Special("\x1b\x13");
    constEventEvent::CtrlAltT=Event::Special("\x1b\x14");
    constEventEvent::CtrlAltU=Event::Special("\x1b\x15");
    constEventEvent::CtrlAltV=Event::Special("\x1b\x16");
    constEventEvent::CtrlAltW=Event::Special("\x1b\x17");
    constEventEvent::CtrlAltX=Event::Special("\x1b\x18");
    constEventEvent::CtrlAltY=Event::Special("\x1b\x19");
    constEventEvent::CtrlAltZ=Event::Special("\x1b\x1a");

    //NOLINTEND
    //clang-formaton

    }//namespaceftxui