summaryrefslogtreecommitdiff
path: root/src/ui_terminal_callbacks.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui_terminal_callbacks.cc')
-rw-r--r--src/ui_terminal_callbacks.cc129
1 files changed, 129 insertions, 0 deletions
diff --git a/src/ui_terminal_callbacks.cc b/src/ui_terminal_callbacks.cc
new file mode 100644
index 0000000..a742e27
--- /dev/null
+++ b/src/ui_terminal_callbacks.cc
@@ -0,0 +1,129 @@
+#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<uiImpl> 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<int> 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<commands, std::function<void(std::vector<int>)>> UI::getCommandCallbacks(WINDOW *terminal) {
+ std::map<commands, std::function<void(std::vector<int>)>> cmdMap = {
+ {commands::NOTCOMMAND, [terminal,data=data](std::vector<int> args) { if(data->DECIM) winsch(terminal, args[0]); else waddch(terminal, args[0]); }},
+ {commands::BS, [terminal](std::vector<int> args) { wprintw(terminal, "\b"); }}, //TODO: Probably incorrect, see https://github.com/tmux/tmux/blob/master/screen-write.c#L982
+ {commands::HT, [terminal](std::vector<int> args) { wprintw(terminal, "\t"); }},
+ {commands::LF, [terminal](std::vector<int> args) { wprintw(terminal, "\n"); }},
+ {commands::CR, [terminal](std::vector<int> args) { wprintw(terminal, "\r"); }},
+ {commands::RIS, [terminal](std::vector<int> args) { wclear(terminal); wmove(terminal, 0, 0); wattr_on(terminal, A_NORMAL); }},
+ {commands::IND, [terminal](std::vector<int> args) { CURYX wmove(terminal, y+1, x); }},
+ {commands::RI, [terminal](std::vector<int> args) { CURYX wmove(terminal, y-1, x); }},
+ {commands::DECSC, [terminal,data=data](std::vector<int> args) { getyx(terminal, data->savedYDEC, data->savedXDEC); wattr_get(terminal, &data->savedAttrs, &data->savedColor, &data->savedColorInt); }},
+ {commands::DECRC, [terminal,data=data](std::vector<int> args) { wmove(terminal, data->savedYDEC, data->savedXDEC); wattr_set(terminal, data->savedAttrs, data->savedColor, &data->savedColorInt); }},
+ {commands::CUU, [terminal](std::vector<int> args) { EXPARGS(1, 1) CURYX wmove(terminal, y-args[0], x); }},
+ {commands::CUD, [terminal](std::vector<int> args) { EXPARGS(1, 1) CURYX wmove(terminal, y+args[0], x); }},
+ {commands::CUF, [terminal](std::vector<int> args) { EXPARGS(1, 1) CURYX wmove(terminal, y, x+args[0]); }},
+ {commands::CUB, [terminal](std::vector<int> args) { EXPARGS(1, 1) CURYX wmove(terminal, y, x-args[0]); }},
+ {commands::CNL, [terminal](std::vector<int> args) { EXPARGS(1, 1) CURYX wmove(terminal, y+args[0], 0); }},
+ {commands::CPL, [terminal](std::vector<int> args) { EXPARGS(1, 1) CURYX wmove(terminal, y-args[0], 0); }},
+ {commands::CHA, [terminal](std::vector<int> args) { EXPARGS(1, 1) CURYX wmove(terminal, y, args[0]-1); (void)x; }},
+ {commands::CUP, [terminal](std::vector<int> args) { EXPARGS(2, 1) wmove(terminal, args[0]-1, args[1]-1); }},
+ {commands::ED, [terminal](std::vector<int> args) { EXPARGS(1, 0) CURYX if(args[0] == 0) wclrtobot(terminal); else if(args[0] == 1) { for(int i=0; i<x; i++) mvwaddch(terminal, y, i, ' '); for(int i=0; i<y; i++) {wmove(terminal, i, 0); wclrtoeol(terminal);} wmove(terminal, y, x); } else if(args[0] == 2 or args[0] == 3) wclear(terminal); }},
+ {commands::EL, [terminal](std::vector<int> args) { EXPARGS(1, 0) CURYX if(args[0] == 0) wclrtoeol(terminal); else if(args[0] == 1) { for(int i=0; i<x; i++) mvwaddch(terminal, y, i, ' '); wmove(terminal, y, x); } else if(args[0] == 2) { wmove(terminal, y, 0); wclrtoeol(terminal); wmove(terminal, y, x); } }},
+ {commands::IL, [terminal](std::vector<int> args) { EXPARGS(1, 1) winsdelln(terminal, args[0]); }},
+ {commands::DL, [terminal](std::vector<int> args) { EXPARGS(1, 1) winsdelln(terminal, -1*args[0]); }},
+ {commands::DCH, [terminal](std::vector<int> args) { EXPARGS(1, 1) for(int i=0; i<args[0]; i++) wdelch(terminal); }},
+ {commands::ECH, [terminal](std::vector<int> args) { EXPARGS(1, 1) CURYX for(int i=0; i<args[0]; i++) waddch(terminal, ' '); wmove(terminal, y, x); }},
+ {commands::VPA, [terminal](std::vector<int> args) { EXPARGS(1, 1) CURYX wmove(terminal, args[0]-1, x); (void)y; }},
+ {commands::VPR, [terminal](std::vector<int> args) { EXPARGS(1, 1) CURYX wmove(terminal, y+args[0], x); }},
+ {commands::SCP, [terminal,data=data](std::vector<int> args) { getyx(terminal, data->savedYCP, data->savedXCP); }},
+ {commands::RCP, [terminal,data=data](std::vector<int> args) { wmove(terminal, data->savedYCP, data->savedXCP); }},
+ {commands::SM, [data=data](std::vector<int> args) { EXPARGS(1, 0) setMode(data, args[0], true); }},
+ {commands::RM, [data=data](std::vector<int> args) { EXPARGS(1, 0) setMode(data, args[0], false); }},
+ {commands::SGR, [terminal](std::vector<int> 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;
+ }
+}