[45157b3] | 1 | /* |
---|
| 2 | This file is part of Konsole, an X terminal. |
---|
| 3 | |
---|
| 4 | Copyright (C) 2007 by Robert Knight <robertknight@gmail.com> |
---|
| 5 | Copyright (C) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> |
---|
| 6 | |
---|
| 7 | Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008 |
---|
| 8 | |
---|
| 9 | This program is free software; you can redistribute it and/or modify |
---|
| 10 | it under the terms of the GNU General Public License as published by |
---|
| 11 | the Free Software Foundation; either version 2 of the License, or |
---|
| 12 | (at your option) any later version. |
---|
| 13 | |
---|
| 14 | This program is distributed in the hope that it will be useful, |
---|
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | GNU General Public License for more details. |
---|
| 18 | |
---|
| 19 | You should have received a copy of the GNU General Public License |
---|
| 20 | along with this program; if not, write to the Free Software |
---|
| 21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
---|
| 22 | 02110-1301 USA. |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #ifndef VT102EMULATION_H |
---|
| 26 | #define VT102EMULATION_H |
---|
| 27 | |
---|
| 28 | // Standard Library |
---|
| 29 | #include <stdio.h> |
---|
| 30 | |
---|
| 31 | // Qt |
---|
| 32 | #include <QtGui/QKeyEvent> |
---|
| 33 | #include <QtCore/QHash> |
---|
| 34 | #include <QtCore/QTimer> |
---|
| 35 | |
---|
| 36 | // Konsole |
---|
| 37 | #include "Emulation.h" |
---|
| 38 | #include "Screen.h" |
---|
| 39 | |
---|
| 40 | #define MODE_AppScreen (MODES_SCREEN+0) |
---|
| 41 | #define MODE_AppCuKeys (MODES_SCREEN+1) |
---|
| 42 | #define MODE_AppKeyPad (MODES_SCREEN+2) |
---|
| 43 | #define MODE_Mouse1000 (MODES_SCREEN+3) |
---|
| 44 | #define MODE_Mouse1001 (MODES_SCREEN+4) |
---|
| 45 | #define MODE_Mouse1002 (MODES_SCREEN+5) |
---|
| 46 | #define MODE_Mouse1003 (MODES_SCREEN+6) |
---|
| 47 | #define MODE_Ansi (MODES_SCREEN+7) |
---|
| 48 | #define MODE_total (MODES_SCREEN+8) |
---|
| 49 | |
---|
| 50 | namespace Konsole |
---|
| 51 | { |
---|
| 52 | |
---|
| 53 | struct DECpar |
---|
| 54 | { |
---|
| 55 | bool mode[MODE_total]; |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | struct CharCodes |
---|
| 59 | { |
---|
| 60 | // coding info |
---|
| 61 | char charset[4]; // |
---|
| 62 | int cu_cs; // actual charset. |
---|
| 63 | bool graphic; // Some VT100 tricks |
---|
| 64 | bool pound ; // Some VT100 tricks |
---|
| 65 | bool sa_graphic; // saved graphic |
---|
| 66 | bool sa_pound; // saved pound |
---|
| 67 | }; |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * Provides an xterm compatible terminal emulation based on the DEC VT102 terminal. |
---|
| 71 | * A full description of this terminal can be found at http://vt100.net/docs/vt102-ug/ |
---|
| 72 | * |
---|
| 73 | * In addition, various additional xterm escape sequences are supported to provide |
---|
| 74 | * features such as mouse input handling. |
---|
| 75 | * See http://rtfm.etla.org/xterm/ctlseq.html for a description of xterm's escape |
---|
| 76 | * sequences. |
---|
| 77 | * |
---|
| 78 | */ |
---|
| 79 | class Vt102Emulation : public Emulation |
---|
| 80 | { |
---|
| 81 | Q_OBJECT |
---|
| 82 | |
---|
| 83 | public: |
---|
| 84 | |
---|
| 85 | /** Constructs a new emulation */ |
---|
| 86 | Vt102Emulation(); |
---|
| 87 | ~Vt102Emulation(); |
---|
| 88 | |
---|
| 89 | // reimplemented |
---|
| 90 | virtual void clearEntireScreen(); |
---|
| 91 | virtual void reset(); |
---|
| 92 | |
---|
| 93 | // reimplemented |
---|
| 94 | virtual char getErase() const; |
---|
| 95 | |
---|
| 96 | public slots: |
---|
| 97 | |
---|
| 98 | // reimplemented |
---|
| 99 | virtual void sendString(const char*,int length = -1); |
---|
| 100 | virtual void sendText(const QString& text); |
---|
| 101 | virtual void sendKeyEvent(QKeyEvent*); |
---|
| 102 | virtual void sendMouseEvent( int buttons, int column, int line , int eventType ); |
---|
| 103 | |
---|
| 104 | protected: |
---|
| 105 | // reimplemented |
---|
| 106 | virtual void setMode (int mode); |
---|
| 107 | virtual void resetMode (int mode); |
---|
| 108 | |
---|
| 109 | // reimplemented |
---|
| 110 | virtual void receiveChar(int cc); |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | private slots: |
---|
| 114 | |
---|
| 115 | //causes changeTitle() to be emitted for each (int,QString) pair in pendingTitleUpdates |
---|
| 116 | //used to buffer multiple title updates |
---|
| 117 | void updateTitle(); |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | private: |
---|
| 121 | unsigned short applyCharset(unsigned short c); |
---|
| 122 | void setCharset(int n, int cs); |
---|
| 123 | void useCharset(int n); |
---|
| 124 | void setAndUseCharset(int n, int cs); |
---|
| 125 | void saveCursor(); |
---|
| 126 | void restoreCursor(); |
---|
| 127 | void resetCharset(int scrno); |
---|
| 128 | |
---|
| 129 | void setMargins(int top, int bottom); |
---|
| 130 | //set margins for all screens back to their defaults |
---|
| 131 | void setDefaultMargins(); |
---|
| 132 | |
---|
| 133 | // returns true if 'mode' is set or false otherwise |
---|
| 134 | bool getMode (int mode); |
---|
| 135 | // saves the current boolean value of 'mode' |
---|
| 136 | void saveMode (int mode); |
---|
| 137 | // restores the boolean value of 'mode' |
---|
| 138 | void restoreMode(int mode); |
---|
| 139 | // resets all modes |
---|
| 140 | void resetModes(); |
---|
| 141 | |
---|
| 142 | void resetToken(); |
---|
| 143 | #define MAXPBUF 80 |
---|
| 144 | void pushToToken(int cc); |
---|
| 145 | int pbuf[MAXPBUF]; //FIXME: overflow? |
---|
| 146 | int ppos; |
---|
| 147 | #define MAXARGS 15 |
---|
| 148 | void addDigit(int dig); |
---|
| 149 | void addArgument(); |
---|
| 150 | int argv[MAXARGS]; |
---|
| 151 | int argc; |
---|
| 152 | void initTokenizer(); |
---|
| 153 | int tbl[256]; |
---|
| 154 | |
---|
| 155 | void scan_buffer_report(); //FIXME: rename |
---|
| 156 | void ReportErrorToken(); //FIXME: rename |
---|
| 157 | |
---|
| 158 | void tau(int code, int p, int q); |
---|
| 159 | void XtermHack(); |
---|
| 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 | DECpar _currParm; |
---|
| 178 | DECpar _saveParm; |
---|
| 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 | } |
---|
| 191 | |
---|
| 192 | #endif // VT102EMULATION_H |
---|