File indexing completed on 2024-04-21 05:51:27
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 0003 SPDX-FileCopyrightText: 1997, 1998 Lars Doelle <lars.doelle@on-line.de> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef SCREEN_H 0009 #define SCREEN_H 0010 0011 // STD 0012 #include <memory> 0013 0014 // Qt 0015 #include <QBitArray> 0016 #include <QRect> 0017 #include <QSet> 0018 #include <QVarLengthArray> 0019 #include <QVector> 0020 0021 // Konsole 0022 #include "../characters/Character.h" 0023 #include "konsoleprivate_export.h" 0024 0025 #define MODE_Origin 0 0026 #define MODE_Wrap 1 0027 #define MODE_Insert 2 0028 #define MODE_Screen 3 0029 #define MODE_Cursor 4 0030 #define MODE_NewLine 5 0031 #define MODE_AppScreen 6 0032 #define MODE_SelectCursor 7 0033 #define MODES_SCREEN 8 0034 0035 #define REPL_None 0 0036 #define REPL_PROMPT 1 0037 #define REPL_INPUT 2 0038 #define REPL_OUTPUT 3 0039 0040 struct TerminalGraphicsPlacement_t { 0041 QPixmap pixmap; 0042 qint64 id; 0043 qint64 pid; 0044 int z, X, Y, col, row, cols, rows; 0045 qreal opacity; 0046 bool scrolling; 0047 }; 0048 0049 namespace Konsole 0050 { 0051 class TerminalCharacterDecoder; 0052 class TerminalDisplay; 0053 class HistoryType; 0054 class HistoryScroll; 0055 class EscapeSequenceUrlExtractor; 0056 0057 /** 0058 \brief An image of characters with associated attributes. 0059 0060 The terminal emulation ( Emulation ) receives a serial stream of 0061 characters from the program currently running in the terminal. 0062 From this stream it creates an image of characters which is ultimately 0063 rendered by the display widget ( TerminalDisplay ). Some types of emulation 0064 may have more than one screen image. 0065 0066 getImage() is used to retrieve the currently visible image 0067 which is then used by the display widget to draw the output from the 0068 terminal. 0069 0070 The number of lines of output history which are kept in addition to the current 0071 screen image depends on the history scroll being used to store the output. 0072 The scroll is specified using setScroll() 0073 The output history can be retrieved using writeToStream() 0074 0075 The screen image has a selection associated with it, specified using 0076 setSelectionStart() and setSelectionEnd(). The selected text can be retrieved 0077 using selectedText(). When getImage() is used to retrieve the visible image, 0078 characters which are part of the selection have their colors inverted. 0079 */ 0080 class KONSOLEPRIVATE_EXPORT Screen 0081 { 0082 public: 0083 /* PlainText: Return plain text (default) 0084 * ConvertToHtml: Specifies if returned text should have HTML tags. 0085 * PreserveLineBreaks: Specifies whether new line characters should be 0086 * inserted into the returned text at the end of each terminal line. 0087 * TrimLeadingWhitespace: Specifies whether leading spaces should be 0088 * trimmed in the returned text. 0089 * TrimTrailingWhitespace: Specifies whether trailing spaces should be 0090 * trimmed in the returned text. 0091 */ 0092 enum DecodingOption { 0093 PlainText = 0x0, 0094 ConvertToHtml = 0x1, 0095 PreserveLineBreaks = 0x2, 0096 TrimLeadingWhitespace = 0x4, 0097 TrimTrailingWhitespace = 0x8, 0098 ExcludePrompt = 0x10, 0099 ExcludeInput = 0x20, 0100 ExcludeOutput = 0x40, 0101 }; 0102 Q_DECLARE_FLAGS(DecodingOptions, DecodingOption) 0103 0104 /** Construct a new screen image of size @p lines by @p columns. */ 0105 Screen(int lines, int columns); 0106 ~Screen(); 0107 0108 Screen(const Screen &) = delete; 0109 Screen &operator=(const Screen &) = delete; 0110 0111 EscapeSequenceUrlExtractor *urlExtractor() const; 0112 0113 // VT100/2 Operations 0114 // Cursor Movement 0115 0116 /** 0117 * Move the cursor up by @p n lines. The cursor will stop at the 0118 * top margin. 0119 */ 0120 void cursorUp(int n); 0121 /** 0122 * Move the cursor down by @p n lines. The cursor will stop at the 0123 * bottom margin. 0124 */ 0125 void cursorDown(int n); 0126 /** 0127 * Move the cursor to the left by @p n columns. 0128 * The cursor will stop at the first column. 0129 */ 0130 void cursorLeft(int n); 0131 /** 0132 * Moves cursor to beginning of the line by @p n lines down. 0133 * The cursor will stop at the beginning of the line. 0134 */ 0135 void cursorNextLine(int n); 0136 /** 0137 * Moves cursor to beginning of the line by @p n lines up. 0138 * The cursor will stop at the beginning of the line. 0139 */ 0140 void cursorPreviousLine(int n); 0141 /** 0142 * Move the cursor to the right by @p n columns. 0143 * The cursor will stop at the right-most column. 0144 */ 0145 void cursorRight(int n); 0146 /** Position the cursor on line @p y. */ 0147 void setCursorY(int y); 0148 /** Position the cursor at column @p x. */ 0149 void setCursorX(int x); 0150 /** Position the cursor at line @p y, column @p x. */ 0151 void setCursorYX(int y, int x); 0152 0153 void initSelCursor(); 0154 int selCursorUp(int n); 0155 int selCursorDown(int n); 0156 int selCursorLeft(int n); 0157 int selCursorRight(int n); 0158 0159 int selSetSelectionStart(int mode); 0160 int selSetSelectionEnd(int mode); 0161 0162 /** 0163 * Sets the margins for scrolling the screen. 0164 * 0165 * @param top The top line of the new scrolling margin. 0166 * @param bot The bottom line of the new scrolling margin. 0167 */ 0168 void setMargins(int top, int bot); 0169 /** Returns the top line of the scrolling region. */ 0170 int topMargin() const; 0171 /** Returns the bottom line of the scrolling region. */ 0172 int bottomMargin() const; 0173 0174 /** 0175 * Resets the scrolling margins back to the top and bottom lines 0176 * of the screen. 0177 */ 0178 void setDefaultMargins(); 0179 0180 /** 0181 * Moves the cursor down one line, if the MODE_NewLine mode 0182 * flag is enabled then the cursor is returned to the leftmost 0183 * column first. 0184 * 0185 * Equivalent to NextLine() if the MODE_NewLine flag is set 0186 * or index() otherwise. 0187 */ 0188 void newLine(); 0189 /** 0190 * Moves the cursor down one line and positions it at the beginning 0191 * of the line. Equivalent to calling Return() followed by index() 0192 */ 0193 void nextLine(); 0194 0195 /** 0196 * Move the cursor down one line. If the cursor is on the bottom 0197 * line of the scrolling region (as returned by bottomMargin()) the 0198 * scrolling region is scrolled up by one line instead. 0199 */ 0200 void index(); 0201 /** 0202 * Move the cursor up one line. If the cursor is on the top line 0203 * of the scrolling region (as returned by topMargin()) the scrolling 0204 * region is scrolled down by one line instead. 0205 */ 0206 void reverseIndex(); 0207 0208 /** 0209 * Scroll the scrolling region of the screen up by @p n lines. 0210 * The scrolling region is initially the whole screen, but can be changed 0211 * using setMargins() 0212 */ 0213 void scrollUp(int n); 0214 /** 0215 * Scroll the scrolling region of the screen down by @p n lines. 0216 * The scrolling region is initially the whole screen, but can be changed 0217 * using setMargins() 0218 */ 0219 void scrollDown(int n); 0220 /** 0221 * Moves the cursor to the beginning of the current line. 0222 * Equivalent to setCursorX(0) 0223 */ 0224 void toStartOfLine(); 0225 /** 0226 * Moves the cursor one column to the left and erases the character 0227 * at the new cursor position. 0228 */ 0229 void backspace(); 0230 /** Moves the cursor @p n tab-stops to the right. */ 0231 void tab(int n = 1); 0232 /** Moves the cursor @p n tab-stops to the left. */ 0233 void backtab(int n); 0234 0235 // Editing 0236 0237 /** 0238 * Erase @p n characters beginning from the current cursor position. 0239 * This is equivalent to over-writing @p n characters starting with the current 0240 * cursor position with spaces. 0241 * If @p n is 0 then one character is erased. 0242 */ 0243 void eraseChars(int n); 0244 /** 0245 * Delete @p n characters beginning from the current cursor position. 0246 * If @p n is 0 then one character is deleted. 0247 */ 0248 void deleteChars(int n); 0249 /** 0250 * Insert @p n blank characters beginning from the current cursor position. 0251 * The position of the cursor is not altered. 0252 * If @p n is 0 then one character is inserted. 0253 */ 0254 void insertChars(int n); 0255 /** 0256 * Repeat the preceding graphic character @p n times, including SPACE. 0257 * If @p n is 0 then the character is repeated once. 0258 */ 0259 void repeatChars(int n); 0260 /** 0261 * Removes @p n lines beginning from the current cursor position. 0262 * The position of the cursor is not altered. 0263 * If @p n is 0 then one line is removed. 0264 */ 0265 void deleteLines(int n); 0266 /** 0267 * Inserts @p lines beginning from the current cursor position. 0268 * The position of the cursor is not altered. 0269 * If @p n is 0 then one line is inserted. 0270 */ 0271 void insertLines(int n); 0272 /** Clears all the tab stops. */ 0273 void clearTabStops(); 0274 /** Sets or removes a tab stop at the cursor's current column. */ 0275 void changeTabStop(bool set); 0276 0277 /** Resets (clears) the specified screen @p m. */ 0278 void resetMode(int m); 0279 /** Sets (enables) the specified screen @p m. */ 0280 void setMode(int m); 0281 /** 0282 * Saves the state of the specified screen @p m. It can be restored 0283 * using restoreMode() 0284 */ 0285 void saveMode(int m); 0286 /** Restores the state of a screen @p m saved by calling saveMode() */ 0287 void restoreMode(int m); 0288 /** Returns whether the specified screen @p me is enabled or not .*/ 0289 bool getMode(int m) const; 0290 0291 /** 0292 * Saves the current position and appearance (text color and style) of the cursor. 0293 * It can be restored by calling restoreCursor() 0294 */ 0295 void saveCursor(); 0296 /** Restores the position and appearance of the cursor. See saveCursor() */ 0297 void restoreCursor(); 0298 0299 /** Clear the whole screen, moving the current screen contents into the history first. */ 0300 void clearEntireScreen(); 0301 /** 0302 * Clear the area of the screen from the current cursor position to the end of 0303 * the screen. 0304 */ 0305 void clearToEndOfScreen(); 0306 /** 0307 * Clear the area of the screen from the current cursor position to the start 0308 * of the screen. 0309 */ 0310 void clearToBeginOfScreen(); 0311 /** Clears the whole of the line on which the cursor is currently positioned. */ 0312 void clearEntireLine(); 0313 /** Clears from the current cursor position to the end of the line. */ 0314 void clearToEndOfLine(); 0315 /** Clears from the current cursor position to the beginning of the line. */ 0316 void clearToBeginOfLine(); 0317 0318 /** Fills the entire screen with the letter 'E' */ 0319 void helpAlign(); 0320 0321 /** 0322 * Enables the given @p rendition flag. Rendition flags control the appearance 0323 * of characters on the screen. 0324 * 0325 * @see Character::rendition 0326 */ 0327 void setRendition(RenditionFlags rendition); 0328 void setUnderlineType(int type); 0329 /** 0330 * Disables the given @p rendition flag. Rendition flags control the appearance 0331 * of characters on the screen. 0332 * 0333 * @see Character::rendition 0334 */ 0335 void resetRendition(RenditionFlags rendition); 0336 0337 /** 0338 * Sets the cursor's foreground color. 0339 * @param space The color space used by the @p color argument 0340 * @param color The new foreground color. The meaning of this depends on 0341 * the color @p space used. 0342 * 0343 * @see CharacterColor 0344 */ 0345 void setForeColor(int space, int color); 0346 /** 0347 * Sets the cursor's background color. 0348 * @param space The color space used by the @p color argument. 0349 * @param color The new background color. The meaning of this depends on 0350 * the color @p space used. 0351 * 0352 * @see CharacterColor 0353 */ 0354 void setBackColor(int space, int color); 0355 /** 0356 * Resets the cursor's color back to the default and sets the 0357 * character's rendition flags back to the default settings. 0358 */ 0359 void setDefaultRendition(); 0360 0361 void setULColor(int space, int color); 0362 0363 CharacterColor const *ulColorTable() const 0364 { 0365 return _ulColors; 0366 } 0367 0368 /** Returns the column which the cursor is positioned at. */ 0369 int getCursorX() const; 0370 /** Returns the line which the cursor is positioned on. */ 0371 int getCursorY() const; 0372 0373 /** 0374 * Resets the state of the screen. This resets the various screen modes 0375 * back to their default states. The cursor style and colors are reset 0376 * (as if setDefaultRendition() had been called) 0377 * 0378 * <ul> 0379 * <li>Line wrapping is enabled.</li> 0380 * <li>Origin mode is disabled.</li> 0381 * <li>Insert mode is disabled.</li> 0382 * <li>Cursor mode is enabled. TODO Document me</li> 0383 * <li>Screen mode is disabled. TODO Document me</li> 0384 * <li>New line mode is disabled. TODO Document me</li> 0385 * </ul> 0386 * 0387 * If @p softReset is true then perform a DECSTR, 0388 * otherwise perform RIS (Reset to Initial State). 0389 * 0390 * If @p preservePrompt is true, then attempt to preserve the 0391 * line with the command prompt even on a RIS. 0392 */ 0393 void reset(bool softReset = false, bool preservePrompt = false); 0394 0395 /** 0396 * Displays a new character at the current cursor position. 0397 * 0398 * If the cursor is currently positioned at the right-edge of the screen and 0399 * line wrapping is enabled then the character is added at the start of a new 0400 * line below the current one. 0401 * 0402 * If the MODE_Insert screen mode is currently enabled then the character 0403 * is inserted at the current cursor position, otherwise it will replace the 0404 * character already at the current cursor position. 0405 */ 0406 void displayCharacter(uint c); 0407 0408 /** 0409 * Resizes the image to a new fixed size of @p new_lines by @p new_columns. 0410 * In the case that @p new_columns is smaller than the current number of columns, 0411 * existing lines are not truncated. This prevents characters from being lost 0412 * if the terminal display is resized smaller and then larger again. 0413 * 0414 * The top and bottom margins are reset to the top and bottom of the new 0415 * screen size. Tab stops are also reset and the current selection is 0416 * cleared. 0417 */ 0418 void resizeImage(int new_lines, int new_columns); 0419 0420 /** 0421 * Returns the current screen image. 0422 * The result is an array of Characters of size [getLines()][getColumns()] which 0423 * must be freed by the caller after use. 0424 * 0425 * @param dest Buffer to copy the characters into 0426 * @param size Size of @p dest in Characters 0427 * @param startLine Index of first line to copy 0428 * @param endLine Index of last line to copy 0429 */ 0430 void getImage(Character *dest, int size, int startLine, int endLine) const; 0431 0432 /** 0433 * Returns the additional attributes associated with lines in the image. 0434 * The most important attribute is LINE_WRAPPED which specifies that the 0435 * line is wrapped, 0436 * other attributes control the size of characters in the line. 0437 */ 0438 QVector<LineProperty> getLineProperties(int startLine, int endLine) const; 0439 0440 /** Return the number of lines. */ 0441 int getLines() const 0442 { 0443 return _lines; 0444 } 0445 0446 /** Return the number of columns. */ 0447 int getColumns() const 0448 { 0449 return _columns; 0450 } 0451 0452 /** Return the number of lines in the history buffer. */ 0453 int getHistLines() const; 0454 /** 0455 * Sets the type of storage used to keep lines in the history. 0456 * If @p copyPreviousScroll is true then the contents of the previous 0457 * history buffer are copied into the new scroll. 0458 */ 0459 void setScroll(const HistoryType &, bool copyPreviousScroll = true); 0460 /** Returns the type of storage used to keep lines in the history. */ 0461 const HistoryType &getScroll() const; 0462 /** 0463 * Returns true if this screen keeps lines that are scrolled off the screen 0464 * in a history buffer. 0465 */ 0466 bool hasScroll() const; 0467 0468 /** 0469 * Sets the start of the selection. 0470 * 0471 * @param x The column index of the first character in the selection. 0472 * @param y The line index of the first character in the selection. 0473 * @param blockSelectionMode True if the selection is in column mode. 0474 */ 0475 void setSelectionStart(const int x, const int y, const bool blockSelectionMode); 0476 0477 /** 0478 * Sets the end of the current selection. 0479 * 0480 * @param x The column index of the last character in the selection. 0481 * @param y The line index of the last character in the selection. 0482 * @param trimTrailingWhitespace True if trailing whitespace is trimmed from the selection 0483 */ 0484 void setSelectionEnd(const int x, const int y, const bool trimTrailingWhitespace); 0485 0486 /** 0487 * Selects a range of characters with the same REPL mode as the character at (@p x, @p y) 0488 */ 0489 void selectReplContigious(const int x, const int y); 0490 0491 /** 0492 * Retrieves the start of the selection or the cursor position if there 0493 * is no selection. 0494 */ 0495 void getSelectionStart(int &column, int &line) const; 0496 0497 /** 0498 * Retrieves the end of the selection or the cursor position if there 0499 * is no selection. 0500 */ 0501 void getSelectionEnd(int &column, int &line) const; 0502 0503 /** Clears the current selection */ 0504 void clearSelection(); 0505 0506 /** Return the selection state */ 0507 bool hasSelection() const; 0508 0509 /** 0510 * Returns true if the character at (@p x, @p y) is part of the 0511 * current selection. 0512 */ 0513 bool isSelected(const int x, const int y) const; 0514 0515 /** 0516 * Convenience method. Returns the currently selected text. 0517 * @param options See Screen::DecodingOptions 0518 */ 0519 QString selectedText(const DecodingOptions options) const; 0520 0521 /** 0522 * Convenience method. Returns the text between two indices. 0523 * @param startIndex Specifies the starting text index 0524 * @param endIndex Specifies the ending text index 0525 * @param options See Screen::DecodingOptions 0526 */ 0527 QString text(int startIndex, int endIndex, const DecodingOptions options) const; 0528 0529 /** 0530 * Copies part of the output to a stream. 0531 * 0532 * @param decoder A decoder which converts terminal characters into text 0533 * @param fromLine The first line in the history to retrieve 0534 * @param toLine The last line in the history to retrieve 0535 */ 0536 void writeLinesToStream(TerminalCharacterDecoder *decoder, int fromLine, int toLine) const; 0537 0538 /** 0539 * Checks if the text between from and to is inside the current 0540 * selection. If this is the case, the selection is cleared. The 0541 * from and to are coordinates in the current viewable window. 0542 * The loc(x,y) macro can be used to generate these values from a 0543 * column,line pair. 0544 * 0545 * @param from The start of the area to check. 0546 * @param to The end of the area to check 0547 */ 0548 void checkSelection(int from, int to); 0549 0550 /** 0551 * Sets or clears an attribute of the current line. 0552 * 0553 * @param property The attribute to set or clear 0554 * Possible properties are: 0555 * LINE_WRAPPED: Specifies that the line is wrapped. 0556 * LINE_DOUBLEWIDTH: Specifies that the characters in the current line 0557 * should be double the normal width. 0558 * LINE_DOUBLEHEIGHT_TOP: 0559 * LINE_DOUBLEHEIGHT_BOTTOM: Specifies that the characters in the current line 0560 * should be double the normal height. 0561 * Double-height lines are formed of two lines containing the same characters, 0562 * with the top one having the LINE_DOUBLEHEIGHT_TOP attribute 0563 * and the bottom one having the LINE_DOUBLEHEIGHT_BOTTOM attribute. 0564 * This allows other parts of the code to work on the 0565 * assumption that all lines are the same height. 0566 * 0567 * @param enable true to apply the attribute to the current line or false to remove it 0568 */ 0569 void setLineProperty(quint16 property, bool enable); 0570 0571 /** 0572 * Set REPL mode (shell integration) 0573 * 0574 * @param mode is the REPL mode 0575 * Possible modes are: 0576 * REPL_None 0577 * REPL_PROMPT 0578 * REPL_INPUT 0579 * REPL_OUTPUT 0580 */ 0581 void setReplMode(int mode); 0582 void setExitCode(int exitCode); 0583 /** Return true if semantic shell integration is in use. */ 0584 bool hasRepl() const 0585 { 0586 return _hasRepl; 0587 } 0588 /** Return current REPL mode */ 0589 int replMode() const 0590 { 0591 return _replMode; 0592 } 0593 /** Return location of current REPL mode start. */ 0594 std::pair<int, int> replModeStart() const 0595 { 0596 return _replModeStart; 0597 } 0598 std::pair<int, int> replModeEnd() const 0599 { 0600 return _replModeEnd; 0601 } 0602 0603 /** 0604 * Returns the number of lines that the image has been scrolled up or down by, 0605 * since the last call to resetScrolledLines(). 0606 * 0607 * a positive return value indicates that the image has been scrolled up, 0608 * a negative return value indicates that the image has been scrolled down. 0609 */ 0610 int scrolledLines() const; 0611 0612 /** 0613 * Returns the region of the image which was last scrolled. 0614 * 0615 * This is the area of the image from the top margin to the 0616 * bottom margin when the last scroll occurred. 0617 */ 0618 QRect lastScrolledRegion() const; 0619 0620 /** 0621 * Resets the count of the number of lines that the image has been scrolled up or down by, 0622 * see scrolledLines() 0623 */ 0624 void resetScrolledLines(); 0625 0626 /** 0627 * Returns the number of lines of output which have been 0628 * dropped from the history since the last call 0629 * to resetDroppedLines() 0630 * 0631 * If the history is not unlimited then it will drop 0632 * the oldest lines of output if new lines are added when 0633 * it is full. 0634 */ 0635 int droppedLines() const; 0636 0637 /** 0638 * Resets the count of the number of lines dropped from 0639 * the history. 0640 */ 0641 void resetDroppedLines(); 0642 0643 /** 0644 * Fills the buffer @p dest with @p count instances of the default (ie. blank) 0645 * Character style. 0646 */ 0647 static void fillWithDefaultChar(Character *dest, int count); 0648 0649 void setCurrentTerminalDisplay(TerminalDisplay *display) 0650 { 0651 _currentTerminalDisplay = display; 0652 } 0653 0654 TerminalDisplay *currentTerminalDisplay() 0655 { 0656 return _currentTerminalDisplay; 0657 } 0658 0659 QSet<uint> usedExtendedChars() const 0660 { 0661 QSet<uint> result; 0662 for (int i = 0; i < _lines; ++i) { 0663 const ImageLine &il = _screenLines[i]; 0664 for (int j = 0; j < il.length(); ++j) { 0665 if (il[j].rendition.f.extended) { 0666 result << il[j].character; 0667 } 0668 } 0669 } 0670 return result; 0671 } 0672 0673 void setEnableUrlExtractor(const bool enable); 0674 0675 static const Character DefaultChar; 0676 0677 // Return the total number of lines before resize (fix scroll glitch) 0678 int getOldTotalLines(); 0679 // Return if it was a resize signal (fix scroll glitch) 0680 bool isResize(); 0681 // Set reflow condition 0682 void setReflowLines(bool enable); 0683 0684 /* Graphics display functions */ 0685 void addPlacement(QPixmap pixmap, 0686 int &rows, 0687 int &cols, 0688 int row = -1, 0689 int col = -1, 0690 bool scrolling = true, 0691 int moveCursor = 1, 0692 bool leaveText = false, 0693 int z = -1000, 0694 int id = -1, 0695 int pid = -1, 0696 qreal opacity = 1.0, 0697 int X = 0, 0698 int Y = 0); 0699 TerminalGraphicsPlacement_t *getGraphicsPlacement(unsigned int i); 0700 void delPlacements(int = 'a', qint64 = 0, qint64 = -1, int = 0, int = 0, int = 0); 0701 0702 bool hasGraphics() const 0703 { 0704 return _hasGraphics; 0705 } 0706 void setIgnoreWcWidth(bool ignore); 0707 0708 private: 0709 // copies a line of text from the screen or history into a stream using a 0710 // specified character decoder. Returns the number of lines actually copied, 0711 // which may be less than 'count' if (start+count) is more than the number of characters on 0712 // the line 0713 // 0714 // line - the line number to copy, from 0 (the earliest line in the history) up to 0715 // history->getLines() + lines - 1 0716 // start - the first column on the line to copy 0717 // count - the number of characters on the line to copy 0718 // decoder - a decoder which converts terminal characters (an Character array) into text 0719 // appendNewLine - if true a new line character (\n) is appended to the end of the line 0720 // isBlockSelectionMode - takes that in consideration while appending a new line. 0721 int copyLineToStream(int line, 0722 int start, 0723 int count, 0724 TerminalCharacterDecoder *decoder, 0725 bool appendNewLine, 0726 bool isBlockSelectionMode, 0727 const DecodingOptions options) const; 0728 0729 // fills a section of the screen image with the character 'c' 0730 // the parameters are specified as offsets from the start of the screen image. 0731 // the loc(x,y) macro can be used to generate these values from a column,line pair. 0732 // if resetLineRendition is true, all completely cleared lines will be set to single-width. 0733 void clearImage(int loca, int loce, char c, bool resetLineRendition = true); 0734 0735 // erases a rectangular section of the screen. 0736 void eraseBlock(int y, int x, int height, int width); 0737 0738 // move screen image between 'sourceBegin' and 'sourceEnd' to 'dest'. 0739 // the parameters are specified as offsets from the start of the screen image. 0740 // the loc(x,y) macro can be used to generate these values from a column,line pair. 0741 // 0742 // NOTE: moveImage() can only move whole lines 0743 void moveImage(int dest, int sourceBegin, int sourceEnd); 0744 // scroll up 'n' lines in current region, clearing the bottom 'n' lines 0745 void scrollUp(int from, int n); 0746 // scroll down 'n' lines in current region, clearing the top 'n' lines 0747 void scrollDown(int from, int n); 0748 0749 // when we handle scroll commands, we need to know which screenwindow will scroll 0750 TerminalDisplay *_currentTerminalDisplay; 0751 0752 void addHistLine(); 0753 // add lines from _screen to _history and remove from _screen the added lines (used to resize lines and columns) 0754 void fastAddHistLine(); 0755 0756 void initTabStops(); 0757 0758 void updateEffectiveRendition(); 0759 void reverseRendition(Character &p) const; 0760 0761 bool isSelectionValid() const; 0762 // copies text from 'startIndex' to 'endIndex' to a stream 0763 // startIndex and endIndex are positions generated using the loc(x,y) macro 0764 void writeToStream(TerminalCharacterDecoder *decoder, int startIndex, int endIndex, const DecodingOptions options) const; 0765 // copies 'count' lines from the screen buffer into 'dest', 0766 // starting from 'startLine', where 0 is the first line in the screen buffer 0767 void copyFromScreen(Character *dest, int startLine, int count) const; 0768 // copies 'count' lines from the history buffer into 'dest', 0769 // starting from 'startLine', where 0 is the first line in the history 0770 void copyFromHistory(Character *dest, int startLine, int count) const; 0771 0772 Character getCharacter(int col, int row) const; 0773 0774 // returns a buffer that can hold at most 'count' characters, 0775 // where the number of reallocations and object reinitializations 0776 // should be as minimal as possible 0777 static Character *getCharacterBuffer(const int size); 0778 0779 // Returns if its app mode or not 0780 inline bool isAppMode() 0781 { 0782 return _currentModes[MODE_AppScreen] == 1; 0783 } 0784 // Get the cursor line after checking if its app mode or not 0785 int getCursorLine(); 0786 // Set the cursor line after checking if its app mode or not 0787 void setCursorLine(int newLine); 0788 0789 int getLineLength(const int line) const; 0790 0791 // returns the width in columns of the specified screen line, 0792 // taking DECDWL/DECDHL (double width/height modes) into account. 0793 int getScreenLineColumns(const int line) const; 0794 0795 // screen image ---------------- 0796 int _lines; 0797 int _columns; 0798 0799 typedef QVector<Character> ImageLine; // [0..columns] 0800 std::vector<ImageLine> _screenLines; // [lines] 0801 int _screenLinesSize; // _screenLines.size() 0802 0803 int _scrolledLines; 0804 QRect _lastScrolledRegion; 0805 0806 int _droppedLines; 0807 0808 int _oldTotalLines; 0809 bool _isResize; 0810 bool _enableReflowLines; 0811 0812 std::vector<LineProperty> _lineProperties; 0813 LineProperty linePropertiesAt(unsigned int line); 0814 0815 // history buffer --------------- 0816 std::unique_ptr<HistoryScroll> _history; 0817 0818 // cursor location 0819 int _cuX; 0820 int _cuY; 0821 0822 // select mode cursor location 0823 int _selCuX{}; 0824 int _selCuY{}; 0825 0826 // cursor color and rendition info 0827 CharacterColor _currentForeground; 0828 CharacterColor _currentBackground; 0829 RenditionFlagsC _currentRendition; 0830 0831 CharacterColor _ulColors[15]; 0832 int _ulColorQueueStart; 0833 int _ulColorQueueEnd; 0834 int _currentULColor; 0835 0836 // margins ---------------- 0837 int _topMargin; 0838 int _bottomMargin; 0839 0840 // states ---------------- 0841 int _currentModes[MODES_SCREEN]; 0842 int _savedModes[MODES_SCREEN]; 0843 int _replMode; 0844 bool _hasRepl; 0845 bool _replHadOutput; 0846 std::pair<int, int> _replModeStart; 0847 std::pair<int, int> _replModeEnd; 0848 std::pair<int, int> _replLastOutputStart; 0849 std::pair<int, int> _replLastOutputEnd; 0850 int commandCounter = 0; 0851 0852 // ---------------------------- 0853 0854 QBitArray _tabStops; 0855 0856 // selection ------------------- 0857 int _selBegin; // The first location selected. 0858 int _selTopLeft; // TopLeft Location. 0859 int _selBottomRight; // Bottom Right Location. 0860 bool _blockSelectionMode; // Column selection mode 0861 0862 // effective colors and rendition ------------ 0863 CharacterColor _effectiveForeground; // These are derived from 0864 CharacterColor _effectiveBackground; // the cu_* variables above 0865 RenditionFlagsC _effectiveRendition; // to speed up operation 0866 0867 class SavedState 0868 { 0869 public: 0870 SavedState() 0871 : cursorColumn(0) 0872 , cursorLine(0) 0873 , originMode(0) 0874 , rendition({0}) 0875 , foreground(CharacterColor()) 0876 , background(CharacterColor()) 0877 { 0878 } 0879 0880 int cursorColumn; 0881 int cursorLine; 0882 int originMode; 0883 RenditionFlagsC rendition; 0884 CharacterColor foreground; 0885 CharacterColor background; 0886 }; 0887 SavedState _savedState; 0888 0889 // last position where we added a character 0890 int _lastPos; 0891 0892 // used in REP (repeating char) 0893 quint32 _lastDrawnChar; 0894 std::unique_ptr<EscapeSequenceUrlExtractor> _escapeSequenceUrlExtractor; 0895 void toggleUrlInput(); 0896 0897 // Vt102Emulation defined max argument value that can be passed to a Screen function 0898 const int MAX_SCREEN_ARGUMENT = 40960; 0899 0900 /* Graphics */ 0901 void addPlacement(std::unique_ptr<TerminalGraphicsPlacement_t> &u); 0902 std::vector<std::unique_ptr<TerminalGraphicsPlacement_t>> _graphicsPlacements; 0903 void scrollPlacements(int n, qint64 below = INT64_MAX, qint64 above = INT64_MAX); 0904 bool _hasGraphics; 0905 0906 // 0907 bool _ignoreWcWidth; 0908 }; 0909 0910 Q_DECLARE_OPERATORS_FOR_FLAGS(Screen::DecodingOptions) 0911 0912 } 0913 0914 #endif // SCREEN_H