13 : line(
std::move(line_))
14 , chunks(1, {color, 0})
20 chunks.emplace_back(
Chunk{color, line.size()});
21 line.append(text.data(), text.size());
26 auto oldN = chunks.size();
27 auto oldPos = line.size();
31 append(chunks, ln.chunks);
32 for (
auto it = chunks.begin() + oldN, et = chunks.end(); it != et; ++it) {
43 if (line.empty())
return result;
44 assert(!chunks.empty());
46 auto it = line.begin(), et = line.end();
47 while ((it != et) && column--) {
50 auto pos = narrow<unsigned>(std::distance(line.begin(), it));
53 assert(it2 != chunks.begin());
54 auto splitColor = it2[-1].color;
57 result.
addChunk(std::string_view{it, et}, splitColor);
58 result.chunks.insert(result.chunks.end(), it2, chunks.end());
65 if (it2[-1].pos == pos) --it2;
66 chunks.erase(it2, chunks.end());
78 assert(i < chunks.size());
79 return chunks[i].color;
84 assert(i < chunks.size());
85 auto pos = chunks[i].pos;
86 auto len = ((i + 1) == chunks.size())
87 ? std::string_view::npos
88 : chunks[i + 1].pos - pos;
89 return std::string_view(line).substr(pos, len);
This class represents a single text line in the console.
ConsoleLine splitAtColumn(unsigned column)
Split this line at a given column number.
void addLine(const ConsoleLine &ln)
Append another line (possibly containing multiple chunks).
std::string_view chunkText(size_t i) const
Get the text for the i-th chunk.
imColor chunkColor(size_t i) const
Get the color for the i-th chunk.
ConsoleLine()=default
Construct empty line.
void addChunk(std::string_view text, imColor color=imColor::TEXT)
Append a chunk with a (different) color.
size_t numChars() const
Get the number of UTF8 characters in this line.
This file implemented 3 utility functions:
auto upper_bound(ForwardRange &&range, const T &value, Compare comp={}, Proj proj={})
size_t size(std::string_view utf8)
uint32_t next(octet_iterator &it)
constexpr auto drop(Range &&range, size_t n)
void strAppend(std::string &result, Ts &&...ts)
std::string_view::size_type pos