-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgterm.hpp
180 lines (158 loc) · 4.68 KB
/
gterm.hpp
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
// Copyright Timothy Miller, 1999
#ifndef INCLUDED_GTERM_H
#define INCLUDED_GTERM_H
#define FGCOLOR(attr) (((attr)>>4) & 7)
#define BGCOLOR(attr) (((attr)>>8) & 7)
#define FLAG(attr) ((attr) & 0x0f)
class GTerm;
typedef void (GTerm::*StateFunc)();
struct StateOption {
int byte; // char value to look for; -1==end/default
StateFunc action;
StateOption *next_state;
};
class GTerm {
public:
// mode flags
enum {BOLD=1, BLINK=2, UNDERLINE=4, INVERSE=8,
NOEOLWRAP=16, CURSORAPPMODE=32, CURSORRELATIVE=64,
NEWLINE=128, INSERT=256, KEYAPPMODE=512,
DEFERUPDATE=1024, DESTRUCTBS=2048, TEXTONLY=4096,
LOCALECHO=8192, CURSORINVISIBLE=16384} MODES;
private:
// terminal info
int width, height, scroll_top, scroll_bot;
unsigned char *text;
unsigned short *color;
char *tab_stops;
short *linenumbers; // text at text[linenumbers[y]*MAXWIDTH]
unsigned char* dirty_startx;
unsigned char* dirty_endx;
int pending_scroll; // >0 means scroll up
bool doing_update;
bool force_wrap;
bool inverse_mode;
// terminal state
int gfx_x, gfx_y;
int cursor_x, cursor_y;
int save_x, save_y, save_attrib;
int fg_color, bg_color;
int mode_flags;
char charset[2]; //G0,G1 charset
int cur_charset;
StateOption *current_state;
static StateOption normal_state[];
static StateOption esc_state[];
static StateOption bracket_state[];
static StateOption q_bracket_state[];
static StateOption cset_shiftin_state[];
static StateOption cset_shiftout_state[];
static StateOption hash_state[];
static StateOption nonstd_state[];
static StateOption vt52_normal_state[], vt52_esc_state[];
static StateOption vt52_cursory_state[], vt52_cursorx_state[];
static StateOption gfx_state[];
// utility functions
void update_changes();
void scroll_region(int start_y, int end_y, int num); // does clear
void shift_text(int y, int start_x, int end_x, int num); // ditto
void clear_area(int start_x, int start_y, int end_x, int end_y);
void changed_line(int y, int start_x, int end_x);
void move_cursor(int x, int y);
int calc_color(int fg, int bg, int flags);
void translate_charset(unsigned char *buf, unsigned char *ptr);
// action parameters
int nparam, param[30];
unsigned char *input_data;
int data_len;
int q_mode; //in question mode('?') when parsing
int got_param, quote_mode;
// terminal actions
void normal_input();
void set_q_mode();
void set_quote_mode();
void clear_param();
void param_digit();
void next_param();
// non-printing characters
void cr(), lf(), ff(), bell(), tab(), bs();
// escape sequence actions
void keypad_numeric();
void keypad_application();
void save_cursor();
void restore_cursor();
void set_tab();
void index_down();
void index_up();
void next_line();
void reset();
void cursor_left();
void cursor_down();
void cursor_right();
void cursor_up();
void cursor_position();
void device_attrib();
void delete_char();
void set_mode();
void clear_mode();
void request_param();
void set_margins();
void delete_line();
void status_report();
void erase_display();
void erase_line();
void insert_line();
void set_colors();
void clear_tab();
void insert_char();
void screen_align();
void erase_char();
void charset_g1();
void charset_g0();
void cset_g0_a();
void cset_g0_b();
void cset_g0_0();
void cset_g0_1();
void cset_g0_2();
void cset_g1_a();
void cset_g1_b();
void cset_g1_0();
void cset_g1_1();
void cset_g1_2();
void cursor_ypos();
// vt52 stuff
void vt52_cursory();
void vt52_cursorx();
void vt52_ident();
// gfx extension
void gfx_input();
public:
GTerm(int w, int h);
virtual ~GTerm();
// function to control terminal
virtual void ProcessInput(int len, unsigned char *data);
virtual void ResizeTerminal(int width, int height);
int Width() { return width; }
int Height() { return height; }
virtual void Update();
virtual void ExposeArea(int x, int y, int w, int h);
virtual void Reset();
int GetMode() { return mode_flags; }
void SetMode(int mode) { mode_flags = mode; }
void set_mode_flag(int flag);
void clear_mode_flag(int flag);
// manditory child-supplied functions
virtual void DrawText(int fg_color, int bg_color, int flags,
int x, int y, int len, unsigned char *string) = 0;
virtual void DrawCursor(int fg_color, int bg_color, int flags,
int x, int y, unsigned char c) = 0;
// optional child-supplied functions
virtual void MoveChars(int sx, int sy, int dx, int dy, int w, int h) { }
virtual void ClearChars(int bg_color, int x, int y, int w, int h) { }
virtual void SendBack(const char *data) { }
virtual void ModeChange(int state) { }
virtual void Bell() { }
virtual void RequestSizeChange(int w, int h) { }
virtual void PlotPixel(int x, int y, int c) { }
};
#endif