Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / konsole / src / TerminalCharacterDecoder.h
blob934ff110fe7f13ee71cc75a8a438058aa8888192
1 /*
2 This file is part of Konsole, an X terminal.
4 Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
22 #ifndef TERMINAL_CHARACTER_DECODER_H
23 #define TERMINAL_CHARACTER_DECODER_H
25 #include "Character.h"
27 #include <QList>
29 class QTextStream;
31 namespace Konsole
34 /**
35 * Base class for terminal character decoders
37 * The decoder converts lines of terminal characters which consist of a unicode character, foreground
38 * and background colours and other appearance-related properties into text strings.
40 * Derived classes may produce either plain text with no other colour or appearance information, or
41 * they may produce text which incorporates these additional properties.
43 class TerminalCharacterDecoder
45 public:
46 virtual ~TerminalCharacterDecoder() {}
48 /** Begin decoding characters. The resulting text is appended to @p output. */
49 virtual void begin(QTextStream* output) = 0;
50 /** End decoding. */
51 virtual void end() = 0;
53 /**
54 * Converts a line of terminal characters with associated properties into a text string
55 * and writes the string into an output QTextStream.
57 * @param characters An array of characters of length @p count.
58 * @param properties Additional properties which affect all characters in the line
59 * @param output The output stream which receives the decoded text
61 virtual void decodeLine(const Character* const characters,
62 int count,
63 LineProperty properties) = 0;
66 /**
67 * A terminal character decoder which produces plain text, ignoring colours and other appearance-related
68 * properties of the original characters.
70 class PlainTextDecoder : public TerminalCharacterDecoder
72 public:
73 PlainTextDecoder();
75 /**
76 * Set whether trailing whitespace at the end of lines should be included
77 * in the output.
78 * Defaults to true.
80 void setTrailingWhitespace(bool enable);
81 /**
82 * Returns whether trailing whitespace at the end of lines is included
83 * in the output.
85 bool trailingWhitespace() const;
86 /**
87 * Returns of character positions in the output stream
88 * at which new lines where added. Returns an empty if setTrackLinePositions() is false or if
89 * the output device is not a string.
91 QList<int> linePositions() const;
92 /** Enables recording of character positions at which new lines are added. See linePositions() */
93 void setRecordLinePositions(bool record);
95 virtual void begin(QTextStream* output);
96 virtual void end();
98 virtual void decodeLine(const Character* const characters,
99 int count,
100 LineProperty properties);
103 private:
104 QTextStream* _output;
105 bool _includeTrailingWhitespace;
107 bool _recordLinePositions;
108 QList<int> _linePositions;
112 * A terminal character decoder which produces pretty HTML markup
114 class HTMLDecoder : public TerminalCharacterDecoder
116 public:
117 /**
118 * Constructs an HTML decoder using a default black-on-white color scheme.
120 HTMLDecoder();
123 * Sets the colour table which the decoder uses to produce the HTML colour codes in its
124 * output
126 void setColorTable( const ColorEntry* table );
128 virtual void decodeLine(const Character* const characters,
129 int count,
130 LineProperty properties);
132 virtual void begin(QTextStream* output);
133 virtual void end();
135 private:
136 void openSpan(QString& text , const QString& style);
137 void closeSpan(QString& text);
139 QTextStream* _output;
140 const ColorEntry* _colorTable;
141 bool _innerSpanOpen;
142 quint8 _lastRendition;
143 CharacterColor _lastForeColor;
144 CharacterColor _lastBackColor;
150 #endif