~larryprice/acolyterm/release-0.1

« back to all changes in this revision

Viewing changes to src/plugin/konsole/TerminalCharacterDecoder.h

  • Committer: Larry Price
  • Date: 2016-06-15 14:47:59 UTC
  • Revision ID: larry.price@canonical.com-20160615144759-6wopn0gxwgta3x1n
Updating QMLTermWidget and removing unnecessary konsole codebase

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of Konsole, an X terminal.
3
 
 
4
 
    Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
5
 
 
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.
10
 
 
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.
15
 
 
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.
20
 
*/
21
 
 
22
 
#ifndef TERMINAL_CHARACTER_DECODER_H
23
 
#define TERMINAL_CHARACTER_DECODER_H
24
 
 
25
 
#include "Character.h"
26
 
 
27
 
#include <QList>
28
 
 
29
 
class QTextStream;
30
 
 
31
 
 
32
 
 
33
 
/**
34
 
 * Base class for terminal character decoders
35
 
 *
36
 
 * The decoder converts lines of terminal characters which consist of a unicode character, foreground
37
 
 * and background colours and other appearance-related properties into text strings.
38
 
 *
39
 
 * Derived classes may produce either plain text with no other colour or appearance information, or
40
 
 * they may produce text which incorporates these additional properties.
41
 
 */
42
 
class TerminalCharacterDecoder
43
 
{
44
 
public:
45
 
    virtual ~TerminalCharacterDecoder() {}
46
 
 
47
 
    /** Begin decoding characters.  The resulting text is appended to @p output. */
48
 
    virtual void begin(QTextStream* output) = 0;
49
 
    /** End decoding. */
50
 
    virtual void end() = 0;
51
 
 
52
 
    /**
53
 
     * Converts a line of terminal characters with associated properties into a text string
54
 
     * and writes the string into an output QTextStream.
55
 
     *
56
 
     * @param characters An array of characters of length @p count.
57
 
     * @param count The number of characters
58
 
     * @param properties Additional properties which affect all characters in the line
59
 
     */
60
 
    virtual void decodeLine(const Character* const characters,
61
 
                            int count,
62
 
                            LineProperty properties) = 0;
63
 
};
64
 
 
65
 
/**
66
 
 * A terminal character decoder which produces plain text, ignoring colours and other appearance-related
67
 
 * properties of the original characters.
68
 
 */
69
 
class PlainTextDecoder : public TerminalCharacterDecoder
70
 
{
71
 
public:
72
 
    PlainTextDecoder();
73
 
 
74
 
    /**
75
 
     * Set whether trailing whitespace at the end of lines should be included
76
 
     * in the output.
77
 
     * Defaults to true.
78
 
     */
79
 
    void setTrailingWhitespace(bool enable);
80
 
    /**
81
 
     * Returns whether trailing whitespace at the end of lines is included
82
 
     * in the output.
83
 
     */
84
 
    bool trailingWhitespace() const;
85
 
    /**
86
 
     * Returns of character positions in the output stream
87
 
     * at which new lines where added.  Returns an empty if setTrackLinePositions() is false or if
88
 
     * the output device is not a string.
89
 
     */
90
 
    QList<int> linePositions() const;
91
 
    /** Enables recording of character positions at which new lines are added.  See linePositions() */
92
 
    void setRecordLinePositions(bool record);
93
 
 
94
 
    virtual void begin(QTextStream* output);
95
 
    virtual void end();
96
 
 
97
 
    virtual void decodeLine(const Character* const characters,
98
 
                            int count,
99
 
                            LineProperty properties);
100
 
 
101
 
 
102
 
private:
103
 
    QTextStream* _output;
104
 
    bool _includeTrailingWhitespace;
105
 
 
106
 
    bool _recordLinePositions;
107
 
    QList<int> _linePositions;
108
 
};
109
 
 
110
 
/**
111
 
 * A terminal character decoder which produces pretty HTML markup
112
 
 */
113
 
class HTMLDecoder : public TerminalCharacterDecoder
114
 
{
115
 
public:
116
 
    /**
117
 
     * Constructs an HTML decoder using a default black-on-white color scheme.
118
 
     */
119
 
    HTMLDecoder();
120
 
 
121
 
    /**
122
 
     * Sets the colour table which the decoder uses to produce the HTML colour codes in its
123
 
     * output
124
 
     */
125
 
    void setColorTable( const ColorEntry* table );
126
 
 
127
 
    virtual void decodeLine(const Character* const characters,
128
 
                            int count,
129
 
                            LineProperty properties);
130
 
 
131
 
    virtual void begin(QTextStream* output);
132
 
    virtual void end();
133
 
 
134
 
private:
135
 
    void openSpan(QString& text , const QString& style);
136
 
    void closeSpan(QString& text);
137
 
 
138
 
    QTextStream* _output;
139
 
    const ColorEntry* _colorTable;
140
 
    bool _innerSpanOpen;
141
 
    quint8 _lastRendition;
142
 
    CharacterColor _lastForeColor;
143
 
    CharacterColor _lastBackColor;
144
 
 
145
 
};
146
 
 
147
 
 
148
 
#endif