-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgterm.cpp
More file actions
150 lines (123 loc) · 3.11 KB
/
gterm.cpp
File metadata and controls
150 lines (123 loc) · 3.11 KB
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
// Copyright Timothy Miller, 1999
#include "gterm.hpp"
#include <cassert>
#include <cstring>
#include <iostream>
#ifndef min
#define min(x,y) ((x)<(y)?(x):(y))
#endif
#ifndef max
#define max(x,y) ((x)<(y)?(y):(x))
#endif
#define ASSERT_X(x) (assert((x) >= 0 && (x) < width))
#define ASSERT_Y(y) (assert((y) >= 0 && (y) < height))
void GTerm::Update()
{
update_changes();
}
void GTerm::ProcessInput(int len, unsigned char *data)
{
int i;
StateOption *last_state;
data_len = len;
input_data = data;
#if 0
//std::string s((const char*)data,unsigned(len));
cerr<<"len=" << len << ",data:[";
for (i=0; i<len; i++) {
if (data[i]<32 || data[i]>126) {
cout << '\\' << ((int)(data[i]&0700)>>6) <<
((int)(data[i]&070)>>3) << ((int)(data[i]&07));
} else {
cout << data[i];
}
}
cout <<"]"<<endl;
#endif
while (data_len) {
i = 0;
while (current_state[i].byte != -1 &&
current_state[i].byte != *input_data) i++;
// action must be allowed to redirect state change
last_state = current_state+i;
current_state = last_state->next_state;
if (last_state->action)
(this->*(last_state->action))();
input_data++;
data_len--;
}
if (!(mode_flags & DEFERUPDATE) ||
(pending_scroll > scroll_bot-scroll_top)) update_changes();
}
void GTerm::Reset()
{
reset();
}
void GTerm::ExposeArea(int x, int y, int w, int h)
{
ASSERT_X(x);
ASSERT_Y(y);
assert(w > 0 && h > 0);
int i;
for (i=0; i<h; i++) changed_line(i+y, x, x+w-1);
if (!(mode_flags & DEFERUPDATE)) update_changes();
}
void GTerm::ResizeTerminal(int w, int h)
{
assert(w > 0 && h > 0);
if (width == w && height == h)
return;
int cx, cy;
cx = min(w-1, cursor_x);
cy = min(h-1, cursor_y);
move_cursor(cx, cy);
delete[] dirty_endx;
delete[] dirty_startx;
delete[] linenumbers;
delete[] tab_stops;
delete[] text;
delete[] color;
width = w;
height = h;
text = new unsigned char[width * height];
color = new unsigned short[width * height];
tab_stops = new char[width];
linenumbers = new short[height];
dirty_startx = new unsigned char[height];
dirty_endx = new unsigned char[height];
save_x = 0;
save_y = 0;
scroll_top = 0;
scroll_bot = height-1;
int i;
for (i=0; i<height; i++) {
// make it draw whole terminal to start
dirty_startx[i] = 0;
dirty_endx[i] = width - 1;
}
for (i=0; i<height; i++) linenumbers[i] = i;
memset(tab_stops, 0, width);
clear_area(0, 0, width-1, height-1);
}
GTerm::GTerm(int w, int h) : width(w), height(h),mode_flags(0),cur_charset(0)
{
assert(w > 0 && h > 0);
doing_update = false;
charset[0] = charset[1] = 'B';
text = new unsigned char[width * height];
color = new unsigned short[width * height];
tab_stops = new char[width];
linenumbers = new short[height];
dirty_startx = new unsigned char[height];
dirty_endx = new unsigned char[height];
reset();
}
GTerm::~GTerm()
{
delete[] dirty_endx;
delete[] dirty_startx;
delete[] linenumbers;
delete[] tab_stops;
delete[] text;
delete[] color;
}