forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVT100Screen.h
342 lines (283 loc) · 10.2 KB
/
VT100Screen.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
// -*- mode:objc -*-
// $Id: VT100Screen.h,v 1.38 2008-09-30 06:21:12 yfabian Exp $
/*
** VT100Screen.h
**
** Copyright (c) 2002, 2003
**
** Author: Fabian, Ujwal S. Setlur
** Initial code by Kiichi Kusama
**
** Project: iTerm
**
** Description: Implements the VT100 screen.
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#import <Cocoa/Cocoa.h>
#import <iTerm/VT100Terminal.h>
#import <LineBuffer.h>
#import "DVR.h"
@class PTYTask;
@class PTYSession;
@class PTYTextView;
@class iTermGrowlDelegate;
// continueFindAllResults populates an array of search results with these
// objects.
@interface SearchResult : NSObject
{
@public
int startX, endX;
long long absStartY, absEndY;
}
@end
// For debugging: log the buffer.
void DumpBuf(screen_char_t* p, int n);
// Convert a string into screen_char_t. This deals with padding out double-
// width characters, joining combining marks, and skipping zero-width spaces.
//
// The buffer size must be at least twice the length of the string (worst case:
// every character is double-width).
// Pass prototype foreground and background colors in fg and bg.
// *len is filled in with the number of elements of *buf that were set.
// encoding is currently ignored and it's assumed to be UTF-16.
// A good choice for ambiguousIsDoubleWidth is [SESSION doubleWidth].
// If not null, *cursorIndex gives an index into s and is changed into the
// corresponding index into buf.
void StringToScreenChars(NSString *s,
screen_char_t *buf,
screen_char_t fg,
screen_char_t bg,
int *len,
NSStringEncoding encoding,
BOOL ambiguousIsDoubleWidth,
int* cursorIndex);
@interface VT100Screen : NSObject
{
int WIDTH; // width of screen
int HEIGHT; // height of screen
int cursorX;
int cursorY;
int SAVE_CURSOR_X;
int SAVE_CURSOR_Y;
int ALT_SAVE_CURSOR_X;
int ALT_SAVE_CURSOR_Y;
int SCROLL_TOP;
int SCROLL_BOTTOM;
NSMutableSet* tabStops;
VT100Terminal *TERMINAL;
PTYTask *SHELL;
PTYSession *SESSION;
int charset[4], saveCharset[4];
BOOL blinkShow;
BOOL PLAYBELL;
BOOL SHOWBELL;
BOOL FLASHBELL;
BOOL GROWL;
BOOL blinkingCursor;
PTYTextView *display;
// A circular buffer exactly (WIDTH+1) * HEIGHT elements in size. This contains
// only the contents of the screen. The scrollback buffer is stored in linebuffer.
screen_char_t *buffer_lines;
// The position in buffer_lines of the first line in the screen. The logical lines
// wrap around the circular buffer.
screen_char_t *screen_top;
// buffer holding flags for each char on whether it needs to be redrawn
char *dirty;
// Number of bytes in the dirty array.
int dirtySize;
// a single default line
screen_char_t *default_line;
screen_char_t *result_line;
// temporary buffer to store main buffer in SAVE_BUFFER/RESET_BUFFER mode
screen_char_t *temp_buffer;
// default line stuff
screen_char_t default_bg_code;
screen_char_t default_fg_code;
int default_line_width;
// Max size of scrollback buffer
unsigned int max_scrollback_lines;
// This flag overrides max_scrollback_lines:
BOOL unlimitedScrollback_;
// how many scrollback lines have been lost due to overflow
int scrollback_overflow;
long long cumulative_scrollback_overflow;
// print to ansi...
BOOL printToAnsi; // YES=ON, NO=OFF, default=NO;
NSMutableString *printToAnsiString;
// Growl stuff
iTermGrowlDelegate* gd;
// Scrollback buffer
LineBuffer* linebuffer;
FindContext findContext;
long long savedFindContextAbsPos_;
// Used for recording instant replay.
DVR* dvr;
BOOL saveToScrollbackInAlternateScreen_;
}
- (id)init;
- (void)dealloc;
- (NSString *)description;
- (screen_char_t*)initScreenWithWidth:(int)width Height:(int)height;
- (void)resizeWidth:(int)new_width height:(int)height;
- (void)reset;
- (void)setWidth:(int)width height:(int)height;
- (int)width;
- (int)height;
- (void)setScrollback:(unsigned int)lines;
- (void)setUnlimitedScrollback:(BOOL)enable;
- (void)setTerminal:(VT100Terminal *)terminal;
- (VT100Terminal *)terminal;
- (void)setShellTask:(PTYTask *)shell;
- (PTYTask *)shellTask;
- (PTYSession *) session;
- (void)setSession:(PTYSession *)session;
- (PTYTextView *) display;
- (void) setDisplay: (PTYTextView *) aDisplay;
- (BOOL) blinkingCursor;
- (void) setBlinkingCursor: (BOOL) flag;
- (void)showCursor:(BOOL)show;
- (void)setPlayBellFlag:(BOOL)flag;
- (void)setShowBellFlag:(BOOL)flag;
- (void)setFlashBellFlag:(BOOL)flag;
- (void)setGrowlFlag:(BOOL)flag;
- (void)setSaveToScrollbackInAlternateScreen:(BOOL)flag;
- (BOOL)growl;
// line access
// This function is dangerous! It writes to an internal buffer and returns a
// pointer to it. Better to use getLineAtIndex:withBuffer:.
- (screen_char_t *) getLineAtIndex: (int) theIndex;
// Provide a buffer as large as sizeof(screen_char_t*) * ([SCREEN width] + 1)
- (screen_char_t *)getLineAtIndex:(int)theIndex withBuffer:(screen_char_t*)buffer;
- (screen_char_t *)getLineAtScreenIndex:(int)theIndex;
- (NSString *)getLineString:(screen_char_t *)theLine;
// edit screen buffer
- (void)putToken:(VT100TCC)token;
- (void)clearBuffer;
- (long long)absoluteLineNumberOfCursor;
- (void)clearScrollbackBuffer;
- (void)saveBuffer;
- (void)restoreBuffer;
- (void)mouseModeDidChange:(MouseMode)mouseMode;
// internal
- (void)setString:(NSString *)s ascii:(BOOL)ascii;
- (void)setStringToX:(int)x
Y:(int)y
string:(NSString *)string
ascii:(BOOL)ascii;
- (void)addLineToScrollback;
- (void)setNewLine;
- (void)deleteCharacters:(int)n;
- (void)backSpace;
- (void)backTab;
- (void)setTab;
- (void)clearTabStop;
- (BOOL)haveTabStopAt:(int)x;
- (void)setTabStopAt:(int)x;
- (void)removeTabStopAt:(int)x;
- (void)clearScreen;
- (void)eraseInDisplay:(VT100TCC)token;
- (void)eraseInLine:(VT100TCC)token;
- (void)selectGraphicRendition:(VT100TCC)token;
- (void)cursorLeft:(int)n;
- (void)cursorRight:(int)n;
- (void)cursorUp:(int)n;
- (void)cursorDown:(int)n;
- (void)cursorToX: (int) x;
- (void)cursorToX:(int)x Y:(int)y;
- (void)saveCursorPosition;
- (void)restoreCursorPosition;
- (void)setTopBottom:(VT100TCC)token;
- (void)scrollUp;
- (void)scrollDown;
- (void)activateBell;
- (void)deviceReport:(VT100TCC)token;
- (void)deviceAttribute:(VT100TCC)token;
- (void)insertBlank: (int)n;
- (void)insertLines: (int)n;
- (void)deleteLines: (int)n;
- (void)blink;
- (int)cursorX;
- (int)cursorY;
- (int)numberOfLines;
- (int)numberOfScrollbackLines;
- (int)scrollbackOverflow;
- (long long)totalScrollbackOverflow;
- (void)resetScrollbackOverflow;
- (void)scrollScreenIntoScrollbackBuffer:(int)leaving;
// Set a range of bytes to dirty=1
- (void)setRangeDirty:(NSRange)range;
// OR in a value into the dirty array at an x,y coordinate
- (void)setCharDirtyAtX:(int)x Y:(int)y value:(int)v;
// Retrieve the dirty flags at an x,y coordinate
- (int)dirtyAtX:(int)x Y:(int)y;
// Check if any flag is set at an x,y coordinate in the dirty array
- (BOOL)isDirtyAtX:(int)x Y:(int)y;
- (void)resetDirty;
- (void)setDirty;
// print to ansi...
- (BOOL) printToAnsi;
- (void) setPrintToAnsi: (BOOL) aFlag;
- (void) printStringToAnsi: (NSString *) aString;
// UI stuff
- (void) doPrint;
// Is this character double width on this screen?
- (BOOL)isDoubleWidthCharacter:(unichar)c;
// Initialize the find context.
- (FindContext*)findContext;
- (void)initFindString:(NSString*)aString
forwardDirection:(BOOL)direction
ignoringCase:(BOOL)ignoreCase
regex:(BOOL)regex
startingAtX:(int)x
startingAtY:(int)y
withOffset:(int)offsetof
inContext:(FindContext*)context
multipleResults:(BOOL)multipleResults;
- (BOOL)continueFindResultAtStartX:(int*)startX
atStartY:(int*)startY
atEndX:(int*)endX
atEndY:(int*)endY
found:(BOOL*)found
inContext:(FindContext*)context;
// Find all matches to to the search in the provided context. Returns YES if it
// should be called again.
- (BOOL)continueFindAllResults:(NSMutableArray*)results
inContext:(FindContext*)context;
- (void)cancelFindInContext:(FindContext*)context;
- (void)dumpDebugLog;
// Set the colors in the prototype char to all text on screen that matches the regex.
- (void)highlightTextMatchingRegex:(NSString *)regex
prototypeChar:(screen_char_t)prototypechar;
// Return a human-readable dump of the screen contents.
- (NSString*)debugString;
// Save the current state to a new frame in the dvr.
- (void)saveToDvr;
// Turn off DVR for this screen.
- (void)disableDvr;
// Accessor.
- (DVR*)dvr;
// If this returns true then the textview will broadcast iTermTabContentsChanged
// when a dirty char is found.
- (BOOL)shouldSendContentsChangedNotification;
// Load a frame from a dvr decoder.
- (void)setFromFrame:(screen_char_t*)s len:(int)len info:(DVRFrameInfo)info;
// Save the position of the current find context (with the screen appended).
- (void)saveFindContextAbsPos;
// Save the position of the end of the scrollback buffer without the screen appeneded.
- (void)saveTerminalAbsPos;
// Restore the saved position into a passed-in find context (see saveFindContextAbsPos and saveTerminalAbsPos).
- (void)restoreSavedPositionToFindContext:(FindContext *)context;
@end