File indexing completed on 2024-04-28 05:31:41
0001 /* 0002 KSysGuard, the KDE System Guard 0003 0004 SPDX-FileCopyrightText: 2008 John Tapsell <tapsell@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 0008 */ 0009 0010 #ifndef _KTextEditVT_h_ 0011 #define _KTextEditVT_h_ 0012 0013 #include <QTextEdit> 0014 0015 #include "processui_export.h" 0016 0017 /* 0018 * \class KTextEditVT 0019 * \brief The KTextEditVT class provides a widget that is used to edit and display 0020 * both plain and rich text with the additional function of being able to 0021 * programmatically append VT100 formatted text. For example to display the output 0022 * from console programs. 0023 * 0024 * This class can be used to display the output of VT100 formatted text with 0025 * ANSI escape code - for example output from the command 'ls --color'. 0026 * 0027 * Only a very limited number of ansi escapes sequences will have an affect. Unrecognised 0028 * ansi escape sequences will be ignored and not displayed. Patches are welcome to support 0029 * more of the sequences. 0030 * 0031 * This output can be then be inserted at the current cursor position by calling 0032 * insertVTText(string); 0033 * 0034 * For example: 0035 * 0036 * \code 0037 * insertVTText(QString("Hi") + QChar(08) + "ello"); 0038 * \endcode 0039 * 0040 * will insert the text "Hello" at the current character position. 0041 * (Character 08 is the literal backspace character. Treated as equivalent to character 127) 0042 */ 0043 class PROCESSUI_EXPORT KTextEditVT : public QTextEdit 0044 { 0045 Q_OBJECT 0046 Q_PROPERTY(bool parseAnsiEscapeCodes READ parseAnsiEscapeCodes WRITE setParseAnsiEscapeCodes) 0047 0048 public: 0049 explicit KTextEditVT(QWidget *parent); 0050 0051 /** Whether to parse ANSI display code. If turned off the escape sequence will be shown literally. */ 0052 bool parseAnsiEscapeCodes() const; 0053 0054 public Q_SLOTS: 0055 /** Set whether to parse ANSI display code. If turned off the escape sequence will be shown literally. */ 0056 void setParseAnsiEscapeCodes(bool displayall); 0057 /** Insert the given string at the current position based on the current state. 0058 * This is interpreted in a VT100 encoding. Backspace and delete will delete the previous character, 0059 * escape sequences can move the cursor and set the current color etc. 0060 * 0061 * This just calls insertVTChar for each character in the string 0062 */ 0063 void insertVTText(const QByteArray &string); 0064 /** Insert the given string at the current position based on the current state. 0065 * This is interpreted in a VT100 encoding. Backspace and delete will delete the previous character, 0066 * escape sequences can move the cursor and set the current color etc. 0067 * 0068 * This just calls insertVTChar for each character in the string 0069 */ 0070 void insertVTText(const QString &string); 0071 0072 /** Insert the given character at the current position based on the current state. 0073 * This is interpreted in a VT100 encoding. Backspace and delete will delete the previous character, 0074 * escape sequences can move the cursor and set the current color etc. 0075 */ 0076 void insertVTChar(const QChar &c); 0077 0078 private: 0079 bool mParseAnsi; 0080 0081 bool escape_sequence; 0082 bool escape_CSI; 0083 bool escape_OSC; 0084 int escape_number1; 0085 int escape_number2; 0086 bool escape_number_separator; 0087 QChar escape_code; 0088 }; 0089 0090 #endif