MauiKit Terminal

TerminalCharacterDecoder.h
1/*
2 This file is part of Konsole, an X terminal.
3
4 SPDX-FileCopyrightText: 2006-2008 Robert Knight <robertknight@gmail.com>
5 SPDX-License-Identifier: GPL-2.0-or-later
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA.
21*/
22
23#ifndef TERMINAL_CHARACTER_DECODER_H
24#define TERMINAL_CHARACTER_DECODER_H
25
26#include "Character.h"
27
28#include <QList>
29
30class QTextStream;
31
32namespace Konsole
33{
34
35/**
36 * Base class for terminal character decoders
37 *
38 * The decoder converts lines of terminal characters which consist of a unicode character, foreground
39 * and background colours and other appearance-related properties into text strings.
40 *
41 * Derived classes may produce either plain text with no other colour or appearance information, or
42 * they may produce text which incorporates these additional properties.
43 */
45{
46public:
48 {
49 }
50
51 /** Begin decoding characters. The resulting text is appended to @p output. */
52 virtual void begin(QTextStream *output) = 0;
53 /** End decoding. */
54 virtual void end() = 0;
55
56 /**
57 * Converts a line of terminal characters with associated properties into a text string
58 * and writes the string into an output QTextStream.
59 *
60 * @param characters An array of characters of length @p count.
61 * @param count The number of characters
62 * @param properties Additional properties which affect all characters in the line
63 */
64 virtual void decodeLine(std::span<const Character> characters, LineProperty properties) = 0;
65};
66
67/**
68 * A terminal character decoder which produces plain text, ignoring colours and other appearance-related
69 * properties of the original characters.
70 */
72{
73public:
75
76 /**
77 * Set whether trailing whitespace at the end of lines should be included
78 * in the output.
79 * Defaults to true.
80 */
81 void setTrailingWhitespace(bool enable);
82 /**
83 * Returns whether trailing whitespace at the end of lines is included
84 * in the output.
85 */
86 bool trailingWhitespace() const;
87 /**
88 * Returns of character positions in the output stream
89 * at which new lines where added. Returns an empty if setTrackLinePositions() is false or if
90 * the output device is not a string.
91 */
93 /** Enables recording of character positions at which new lines are added. See linePositions() */
94 void setRecordLinePositions(bool record);
95
96 void begin(QTextStream *output) override;
97 void end() override;
98
99 void decodeLine(std::span<const Character> characters, LineProperty properties) override;
100
101private:
102 QTextStream *_output;
103 bool _includeTrailingWhitespace;
104
105 bool _recordLinePositions;
106 QList<int> _linePositions;
107};
108
109}
110
111#endif
A terminal character decoder which produces plain text, ignoring colours and other appearance-related...
void setTrailingWhitespace(bool enable)
Set whether trailing whitespace at the end of lines should be included in the output.
bool trailingWhitespace() const
Returns whether trailing whitespace at the end of lines is included in the output.
void decodeLine(std::span< const Character > characters, LineProperty properties) override
Converts a line of terminal characters with associated properties into a text string and writes the s...
void setRecordLinePositions(bool record)
Enables recording of character positions at which new lines are added.
void end() override
End decoding.
void begin(QTextStream *output) override
Begin decoding characters.
QList< int > linePositions() const
Returns of character positions in the output stream at which new lines where added.
Base class for terminal character decoders.
virtual void decodeLine(std::span< const Character > characters, LineProperty properties)=0
Converts a line of terminal characters with associated properties into a text string and writes the s...
virtual void end()=0
End decoding.
virtual void begin(QTextStream *output)=0
Begin decoding characters.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:10:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.