forked from aoyiduo/woterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqvte.h
269 lines (244 loc) · 7.39 KB
/
qvte.h
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*******************************************************************************************
*
* Copyright (C) 2022 Guangzhou AoYiDuo Network Technology Co.,Ltd. All Rights Reserved.
*
* Contact: http://www.aoyiduo.com
*
* this file is used under the terms of the GPLv3[GNU GENERAL PUBLIC LICENSE v3]
* more information follow the website: https://www.gnu.org/licenses/gpl-3.0.en.html
*
*******************************************************************************************/
#ifndef QVTE_H
#define QVTE_H
#include "qvtedef.h"
class QVte
{
public:
QVte();
virtual ~QVte();
void process(const wchar_t *buf, int length);
void resize(int rows, int cols);
void reset();
unsigned int states();
protected:
// to implement
virtual void screenResize(int rows, int cols) = 0;
virtual void resetColor(int c) = 0;
virtual void defineColor(int c, const wchar_t *s) = 0;
virtual void defineCharset(int n, TermCharset cs) = 0;
virtual void selectCharset(int n) = 0;
virtual void showCursor(const TermCursor& cursor) = 0;
virtual void hideCursor(const TermCursor& cursor) = 0;
virtual void clearTabs() = 0;
virtual void setTab(int x) = 0;
virtual void resetTab(int x) = 0;
virtual int getNextTab(int x, int n) = 0;
virtual int getCharWidth(wchar_t c, const TermCursor& cursor) = 0;
virtual void putReversedQuestionMark(const TermCursor& cursor) = 0;
virtual void putChar(wchar_t c, int char_width, const TermCursor& cursor) = 0;
virtual bool requestWidth(int width) = 0;
virtual void clearRegion(int x1, int y1, int x2, int y2, const TermCursor& cursor) = 0;
virtual void insertChars(int x, int n, const TermCursor& cursor) = 0;
virtual void deleteChars(int x, int n, const TermCursor& cursor) = 0;
virtual void scrollUp(int y1, int y2, int n) = 0;
virtual void scrollDown(int y1, int y2, int n) = 0;
virtual void bell() = 0;
virtual void setLineTextSize(int y, TermTextSize t) = 0;
virtual void ttyWrite(const char *s) = 0;
virtual void setWindowTitle(const wchar_t *title) = 0;
virtual void flagLockKeyboard(bool state) = 0;
virtual void flagApplicationScreen(bool state) = 0;
virtual void flagApplicationKeypad(bool state) = 0;
virtual void flagCursorVisible(bool state) = 0;
virtual void flagSoftScroll(bool state) = 0;
virtual void flagScreenReversed(bool state) = 0;
virtual void saveCursor(const TermCursor& cursor) = 0;
virtual TermCursor restoreCursor() const = 0;
virtual void updateCursor(const TermCursor& cursor) = 0;
virtual TermCursor cursorNow() const = 0;
private:
void RIS();
void LFVT();
bool NEL();
void IND();
void RI();
void DECID();
void DECSC();
void DECRC();
void CPR();
void DECALN();
bool handleString(wchar_t c);
void handleControl(wchar_t c);
void handleEsc(wchar_t c);
void handleCsi(wchar_t c);
void handleHash(wchar_t c);
void handleCharset(wchar_t c);
void handleUtf8(wchar_t c);
void handleDefault(wchar_t c);
void parseString();
void resetEscape();
void hc();
void sc();
void setCharPre(int char_width);
void setChar(wchar_t c, int char_width);
void setCharPost(int char_width);
void moveCursor(int x, int y);
void moveCursorAbsolute(int x, int y);
void insertLines(int y, int n);
void deleteLines(int y, int n);
void trmInsertChars(int x, int n);
void trmDeleteChars(int x, int n);
void trmClearRegion(int x1, int y1, int x2, int y2);
void trmClearEntireLine();
void trmClearToEndOfLine();
void trmClearToBeginOfLine();
void trmClearToEndOfScreen();
void trmClearToBeginOfScreen();
void trmClearEntireScreen();
void trmClearHistory();
void trmScrollUp(int y, int n);
void trmScrollDown(int y, int n);
void setColor(int& n, TermColor& color);
void setAttributes();
void restoreModes();
void saveModes();
void setModes();
void resetModes();
void notifyKAM();
void notifyKPAM();
void notifyTCEM();
void notifyDECCOLM();
void notifyDECSCLM();
void notifyDECSCNM();
void notifyDECOM();
void notifySCREEN();
private:
void process(wchar_t c);
private:
struct ControlData
{
ControlData(){
reset();
}
void reset() {
for(int i = 0; i < CTRL_DATA_LEN; i++) {
argv[i] = 0;
}
argc = 1;
dec_mode = false;
}
inline int getArg(int i) {
if (i >= 0 && i < argc) {
return argv[i];
}
return 0;
}
inline bool spaceLeft(){
return argc < CTRL_DATA_LEN;
}
inline bool decMode() {
return dec_mode;
}
bool addArg(wchar_t c){
if (c == '?' && argc == 1) {
dec_mode = true;
return true;
} else if (c == ';') {
argc++;
return true;
} else if (c >= '0' && c <= '9') {
argv[argc-1] = 10*argv[argc-1] + c - '0';
return true;
}
return false;
}
static const int CTRL_DATA_LEN = 32;
int argv[CTRL_DATA_LEN];
int argc;
bool dec_mode;
};
struct StringData {
enum StringType {
ST_None = 0,
ST_Title,
ST_OSC,
ST_PM,
ST_DCS,
ST_APC
};
StringData() {
reset();
}
inline void reset() {
reset(ST_None);
}
void reset(StringType st) {
for(int i = 0; i < STRING_DATA_LEN; i++) {
str_data[i] = 0;
}
next_str_data = str_data;
string_type = st;
finished = false;
nargs = 1;
args[0] = str_data;
}
int parse(wchar_t *s, int n) {
int i = 0;
while (*s && i < n && nargs < STRING_ARG_LEN) {
if (*s == ';') {
*s = 0;
i++;
args[nargs++] = s + 1;
}
s++;
}
return i;
}
inline StringType type(){
return string_type;
}
inline bool isFinished() {
return finished;
}
inline void setFinished() {
finished = true;
}
inline wchar_t *data() {
return str_data;
}
inline wchar_t *getArg(int arg) {
if (arg >= 0 && arg < nargs) {
return args[arg];
}
return nullptr;
}
inline bool addChar(wchar_t c) {
if (next_str_data >= str_data + STRING_DATA_LEN - 2) {
return false;
}
*next_str_data++ = c;
return true;
}
static const int STRING_DATA_LEN = 256;
static const int STRING_ARG_LEN = 32;
wchar_t str_data[STRING_DATA_LEN];
wchar_t *next_str_data;
StringType string_type;
bool finished;
wchar_t *args[STRING_ARG_LEN];
int nargs;
};
private:
int rows;
int columns;
int top;
int bottom;
int defining_charset;
TermCursor cursor;
TermMode mode;
bool cursor_hidden;
unsigned int flags;
ControlData csi_data;
StringData str_data;
};
#endif // QVTE_H