Changeset View
Changeset View
Standalone View
Standalone View
src/Vt102Emulation.cpp
Context not available. | |||||
37 | 37 | | |||
---|---|---|---|---|---|
38 | // Konsole | 38 | // Konsole | ||
39 | #include "KeyboardTranslator.h" | 39 | #include "KeyboardTranslator.h" | ||
40 | #include "Session.h" | ||||
41 | #include "SessionController.h" | ||||
42 | #include "SessionManager.h" | ||||
40 | #include "TerminalDisplay.h" | 43 | #include "TerminalDisplay.h" | ||
41 | 44 | | |||
42 | using Konsole::Vt102Emulation; | 45 | using Konsole::Vt102Emulation; | ||
Context not available. | |||||
148 | - ESC_DE - Escape codes of the form <ESC><any of `()+*#%'> C | 151 | - ESC_DE - Escape codes of the form <ESC><any of `()+*#%'> C | ||
149 | - CSI_PN - Escape codes of the form <ESC>'[' {Pn} ';' {Pn} C | 152 | - CSI_PN - Escape codes of the form <ESC>'[' {Pn} ';' {Pn} C | ||
150 | - CSI_PS - Escape codes of the form <ESC>'[' {Pn} ';' ... C | 153 | - CSI_PS - Escape codes of the form <ESC>'[' {Pn} ';' ... C | ||
154 | - CSI_DBL - Escape codes of the form <ESC>'[' {Pn} ';' ... C C | ||||
151 | - CSI_PR - Escape codes of the form <ESC>'[' '?' {Pn} ';' ... C | 155 | - CSI_PR - Escape codes of the form <ESC>'[' '?' {Pn} ';' ... C | ||
152 | - CSI_PE - Escape codes of the form <ESC>'[' '!' {Pn} ';' ... C | 156 | - CSI_PE - Escape codes of the form <ESC>'[' '!' {Pn} ';' ... C | ||
153 | - VT52 - VT52 escape codes | 157 | - VT52 - VT52 escape codes | ||
Context not available. | |||||
180 | #define TY_CSI_PG(A) TY_CONSTRUCT(9,A,0) | 184 | #define TY_CSI_PG(A) TY_CONSTRUCT(9,A,0) | ||
181 | #define TY_CSI_PE(A) TY_CONSTRUCT(10,A,0) | 185 | #define TY_CSI_PE(A) TY_CONSTRUCT(10,A,0) | ||
182 | 186 | | |||
187 | #define TY_CSI_DBL(A,B) TY_CONSTRUCT(11,A,B) | ||||
188 | | ||||
183 | const int MAX_ARGUMENT = 4096; | 189 | const int MAX_ARGUMENT = 4096; | ||
184 | 190 | | |||
185 | // Tokenizer --------------------------------------------------------------- -- | 191 | // Tokenizer --------------------------------------------------------------- -- | ||
Context not available. | |||||
226 | const int SCS = 16; // Select Character Set | 232 | const int SCS = 16; // Select Character Set | ||
227 | const int GRP = 32; // TODO: Document me | 233 | const int GRP = 32; // TODO: Document me | ||
228 | const int CPS = 64; // Character which indicates end of window resize | 234 | const int CPS = 64; // Character which indicates end of window resize | ||
235 | const int CSIDBLF = 128; // characters which can come first in a 2 character CSI command | ||||
229 | 236 | | |||
230 | void Vt102Emulation::initTokenizer() | 237 | void Vt102Emulation::initTokenizer() | ||
231 | { | 238 | { | ||
Context not available. | |||||
256 | for (s = (quint8 *)"()+*#[]%"; *s != 0u; ++s) { | 263 | for (s = (quint8 *)"()+*#[]%"; *s != 0u; ++s) { | ||
257 | charClass[*s] |= GRP; | 264 | charClass[*s] |= GRP; | ||
258 | } | 265 | } | ||
266 | for (s = (quint8 *)" '$\""; *s != 0u; ++s) { | ||||
267 | charClass[*s] |= CSIDBLF; | ||||
268 | } | ||||
259 | 269 | | |||
260 | resetTokenizer(); | 270 | resetTokenizer(); | ||
261 | } | 271 | } | ||
Context not available. | |||||
292 | #define Xte (Xpe && (cc == 7 || cc == 27)) | 302 | #define Xte (Xpe && (cc == 7 || cc == 27)) | ||
293 | #define ces(C) (cc < 256 && (charClass[cc] & (C)) == (C) && !Xte) | 303 | #define ces(C) (cc < 256 && (charClass[cc] & (C)) == (C) && !Xte) | ||
294 | #define dcs (p >= 2 && s[0] == ESC && s[1] == 'P') | 304 | #define dcs (p >= 2 && s[0] == ESC && s[1] == 'P') | ||
305 | #define csi( ) (p >= 2 && s[0] == ESC && s[1] == '[') | ||||
306 | #define csidbl( ) (p >= 4 && csi() && (charClass[s[p-2]] & CSIDBLF) == CSIDBLF) | ||||
295 | 307 | | |||
296 | #define CNTL(c) ((c)-'@') | 308 | #define CNTL(c) ((c)-'@') | ||
297 | const int ESC = 27; | 309 | const int ESC = 27; | ||
Context not available. | |||||
351 | if (epe( )) { processToken( TY_CSI_PE(cc), 0, 0); resetTokenizer(); return; } | 363 | if (epe( )) { processToken( TY_CSI_PE(cc), 0, 0); resetTokenizer(); return; } | ||
352 | if (ees(DIG)) { addDigit(cc-'0'); return; } | 364 | if (ees(DIG)) { addDigit(cc-'0'); return; } | ||
353 | if (eec(';')) { addArgument(); return; } | 365 | if (eec(';')) { addArgument(); return; } | ||
366 | if (csi() && ees(CSIDBLF)) { return; } // possible first char of a 2 char CSI command | ||||
354 | for (int i = 0; i <= argc; i++) | 367 | for (int i = 0; i <= argc; i++) | ||
355 | { | 368 | { | ||
356 | if (epp()) | 369 | if (epp()) | ||
357 | processToken(TY_CSI_PR(cc,argv[i]), 0, 0); | 370 | processToken(TY_CSI_PR(cc,argv[i]), 0, 0); | ||
358 | else if (egt()) | 371 | else if (egt()) | ||
359 | processToken(TY_CSI_PG(cc), 0, 0); // spec. case for ESC]>0c or ESC]>c | 372 | processToken(TY_CSI_PG(cc), 0, 0); // spec. case for ESC]>0c or ESC]>c | ||
373 | else if (csidbl()) | ||||
374 | processToken(TY_CSI_DBL(cc, s[p-2]), argv[i], 0); | ||||
360 | else if (cc == 'm' && argc - i >= 4 && (argv[i] == 38 || argv[i] == 48) && argv[i+1] == 2) | 375 | else if (cc == 'm' && argc - i >= 4 && (argv[i] == 38 || argv[i] == 48) && argv[i+1] == 2) | ||
361 | { | 376 | { | ||
362 | // ESC[ ... 48;2;<red>;<green>;<blue> ... m -or- ESC[ ... 38;2;<red>;<green>;<blue> ... m | 377 | // ESC[ ... 48;2;<red>;<green>;<blue> ... m -or- ESC[ ... 38;2;<red>;<green>;<blue> ... m | ||
Context not available. | |||||
849 | 864 | | |||
850 | case TY_CSI_PG('c' ) : reportSecondaryAttributes( ); break; //VT100 | 865 | case TY_CSI_PG('c' ) : reportSecondaryAttributes( ); break; //VT100 | ||
851 | 866 | | |||
867 | case TY_CSI_DBL('q', ' ') : // DECSCUSR, VT510/VT520 | ||||
868 | { | ||||
869 | auto scusr = [this](bool blink, Enum::CursorShapeEnum shape) { | ||||
870 | _currentScreen->currentTerminalDisplay()->setBlinkingCursorEnabled(blink); | ||||
871 | _currentScreen->currentTerminalDisplay()->setKeyboardCursorShape(shape); | ||||
872 | }; | ||||
873 | switch (p) | ||||
874 | { | ||||
875 | case 0 : | ||||
876 | { // xterm treats 0 as case 1 (blinking block), vte reverts to 'default'. The | ||||
877 | // latter seems sensible, revert cursor to how it is set in the profile. | ||||
878 | auto session = _currentScreen->currentTerminalDisplay()->sessionController()->session(); | ||||
879 | auto profile = SessionManager::instance()->sessionProfile(session.data()); | ||||
880 | bool blink = profile->blinkingCursorEnabled(); | ||||
881 | auto shape = profile->property<int>(Profile::CursorShape); | ||||
882 | if (shape == Enum::BlockCursor) { | ||||
883 | scusr(blink, Enum::BlockCursor); | ||||
884 | } else if (shape == Enum::IBeamCursor) { | ||||
885 | scusr(blink, Enum::IBeamCursor); | ||||
886 | } else if (shape == Enum::UnderlineCursor) { | ||||
887 | scusr(blink, Enum::UnderlineCursor); | ||||
888 | } | ||||
889 | break; | ||||
890 | } | ||||
891 | case 1 : scusr(true, Enum::BlockCursor); break; | ||||
892 | case 2 : scusr(false, Enum::BlockCursor); break; | ||||
893 | case 3 : scusr(true, Enum::UnderlineCursor); break; | ||||
894 | case 4 : scusr(false, Enum::UnderlineCursor); break; | ||||
895 | case 5 : scusr(true, Enum::IBeamCursor); break; | ||||
896 | case 6 : scusr(false, Enum::IBeamCursor); break; | ||||
897 | default: break; | ||||
898 | } | ||||
899 | break; | ||||
900 | } | ||||
901 | | ||||
852 | default: | 902 | default: | ||
853 | reportDecodingError(); | 903 | reportDecodingError(); | ||
854 | break; | 904 | break; | ||
Context not available. |