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