Mercurial > hg > octave-lyh
annotate gui/src/terminal/Vt102Emulation.h @ 13623:f03f4ac63569
Now scrolling down on new messages.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Thu, 18 Aug 2011 13:53:32 +0200 |
parents | c70511cf64ee |
children |
rev | line source |
---|---|
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 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
38 #define MODE_AppScreen (MODES_SCREEN+0) // Mode #1 |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
39 #define MODE_AppCuKeys (MODES_SCREEN+1) // Application cursor keys (DECCKM) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
40 #define MODE_AppKeyPad (MODES_SCREEN+2) // |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
41 #define MODE_Mouse1000 (MODES_SCREEN+3) // Send mouse X,Y position on press and release |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
42 #define MODE_Mouse1001 (MODES_SCREEN+4) // Use Hilight mouse tracking |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
43 #define MODE_Mouse1002 (MODES_SCREEN+5) // Use cell motion mouse tracking |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
44 #define MODE_Mouse1003 (MODES_SCREEN+6) // Use all motion mouse tracking |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
45 #define MODE_Ansi (MODES_SCREEN+7) // Use US Ascii for character sets G0-G3 (DECANM) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
46 #define MODE_132Columns (MODES_SCREEN+8) // 80 <-> 132 column mode switch (DECCOLM) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
47 #define MODE_Allow132Columns (MODES_SCREEN+9) // Allow DECCOLM mode |
13501 | 48 #define MODE_total (MODES_SCREEN+10) |
49 | |
50 struct CharCodes | |
51 { | |
52 // coding info | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
53 char charset[4]; // |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
54 int cu_cs; // actual charset. |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
55 bool graphic; // Some VT100 tricks |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
56 bool pound; // Some VT100 tricks |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
57 bool sa_graphic; // saved graphic |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
58 bool sa_pound; // saved pound |
13501 | 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 */ | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
71 class Vt102Emulation:public Emulation |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
72 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
73 Q_OBJECT public: |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
74 /** Constructs a new emulation */ |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
75 Vt102Emulation (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
76 ~Vt102Emulation (); |
13501 | 77 |
78 // reimplemented from Emulation | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
79 virtual void clearEntireScreen (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
80 virtual void reset (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
81 virtual char eraseChar () const; |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
82 |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
83 public slots: |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
84 // reimplemented from Emulation |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
85 virtual void sendString (const char *, int length = -1); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
86 virtual void sendText (const QString & text); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
87 virtual void sendKeyEvent (QKeyEvent *); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
88 virtual void sendMouseEvent (int buttons, int column, int line, |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
89 int eventType); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
90 |
13501 | 91 protected: |
92 // reimplemented from Emulation | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
93 virtual void setMode (int mode); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
94 virtual void resetMode (int mode); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
95 virtual void receiveChar (int cc); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
96 |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
97 private slots: |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
98 //causes changeTitle() to be emitted for each (int,QString) pair in pendingTitleUpdates |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
99 //used to buffer multiple title updates |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
100 void updateTitle (); |
13501 | 101 |
102 private: | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
103 unsigned short applyCharset (unsigned short c); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
104 void setCharset (int n, int cs); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
105 void useCharset (int n); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
106 void setAndUseCharset (int n, int cs); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
107 void saveCursor (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
108 void restoreCursor (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
109 void resetCharset (int scrno); |
13501 | 110 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
111 void setMargins (int top, int bottom); |
13501 | 112 //set margins for all screens back to their defaults |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
113 void setDefaultMargins (); |
13501 | 114 |
115 // returns true if 'mode' is set or false otherwise | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
116 bool getMode (int mode); |
13501 | 117 // saves the current boolean value of 'mode' |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
118 void saveMode (int mode); |
13501 | 119 // restores the boolean value of 'mode' |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
120 void restoreMode (int mode); |
13501 | 121 // resets all modes |
122 // (except MODE_Allow132Columns) | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
123 void resetModes (); |
13501 | 124 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
125 void resetTokenizer (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
126 #define MAX_TOKEN_LENGTH 80 |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
127 void addToCurrentToken (int cc); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
128 int tokenBuffer[MAX_TOKEN_LENGTH]; //FIXME: overflow? |
13501 | 129 int tokenBufferPos; |
130 #define MAXARGS 15 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
131 void addDigit (int dig); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
132 void addArgument (); |
13501 | 133 int argv[MAXARGS]; |
134 int argc; | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
135 void initTokenizer (); |
13501 | 136 |
137 // Set of flags for each of the ASCII characters which indicates | |
138 // what category they fall into (printable character, control, digit etc.) | |
139 // for the purposes of decoding terminal output | |
140 int charClass[256]; | |
141 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
142 void reportDecodingError (); |
13501 | 143 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
144 void processToken (int code, int p, int q); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
145 void processWindowAttributeChange (); |
13501 | 146 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
147 void reportTerminalType (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
148 void reportSecondaryAttributes (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
149 void reportStatus (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
150 void reportAnswerBack (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
151 void reportCursorPosition (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
152 void reportTerminalParms (int p); |
13501 | 153 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
154 void onScrollLock (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
155 void scrollLock (const bool lock); |
13501 | 156 |
157 // clears the screen and resizes it to the specified | |
158 // number of columns | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
159 void clearScreenAndSetColumns (int columnCount); |
13501 | 160 |
161 CharCodes _charset[2]; | |
162 | |
163 class TerminalState | |
164 { | |
165 public: | |
166 // Initializes all modes to false | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
167 TerminalState () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
168 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
169 memset (&mode, false, MODE_total * sizeof (bool)); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
170 } |
13501 | 171 |
172 bool mode[MODE_total]; | |
173 }; | |
174 | |
175 TerminalState _currentModes; | |
176 TerminalState _savedModes; | |
177 | |
178 //hash table and timer for buffering calls to the session instance | |
179 //to update the name of the session | |
180 //or window title. | |
181 //these calls occur when certain escape sequences are seen in the | |
182 //output from the terminal | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
183 QHash < int, QString > _pendingTitleUpdates; |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
184 QTimer *_titleUpdateTimer; |
13501 | 185 }; |
186 | |
187 #endif // VT102EMULATION_H |