Updating Doxygen styling and Licenses
[baulk.git] / src / Widgets / BaulkTerm / qtermwidget / TerminalCharacterDecoder.h
blobb42ef781723b3121c1bdce0df18409e723a8f72a
1 // This file is part of Konsole, an X terminal.
2 //
3 // Copyright (C) 2006-7 by Robert Knight <robertknight@gmail.com>
4 //
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>
7 //
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"
26 class QTextStream;
28 namespace Konsole
31 /*!
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
42 public:
43 virtual ~TerminalCharacterDecoder() {}
45 /*! Begin decoding characters. The resulting text is appended to @p output. */
46 virtual void begin(QTextStream* output) = 0;
47 /*! End decoding. */
48 virtual void end() = 0;
50 /*!
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,
59 int count,
60 LineProperty properties) = 0;
63 /*!
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
69 public:
70 PlainTextDecoder();
72 /*!
73 * Set whether trailing whitespace at the end of lines should be included
74 * in the output.
75 * Defaults to true.
77 void setTrailingWhitespace(bool enable);
78 /*!
79 * Returns whether trailing whitespace at the end of lines is included
80 * in the output.
82 bool trailingWhitespace() const;
84 virtual void begin(QTextStream* output);
85 virtual void end();
87 virtual void decodeLine(const Character* const characters,
88 int count,
89 LineProperty properties);
92 private:
93 QTextStream* _output;
94 bool _includeTrailingWhitespace;
97 /*!
98 * A terminal character decoder which produces pretty HTML markup
100 class HTMLDecoder : public TerminalCharacterDecoder
102 public:
103 /*!
104 * Constructs an HTML decoder using a default black-on-white color scheme.
106 HTMLDecoder();
109 * Sets the colour table which the decoder uses to produce the HTML colour codes in its
110 * output
112 void setColorTable( const ColorEntry* table );
114 virtual void decodeLine(const Character* const characters,
115 int count,
116 LineProperty properties);
118 virtual void begin(QTextStream* output);
119 virtual void end();
121 private:
122 void openSpan(QString& text , const QString& style);
123 void closeSpan(QString& text);
125 QTextStream* _output;
126 const ColorEntry* _colorTable;
127 bool _innerSpanOpen;
128 quint8 _lastRendition;
129 CharacterColor _lastForeColor;
130 CharacterColor _lastBackColor;
136 #endif