libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
screen.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <cstdint>
11#include <promeki/namespace.h>
12#include <promeki/list.h>
13#include <promeki/char.h>
14#include <promeki/terminal.h>
15#include <promeki/tui/style.h>
16#include <promeki/ansistream.h>
17
18PROMEKI_NAMESPACE_BEGIN
19
33struct TuiCell {
34 Char ch = Char(U' ');
35 TuiStyle style = TuiStyle(Color::White, Color::Black);
36
38 bool operator==(const TuiCell &other) const { return ch == other.ch && style == other.style; }
40 bool operator!=(const TuiCell &other) const { return !(*this == other); }
41};
42
68class TuiScreen {
69 public:
72
75
81 void resize(int cols, int rows);
82
84 int cols() const { return _cols; }
85
87 int rows() const { return _rows; }
88
95 void setCell(int x, int y, const TuiCell &cell);
96
103 TuiCell cell(int x, int y) const;
104
110 void clear(const Color &fg = Color::White, const Color &bg = Color::Black);
111
116 void flush(AnsiStream &stream);
117
122
133 void setColorMode(Terminal::ColorSupport mode) { _colorMode = mode; }
134
139 Terminal::ColorSupport colorMode() const { return _colorMode; }
140
141 private:
142 int _cols = 0;
143 int _rows = 0;
144 List<TuiCell> _front;
145 List<TuiCell> _back;
146 bool _fullRedraw = true;
147 Terminal::ColorSupport _colorMode = Terminal::TrueColor;
148
149 int index(int x, int y) const { return y * _cols + x; }
150 bool inBounds(int x, int y) const { return x >= 0 && x < _cols && y >= 0 && y < _rows; }
151
152 void emitCell(AnsiStream &stream, const TuiCell &cell, int &cursorX, int &cursorY, int x, int y,
153 Color &lastFg, Color &lastBg, uint8_t &lastStyle);
154};
155
156PROMEKI_NAMESPACE_END
Double-buffered character cell grid for TUI rendering.
Definition screen.h:68
int cols() const
Returns the number of columns.
Definition screen.h:84
int rows() const
Returns the number of rows.
Definition screen.h:87
TuiScreen()
Constructs an empty screen with no buffers.
void setCell(int x, int y, const TuiCell &cell)
Sets a cell in the back buffer.
~TuiScreen()
Destructor.
void resize(int cols, int rows)
Resizes both buffers to the given dimensions.
void flush(AnsiStream &stream)
Diffs front vs back buffer and emits minimal ANSI updates.
Terminal::ColorSupport colorMode() const
Returns the current color mode.
Definition screen.h:139
void setColorMode(Terminal::ColorSupport mode)
Sets the color mode used when emitting colors during flush.
Definition screen.h:133
TuiCell cell(int x, int y) const
Returns the cell at the given position in the back buffer.
void invalidate()
Forces a full redraw on the next flush.
void clear(const Color &fg=Color::White, const Color &bg=Color::Black)
Clears the back buffer with blank cells.
Visual properties of a TUI cell (everything except the character).
Definition style.h:35
A single cell in the TUI screen buffer.
Definition screen.h:33
bool operator!=(const TuiCell &other) const
Returns true if character or style differ.
Definition screen.h:40
bool operator==(const TuiCell &other) const
Returns true if both character and style match.
Definition screen.h:38
TuiStyle style
Visual style (colors and attributes).
Definition screen.h:35
Char ch
The Unicode character in this cell.
Definition screen.h:34