NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
screen.hpp
浏览该文件的文档.
1#ifndef NEFORCE_TUI_SCREEN_HPP__
2#define NEFORCE_TUI_SCREEN_HPP__
3
8
10NEFORCE_BEGIN_NAMESPACE__
11NEFORCE_BEGIN_TUI__
12
17
19class screen;
21
25struct dimensions {
26 int dimx;
27 int dimy;
28};
29
33struct cell {
34 string character;
35 _NEFORCE color foreground;
36 _NEFORCE color background;
37 bool bold : 1;
38 bool dim : 1;
39 bool italic : 1;
40 bool inverted : 1;
41 bool underlined : 1;
43 bool blink : 1;
44 bool strikethrough : 1;
45 bool automerge : 1;
47
48 cell() noexcept :
49 bold(false),
50 dim(false),
51 italic(false),
52 inverted(false),
53 underlined(false),
54 underlined_double(false),
55 blink(false),
56 strikethrough(false),
57 automerge(false) {}
58
62 void reset() noexcept {
64 hyperlink = 0;
65 foreground = _NEFORCE color{};
66 background = _NEFORCE color{};
67 character.clear();
68 }
69
75 NEFORCE_NODISCARD bool visually_equal(const cell& other) const noexcept {
76 return character == other.character && bold == other.bold && dim == other.dim && italic == other.italic &&
77 inverted == other.inverted && underlined == other.underlined &&
78 underlined_double == other.underlined_double && blink == other.blink &&
79 strikethrough == other.strikethrough && hyperlink == other.hyperlink && foreground == other.foreground &&
80 background == other.background;
81 }
82};
83
87struct cursor {
91 enum class shape : uint8_t {
92 Hidden,
93 BlockBlinking,
94 Block,
95 UnderlineBlinking,
96 Underline,
97 BarBlinking,
98 Bar,
99 };
100
101 int x = 0;
102 int y = 0;
104};
105
111class NEFORCE_API surface {
112public:
118 surface(int dimx, int dimy);
119
120 virtual ~surface() = default;
121
126 NEFORCE_NODISCARD int dimx() const noexcept { return dimx_; }
127
132 NEFORCE_NODISCARD int dimy() const noexcept { return dimy_; }
133
140 NEFORCE_NODISCARD string& at(int x, int y);
141
148 NEFORCE_NODISCARD cell& cell_at(int x, int y);
149
156 NEFORCE_NODISCARD cell& fast_cell_at(int x, int y) noexcept { return cells_[static_cast<size_t>(y) * dimx_ + x]; }
157
161 virtual void clear();
162
163protected:
164 int dimx_;
165 int dimy_;
166 vector<cell> cells_;
167};
168
174// NOLINTNEXTLINE(bugprone-exception-escape)
175class NEFORCE_API screen final : public surface {
176public:
182 screen(int dimx, int dimy);
183
189 void resize(int dimx, int dimy);
190
195 NEFORCE_NODISCARD const tui::cursor& cursor() const noexcept { return cursor_; }
196
201 void set_cursor(const tui::cursor& c) noexcept { cursor_ = c; }
202
208 uint8_t register_hyperlink(const string& link);
209
215 NEFORCE_NODISCARD const string& hyperlink(uint8_t id) const;
216
225 NEFORCE_NODISCARD string to_string(const screen& prev) const;
226
233 NEFORCE_NODISCARD string to_plaintext() const;
234
239 void reset_position(bool clear = false);
240
244 void clear() override;
245
246private:
247 tui::cursor cursor_;
248 vector<string> hyperlinks_;
249
250 void update_cell_style(string& ss, const cell& prev, const cell& next) const;
251};
252 // TUI
254
255NEFORCE_END_TUI__
256NEFORCE_END_NAMESPACE__
257#endif // NEFORCE_TUI_SCREEN_HPP__
uint8_t register_hyperlink(const string &link)
注册超链接,返回句柄
const string & hyperlink(uint8_t id) const
根据句柄查找超链接
screen(int dimx, int dimy)
构造函数
string to_plaintext() const
导出为纯文本(无 ANSI 转义)
string to_string(const screen &prev) const
生成 ANSI 转义序列
void set_cursor(const tui::cursor &c) noexcept
设置光标
void reset_position(bool clear=false)
重置光标位置跟踪
void resize(int dimx, int dimy)
调整尺寸
void clear() override
清空所有状态
const tui::cursor & cursor() const noexcept
获取光标
cell & fast_cell_at(int x, int y) noexcept
无边界检查的 cell 访问
cell & cell_at(int x, int y)
有边界检查的 cell 访问
int dimx() const noexcept
获取宽度
string & at(int x, int y)
有边界检查的字符访问
int dimy() const noexcept
获取高度
surface(int dimx, int dimy)
构造函数
virtual void clear()
清空所有 cell
动态大小数组容器
颜色类
unsigned char uint8_t
8位无符号整数类型
constexpr Iterator prev(Iterator iter, iter_difference_t< Iterator > n=1)
获取迭代器的前一个位置
constexpr Iterator next(Iterator iter, iter_difference_t< Iterator > n=1)
获取迭代器的后一个位置
decorator color(color c)
前景色装饰器
像素/字符单元
bool underlined_double
双下划线
bool visually_equal(const cell &other) const noexcept
比较两个 cell 的视觉内容
_NEFORCE color foreground
前景色
uint8_t hyperlink
超链接 ID(0 表示无链接)
void reset() noexcept
重置所有样式为默认值
bool underlined
单下划线
_NEFORCE color background
背景色
bool strikethrough
删除线
bool automerge
相邻同内容自动融合
string character
显示的字符
shape
光标形状枚举