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