1 // This file is part of Konsole, an X terminal.
3 // Copyright (C) 2006-7 by Robert Knight <robertknight@gmail.com>
5 // Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
6 // Forked for Baulk - Copyright (C) 2008-2009 - Jacob Alexander <haata at users.sf.net>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // any later version, including version 3 of the License.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef TERMINAL_CHARACTER_DECODER_H
22 #define TERMINAL_CHARACTER_DECODER_H
24 #include "Character.h"
32 * Base class for terminal character decoders
34 * The decoder converts lines of terminal characters which consist of a unicode character, foreground
35 * and background colours and other appearance-related properties into text strings.
37 * Derived classes may produce either plain text with no other colour or appearance information, or
38 * they may produce text which incorporates these additional properties.
40 class TerminalCharacterDecoder
43 virtual ~TerminalCharacterDecoder() {}
45 /*! Begin decoding characters. The resulting text is appended to @p output. */
46 virtual void begin(QTextStream
* output
) = 0;
48 virtual void end() = 0;
51 * Converts a line of terminal characters with associated properties into a text string
52 * and writes the string into an output QTextStream.
54 * @param characters An array of characters of length @p count.
55 * @param properties Additional properties which affect all characters in the line
56 * @param output The output stream which receives the decoded text
58 virtual void decodeLine(const Character
* const characters
,
60 LineProperty properties
) = 0;
64 * A terminal character decoder which produces plain text, ignoring colours and other appearance-related
65 * properties of the original characters.
67 class PlainTextDecoder
: public TerminalCharacterDecoder
73 * Set whether trailing whitespace at the end of lines should be included
77 void setTrailingWhitespace(bool enable
);
79 * Returns whether trailing whitespace at the end of lines is included
82 bool trailingWhitespace() const;
84 virtual void begin(QTextStream
* output
);
87 virtual void decodeLine(const Character
* const characters
,
89 LineProperty properties
);
94 bool _includeTrailingWhitespace
;
98 * A terminal character decoder which produces pretty HTML markup
100 class HTMLDecoder
: public TerminalCharacterDecoder
104 * Constructs an HTML decoder using a default black-on-white color scheme.
109 * Sets the colour table which the decoder uses to produce the HTML colour codes in its
112 void setColorTable( const ColorEntry
* table
);
114 virtual void decodeLine(const Character
* const characters
,
116 LineProperty properties
);
118 virtual void begin(QTextStream
* output
);
122 void openSpan(QString
& text
, const QString
& style
);
123 void closeSpan(QString
& text
);
125 QTextStream
* _output
;
126 const ColorEntry
* _colorTable
;
128 quint8 _lastRendition
;
129 CharacterColor _lastForeColor
;
130 CharacterColor _lastBackColor
;