MauiKit Terminal

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

KDE's Doxygen guidelines are available online.