#include "ui.h" #include "ui_terminal.h" #include "ui_private.h" namespace ui { #define CURYX int y, x; getyx(terminal, y, x); #define EXPARGS(len, defaultValue) while(args.size() < len) args.push_back(defaultValue); void setMode(std::shared_ptr data, int mode, bool setting) { switch(mode) { case 3: data->DECCRM = setting; //TODO: Implement break; case 4: data->DECIM = setting; break; case 20: if(setting) nl(); else nonl(); break; default: break; } } void SGR(std::vector args, WINDOW *terminal) { switch(args[0]) { case 0: wattr_on(terminal, A_NORMAL); break; case 1: wattr_on(terminal, A_BOLD); break; case 2: wattr_on(terminal, A_DIM); break; case 3: wattr_on(terminal, A_ITALIC); break; case 4: case 21: wattr_on(terminal, A_UNDERLINE); break; case 5: wattr_on(terminal, A_BLINK); break; case 7: wattr_on(terminal, A_REVERSE); break; case 10: // TODO: Investigate behavior of 10-12 wattr_off(terminal, A_ALTCHARSET); break; case 11: wattr_on(terminal, A_ALTCHARSET); break; case 12: wattr_on(terminal, A_ALTCHARSET); break; case 22: wattr_off(terminal, A_DIM); wattr_off(terminal, A_BOLD); break; case 23: wattr_off(terminal, A_ITALIC); break; case 24: wattr_off(terminal, A_UNDERLINE); break; case 25: wattr_off(terminal, A_BLINK); break; case 27: wattr_off(terminal, A_REVERSE); break; case 30: wattr_on(terminal, ); break; case : wattr_on(terminal, ); break; } } std::map)>> UI::getCommandCallbacks(WINDOW *terminal) { std::map)>> cmdMap = { {commands::NOTCOMMAND, [terminal,data=data](std::vector args) { if(data->DECIM) winsch(terminal, args[0]); else waddch(terminal, args[0]); }}, {commands::BS, [terminal](std::vector args) { wprintw(terminal, "\b"); }}, //TODO: Probably incorrect, see https://github.com/tmux/tmux/blob/master/screen-write.c#L982 {commands::HT, [terminal](std::vector args) { wprintw(terminal, "\t"); }}, {commands::LF, [terminal](std::vector args) { wprintw(terminal, "\n"); }}, {commands::CR, [terminal](std::vector args) { wprintw(terminal, "\r"); }}, {commands::RIS, [terminal](std::vector args) { wclear(terminal); wmove(terminal, 0, 0); wattr_on(terminal, A_NORMAL); }}, {commands::IND, [terminal](std::vector args) { CURYX wmove(terminal, y+1, x); }}, {commands::RI, [terminal](std::vector args) { CURYX wmove(terminal, y-1, x); }}, {commands::DECSC, [terminal,data=data](std::vector args) { getyx(terminal, data->savedYDEC, data->savedXDEC); wattr_get(terminal, &data->savedAttrs, &data->savedColor, &data->savedColorInt); }}, {commands::DECRC, [terminal,data=data](std::vector args) { wmove(terminal, data->savedYDEC, data->savedXDEC); wattr_set(terminal, data->savedAttrs, data->savedColor, &data->savedColorInt); }}, {commands::CUU, [terminal](std::vector args) { EXPARGS(1, 1) CURYX wmove(terminal, y-args[0], x); }}, {commands::CUD, [terminal](std::vector args) { EXPARGS(1, 1) CURYX wmove(terminal, y+args[0], x); }}, {commands::CUF, [terminal](std::vector args) { EXPARGS(1, 1) CURYX wmove(terminal, y, x+args[0]); }}, {commands::CUB, [terminal](std::vector args) { EXPARGS(1, 1) CURYX wmove(terminal, y, x-args[0]); }}, {commands::CNL, [terminal](std::vector args) { EXPARGS(1, 1) CURYX wmove(terminal, y+args[0], 0); }}, {commands::CPL, [terminal](std::vector args) { EXPARGS(1, 1) CURYX wmove(terminal, y-args[0], 0); }}, {commands::CHA, [terminal](std::vector args) { EXPARGS(1, 1) CURYX wmove(terminal, y, args[0]-1); (void)x; }}, {commands::CUP, [terminal](std::vector args) { EXPARGS(2, 1) wmove(terminal, args[0]-1, args[1]-1); }}, {commands::ED, [terminal](std::vector args) { EXPARGS(1, 0) CURYX if(args[0] == 0) wclrtobot(terminal); else if(args[0] == 1) { for(int i=0; i args) { EXPARGS(1, 0) CURYX if(args[0] == 0) wclrtoeol(terminal); else if(args[0] == 1) { for(int i=0; i args) { EXPARGS(1, 1) winsdelln(terminal, args[0]); }}, {commands::DL, [terminal](std::vector args) { EXPARGS(1, 1) winsdelln(terminal, -1*args[0]); }}, {commands::DCH, [terminal](std::vector args) { EXPARGS(1, 1) for(int i=0; i args) { EXPARGS(1, 1) CURYX for(int i=0; i args) { EXPARGS(1, 1) CURYX wmove(terminal, args[0]-1, x); (void)y; }}, {commands::VPR, [terminal](std::vector args) { EXPARGS(1, 1) CURYX wmove(terminal, y+args[0], x); }}, {commands::SCP, [terminal,data=data](std::vector args) { getyx(terminal, data->savedYCP, data->savedXCP); }}, {commands::RCP, [terminal,data=data](std::vector args) { wmove(terminal, data->savedYCP, data->savedXCP); }}, {commands::SM, [data=data](std::vector args) { EXPARGS(1, 0) setMode(data, args[0], true); }}, {commands::RM, [data=data](std::vector args) { EXPARGS(1, 0) setMode(data, args[0], false); }}, {commands::SGR, [terminal](std::vector args) { EXPARGS(1, 0) SGR(args, terminal); }}, }; cmdMap.insert({commands::VT, cmdMap[commands::LF]}); cmdMap.insert({commands::FF, cmdMap[commands::LF]}); cmdMap.insert({commands::NEL, cmdMap[commands::LF]}); cmdMap.insert({commands::HPR, cmdMap[commands::CUF]}); cmdMap.insert({commands::HVP, cmdMap[commands::CUP]}); cmdMap.insert({commands::HPA, cmdMap[commands::CHA]}); return cmdMap; } }