Debian Codegraph @

lib/Vt102Emulation.h

raw symbols SCIP
1 /*
2 This file is part of Konsole, an X terminal.
3
4 Copyright 2007-2008 by Robert Knight <[email protected]>
5 Copyright 1997,1998 by Lars Doelle <[email protected]>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA.
21 */
22
23 #ifndef VT102EMULATION_H
24 #define VT102EMULATION_H
25
26 // Standard Library
27 #include <cstdio>
28
29 // Qt
30 #include <QKeyEvent>
31 #include <QHash>
32 #include <QTimer>
33
34 // Konsole
35 #include "Emulation.h"
36 #include "Screen.h"
37
38 #define MODE_AppScreen (MODES_SCREEN+0) // Mode #1
39 #define MODE_AppCuKeys (MODES_SCREEN+1) // Application cursor keys (DECCKM)
40 #define MODE_AppKeyPad (MODES_SCREEN+2) //
41 #define MODE_Mouse1000 (MODES_SCREEN+3) // Send mouse X,Y position on press and release
42 #define MODE_Mouse1001 (MODES_SCREEN+4) // Use Hilight mouse tracking
43 #define MODE_Mouse1002 (MODES_SCREEN+5) // Use cell motion mouse tracking
44 #define MODE_Mouse1003 (MODES_SCREEN+6) // Use all motion mouse tracking
45 #define MODE_Mouse1005 (MODES_SCREEN+7) // Xterm-style extended coordinates
46 #define MODE_Mouse1006 (MODES_SCREEN+8) // 2nd Xterm-style extended coordinates
47 #define MODE_Mouse1015 (MODES_SCREEN+9) // Urxvt-style extended coordinates
48 #define MODE_Ansi (MODES_SCREEN+10) // Use US Ascii for character sets G0-G3 (DECANM)
49 #define MODE_132Columns (MODES_SCREEN+11) // 80 <-> 132 column mode switch (DECCOLM)
50 #define MODE_Allow132Columns (MODES_SCREEN+12) // Allow DECCOLM mode
51 #define MODE_BracketedPaste (MODES_SCREEN+13) // Xterm-style bracketed paste mode
52 #define MODE_total (MODES_SCREEN+14)
53
54 namespace Konsole
55 {
56
57 struct CharCodes
58 {
59 // coding info
60 char charset[4]; //
61 int cu_cs; // actual charset.
62 bool graphic; // Some VT100 tricks
63 bool pound ; // Some VT100 tricks
64 bool sa_graphic; // saved graphic
65 bool sa_pound; // saved pound
66 };
67
68 /**
69 * Provides an xterm compatible terminal emulation based on the DEC VT102 terminal.
70 * A full description of this terminal can be found at http://vt100.net/docs/vt102-ug/
71 *
72 * In addition, various additional xterm escape sequences are supported to provide
73 * features such as mouse input handling.
74 * See http://rtfm.etla.org/xterm/ctlseq.html for a description of xterm's escape
75 * sequences.
76 *
77 */
78 class Vt102Emulation : public Emulation
79 {
80 Q_OBJECT
81
82 public:
83 /** Constructs a new emulation */
84 Vt102Emulation();
85 ~Vt102Emulation() override;
86
87 // reimplemented from Emulation
88 void clearEntireScreen() override;
89 void reset() override;
90 char eraseChar() const override;
91
92 public slots:
93 // reimplemented from Emulation
94 void sendString(const char*,int length = -1) override;
95 void sendText(const QString& text) override;
96 void sendKeyEvent(QKeyEvent*, bool fromPaste) override;
97 void sendMouseEvent(int buttons, int column, int line, int eventType) override;
98 virtual void focusLost();
99 virtual void focusGained();
100
101 protected:
102 // reimplemented from Emulation
103 void setMode(int mode) override;
104 void resetMode(int mode) override;
105 void receiveChar(wchar_t cc) override;
106
107 private slots:
108 //causes changeTitle() to be emitted for each (int,QString) pair in pendingTitleUpdates
109 //used to buffer multiple title updates
110 void updateTitle();
111
112 private:
113 wchar_t applyCharset(wchar_t c);
114 void setCharset(int n, int cs);
115 void useCharset(int n);
116 void setAndUseCharset(int n, int cs);
117 void saveCursor();
118 void restoreCursor();
119 void resetCharset(int scrno);
120 QKeyEvent * remapKeyModifiersForMac(QKeyEvent *event);
121
122
123 void setMargins(int top, int bottom);
124 //set margins for all screens back to their defaults
125 void setDefaultMargins();
126
127 // returns true if 'mode' is set or false otherwise
128 bool getMode (int mode);
129 // saves the current boolean value of 'mode'
130 void saveMode (int mode);
131 // restores the boolean value of 'mode'
132 void restoreMode(int mode);
133 // resets all modes
134 // (except MODE_Allow132Columns)
135 void resetModes();
136
137 void resetTokenizer();
138 #define MAX_TOKEN_LENGTH 256 // Max length of tokens (e.g. window title)
139 void addToCurrentToken(wchar_t cc);
140 wchar_t tokenBuffer[MAX_TOKEN_LENGTH]; //FIXME: overflow?
141 int tokenBufferPos;
142 #define MAXARGS 15
143 void addDigit(int dig);
144 void addArgument();
145 int argv[MAXARGS];
146 int argc;
147 void initTokenizer();
148 int prevCC;
149
150 // Set of flags for each of the ASCII characters which indicates
151 // what category they fall into (printable character, control, digit etc.)
152 // for the purposes of decoding terminal output
153 int charClass[256];
154
155 void reportDecodingError();
156
157 void processToken(int code, wchar_t p, int q);
158 void processWindowAttributeChange();
159 void requestWindowAttribute(int);
160
161 void reportTerminalType();
162 void reportSecondaryAttributes();
163 void reportStatus();
164 void reportAnswerBack();
165 void reportCursorPosition();
166 void reportTerminalParms(int p);
167
168 void onScrollLock();
169 void scrollLock(const bool lock);
170
171 // clears the screen and resizes it to the specified
172 // number of columns
173 void clearScreenAndSetColumns(int columnCount);
174
175 CharCodes _charset[2];
176
177 class TerminalState
178 {
179 public:
180 // Initializes all modes to false
181 TerminalState()
182 { memset(&mode,false,MODE_total * sizeof(bool)); }
183
184 bool mode[MODE_total];
185 };
186
187 TerminalState _currentModes;
188 TerminalState _savedModes;
189
190 //hash table and timer for buffering calls to the session instance
191 //to update the name of the session
192 //or window title.
193 //these calls occur when certain escape sequences are seen in the
194 //output from the terminal
195 QHash<int,QString> _pendingTitleUpdates;
196 QTimer* _titleUpdateTimer;
197
198 bool _reportFocusEvents;
199 };
200
201 }
202
203 #endif // VT102EMULATION_H