@@ -20,8 +20,6 @@ Revision History:
20
20
21
21
#pragma once
22
22
23
- #include < span>
24
-
25
23
#include < til/rle.h>
26
24
27
25
#include " LineRendition.hpp"
@@ -37,6 +35,34 @@ enum class DelimiterClass
37
35
RegularChar
38
36
};
39
37
38
+ struct RowTextIterator
39
+ {
40
+ RowTextIterator (std::span<const wchar_t > chars, std::span<const uint16_t > charOffsets, uint16_t offset) noexcept ;
41
+
42
+ bool operator ==(const RowTextIterator& other) const noexcept ;
43
+ RowTextIterator& operator ++() noexcept ;
44
+ const RowTextIterator& operator *() const noexcept ;
45
+
46
+ std::wstring_view Text () const noexcept ;
47
+ til::CoordType Cols () const noexcept ;
48
+ DbcsAttribute DbcsAttr () const noexcept ;
49
+
50
+ private:
51
+ uint16_t _uncheckedCharOffset (size_t col) const noexcept ;
52
+ bool _uncheckedIsTrailer (size_t col) const noexcept ;
53
+
54
+ // To simplify the detection of wide glyphs, we don't just store the simple character offset as described
55
+ // for _charOffsets. Instead we use the most significant bit to indicate whether any column is the
56
+ // trailing half of a wide glyph. This simplifies many implementation details via _uncheckedIsTrailer.
57
+ static constexpr uint16_t CharOffsetsTrailer = 0x8000 ;
58
+ static constexpr uint16_t CharOffsetsMask = 0x7fff ;
59
+
60
+ std::span<const wchar_t > _chars;
61
+ std::span<const uint16_t > _charOffsets;
62
+ uint16_t _beg;
63
+ uint16_t _end;
64
+ };
65
+
40
66
class ROW final
41
67
{
42
68
public:
@@ -57,16 +83,23 @@ class ROW final
57
83
bool WasDoubleBytePadded () const noexcept ;
58
84
void SetLineRendition (const LineRendition lineRendition) noexcept ;
59
85
LineRendition GetLineRendition () const noexcept ;
86
+ RowTextIterator Begin () const noexcept ;
87
+ RowTextIterator End () const noexcept ;
60
88
61
89
void Reset (const TextAttribute& attr);
62
90
void Resize (wchar_t * charsBuffer, uint16_t * charOffsetsBuffer, uint16_t rowWidth, const TextAttribute& fillAttribute);
63
91
void TransferAttributes (const til::small_rle<TextAttribute, uint16_t , 1 >& attr, til::CoordType newWidth);
64
92
93
+ til::CoordType NavigateToPrevious (til::CoordType column) const noexcept ;
94
+ til::CoordType NavigateToNext (til::CoordType column) const noexcept ;
95
+
65
96
void ClearCell (til::CoordType column);
66
97
OutputCellIterator WriteCells (OutputCellIterator it, til::CoordType columnBegin, std::optional<bool > wrap = std::nullopt, std::optional<til::CoordType> limitRight = std::nullopt);
67
98
bool SetAttrToEnd (til::CoordType columnBegin, TextAttribute attr);
68
99
void ReplaceAttributes (til::CoordType beginIndex, til::CoordType endIndex, const TextAttribute& newAttr);
69
100
void ReplaceCharacters (til::CoordType columnBegin, til::CoordType width, const std::wstring_view& chars);
101
+ til::CoordType Write (til::CoordType columnBegin, til::CoordType columnLimit, std::wstring_view& chars);
102
+ til::CoordType WriteWithOffsets (til::CoordType columnBegin, til::CoordType columnLimit, std::wstring_view& chars, std::span<const uint16_t >& charOffsetsPtr);
70
103
71
104
const til::small_rle<TextAttribute, uint16_t , 1 >& Attributes () const noexcept ;
72
105
TextAttribute GetAttrByColumn (til::CoordType column) const ;
@@ -89,6 +122,30 @@ class ROW final
89
122
#endif
90
123
91
124
private:
125
+ // WriteHelper exists because other forms of abstracting this functionality away (like templates with lambdas)
126
+ // where only very poorly optimized by MSVC as it failed to inline the templates.
127
+ struct WriteHelper
128
+ {
129
+ explicit WriteHelper (ROW& row, til::CoordType columnBegin, til::CoordType columnLimit, const std::wstring_view& chars) noexcept ;
130
+ bool IsValid () const noexcept ;
131
+ void ReplaceCharacters (til::CoordType width) noexcept ;
132
+ void Write () noexcept ;
133
+ void WriteWithOffsets (const std::span<const uint16_t >& charOffsets) noexcept ;
134
+ void Finish ();
135
+
136
+ ROW& row;
137
+ const std::wstring_view& chars;
138
+ uint16_t colBeg;
139
+ uint16_t colLimit;
140
+ uint16_t chExtBeg;
141
+ uint16_t colExtBeg;
142
+ uint16_t leadingSpaces;
143
+ uint16_t chBeg;
144
+ uint16_t colEnd;
145
+ uint16_t colExtEnd;
146
+ size_t charsConsumed;
147
+ };
148
+
92
149
// To simplify the detection of wide glyphs, we don't just store the simple character offset as described
93
150
// for _charOffsets. Instead we use the most significant bit to indicate whether any column is the
94
151
// trailing half of a wide glyph. This simplifies many implementation details via _uncheckedIsTrailer.
@@ -102,13 +159,16 @@ class ROW final
102
159
template <typename T>
103
160
constexpr uint16_t _clampedColumnInclusive (T v) const noexcept ;
104
161
162
+ uint16_t _adjustBackward (uint16_t column) const noexcept ;
163
+ uint16_t _adjustForward (uint16_t column) const noexcept ;
164
+
105
165
wchar_t _uncheckedChar (size_t off) const noexcept ;
106
166
uint16_t _charSize () const noexcept ;
107
167
uint16_t _uncheckedCharOffset (size_t col) const noexcept ;
108
168
bool _uncheckedIsTrailer (size_t col) const noexcept ;
109
169
110
170
void _init () noexcept ;
111
- void _resizeChars (uint16_t colExtEnd, uint16_t chExtBeg, uint16_t chExtEnd , size_t chExtEndNew);
171
+ void _resizeChars (uint16_t colExtEnd, uint16_t chExtBeg, uint16_t chExtEndOld , size_t chExtEndNew);
112
172
113
173
// These fields are a bit "wasteful", but it makes all this a bit more robust against
114
174
// programming errors during initial development (which is when this comment was written).
0 commit comments