1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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;
}
}
|