Changeset View
Changeset View
Standalone View
Standalone View
src/TerminalCharacterDecoder.cpp
Show All 20 Lines | |||||
21 | 21 | | |||
22 | // Own | 22 | // Own | ||
23 | #include "TerminalCharacterDecoder.h" | 23 | #include "TerminalCharacterDecoder.h" | ||
24 | 24 | | |||
25 | // Qt | 25 | // Qt | ||
26 | #include <QTextStream> | 26 | #include <QTextStream> | ||
27 | 27 | | |||
28 | // Konsole | 28 | // Konsole | ||
29 | #include "konsole_wcwidth.h" | | |||
30 | #include "ExtendedCharTable.h" | 29 | #include "ExtendedCharTable.h" | ||
31 | #include "ColorScheme.h" | 30 | #include "ColorScheme.h" | ||
32 | 31 | | |||
33 | using namespace Konsole; | 32 | using namespace Konsole; | ||
34 | PlainTextDecoder::PlainTextDecoder() | 33 | PlainTextDecoder::PlainTextDecoder() | ||
35 | : _output(nullptr) | 34 | : _output(nullptr) | ||
36 | , _includeLeadingWhitespace(true) | 35 | , _includeLeadingWhitespace(true) | ||
37 | , _includeTrailingWhitespace(true) | 36 | , _includeTrailingWhitespace(true) | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 125 | for (int i = count - 1 ; i >= start ; i--) { | |||
133 | } | 132 | } | ||
134 | } | 133 | } | ||
135 | 134 | | |||
136 | for (int i = start; i < outputCount;) { | 135 | for (int i = start; i < outputCount;) { | ||
137 | if ((characters[i].rendition & RE_EXTENDED_CHAR) != 0) { | 136 | if ((characters[i].rendition & RE_EXTENDED_CHAR) != 0) { | ||
138 | ushort extendedCharLength = 0; | 137 | ushort extendedCharLength = 0; | ||
139 | const uint* chars = ExtendedCharTable::instance.lookupExtendedChar(characters[i].character, extendedCharLength); | 138 | const uint* chars = ExtendedCharTable::instance.lookupExtendedChar(characters[i].character, extendedCharLength); | ||
140 | if (chars != nullptr) { | 139 | if (chars != nullptr) { | ||
141 | const QString s = QString::fromUcs4(chars, extendedCharLength); | 140 | plainText.append(QString::fromUcs4(chars, extendedCharLength)); | ||
142 | plainText.append(s); | 141 | i += qMax(1, Character::stringWidth(chars, extendedCharLength)); | ||
143 | i += qMax(1, string_width(s)); | | |||
144 | } else { | 142 | } else { | ||
145 | ++i; | 143 | ++i; | ||
146 | } | 144 | } | ||
147 | } else { | 145 | } else { | ||
148 | // All characters which appear before the last real character are | 146 | // All characters which appear before the last real character are | ||
149 | // seen as real characters, even when they are technically marked as | 147 | // seen as real characters, even when they are technically marked as | ||
150 | // non-real. | 148 | // non-real. | ||
151 | // | 149 | // | ||
152 | // This feels tricky, but otherwise leading "whitespaces" may be | 150 | // This feels tricky, but otherwise leading "whitespaces" may be | ||
153 | // lost in some situation. One typical example is copying the result | 151 | // lost in some situation. One typical example is copying the result | ||
154 | // of `dialog --infobox "qwe" 10 10` . | 152 | // of `dialog --infobox "qwe" 10 10` . | ||
155 | if (characters[i].isRealCharacter || i <= realCharacterGuard) { | 153 | if (characters[i].isRealCharacter || i <= realCharacterGuard) { | ||
156 | plainText.append(QString::fromUcs4(&characters[i].character, 1)); | 154 | plainText.append(QString::fromUcs4(&characters[i].character, 1)); | ||
157 | i += qMax(1, konsole_wcwidth(characters[i].character)); | 155 | i += qMax(1, characters[i].width()); | ||
158 | } else { | 156 | } else { | ||
159 | ++i; // should we 'break' directly here? | 157 | ++i; // should we 'break' directly here? | ||
160 | } | 158 | } | ||
161 | } | 159 | } | ||
162 | } | 160 | } | ||
163 | *_output << plainText; | 161 | *_output << plainText; | ||
164 | } | 162 | } | ||
165 | 163 | | |||
▲ Show 20 Lines • Show All 143 Lines • Show Last 20 Lines |