openMSX
ConsoleLine.hh
Go to the documentation of this file.
1#ifndef CONSOLE_LINE_HH
2#define CONSOLE_LINE_HH
3
4#include "ImGuiUtils.hh"
5
6#include <cstdint>
7#include <string>
8#include <string_view>
9#include <vector>
10
11namespace openmsx {
12
16{
17public:
19 ConsoleLine() = default;
20
22 void clear() {
23 line.clear();
24 chunks.clear();
25 }
26
28 explicit ConsoleLine(std::string line, imColor color = imColor::TEXT);
29
31 void addChunk(std::string_view text, imColor color = imColor::TEXT);
32
34 void addLine(const ConsoleLine& ln);
35
39 ConsoleLine splitAtColumn(unsigned column);
40
43 [[nodiscard]] size_t numChars() const;
45 [[nodiscard]] const std::string& str() const { return line; }
46
49 [[nodiscard]] size_t numChunks() const { return chunks.size(); }
51 [[nodiscard]] imColor chunkColor(size_t i) const;
53 [[nodiscard]] std::string_view chunkText(size_t i) const;
54
55 [[nodiscard]] const auto& getChunks() const { return chunks; }
56
57public:
58 struct Chunk {
60 std::string_view::size_type pos;
61 };
62
63private:
64 std::string line;
65 std::vector<Chunk> chunks;
66};
67
68} // namespace openmsx
69
70#endif
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.
const std::string & str() const
Get the total string, ignoring color differences.
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.
void clear()
Reinitialize to an empty line.
const auto & getChunks() const
size_t numChars() const
Get the number of UTF8 characters in this line.
size_t numChunks() const
Get the number of different chunks.
This file implemented 3 utility functions:
Definition Autofire.cc:11
std::string_view::size_type pos