libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
screen.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <cstdint>
12#include <promeki/core/list.h>
13#include <promeki/core/char.h>
15#include <promeki/tui/style.h>
17
19
27struct TuiCell {
28 Char ch = Char(U' ');
29 TuiStyle style = TuiStyle(Color::White, Color::Black);
30
32 bool operator==(const TuiCell &other) const {
33 return ch == other.ch && style == other.style;
34 }
36 bool operator!=(const TuiCell &other) const {
37 return !(*this == other);
38 }
39};
40
60class TuiScreen {
61 public:
64
67
73 void resize(int cols, int rows);
74
76 int cols() const { return _cols; }
77
79 int rows() const { return _rows; }
80
87 void setCell(int x, int y, const TuiCell &cell);
88
95 TuiCell cell(int x, int y) const;
96
102 void clear(const Color &fg = Color::White, const Color &bg = Color::Black);
103
108 void flush(AnsiStream &stream);
109
114
125 void setColorMode(Terminal::ColorSupport mode) { _colorMode = mode; }
126
131 Terminal::ColorSupport colorMode() const { return _colorMode; }
132
133 private:
134 int _cols = 0;
135 int _rows = 0;
136 List<TuiCell> _front;
137 List<TuiCell> _back;
138 bool _fullRedraw = true;
140
141 int index(int x, int y) const { return y * _cols + x; }
142 bool inBounds(int x, int y) const {
143 return x >= 0 && x < _cols && y >= 0 && y < _rows;
144 }
145
146 void emitCell(AnsiStream &stream, const TuiCell &cell,
147 int &cursorX, int &cursorY, int x, int y,
149};
150
ANSI escape code writer backed by an IODevice. Writes ANSI escape sequences and raw text to an IODevi...
Definition ansistream.h:27
Unicode-aware character class wrapping a single codepoint.
Definition char.h:23
General-purpose RGBA color.
Definition color.h:24
Dynamic array container wrapping std::vector.
Definition list.h:40
ColorSupport
Describes the color capability level of the terminal.
Definition terminal.h:54
@ TrueColor
24-bit true color support.
Definition terminal.h:61
Double-buffered character cell grid for TUI rendering.
Definition screen.h:60
int cols() const
Returns the number of columns.
Definition screen.h:76
TuiScreen()
Constructs an empty screen with no buffers.
void resize(int cols, int rows)
Resizes both buffers to the given dimensions.
TuiCell cell(int x, int y) const
Returns the cell at the given position in the back buffer.
void setCell(int x, int y, const TuiCell &cell)
Sets a cell in the back buffer.
void clear(const Color &fg=Color::White, const Color &bg=Color::Black)
Clears the back buffer with blank cells.
void invalidate()
Forces a full redraw on the next flush.
Terminal::ColorSupport colorMode() const
Returns the current color mode.
Definition screen.h:131
~TuiScreen()
Destructor.
void setColorMode(Terminal::ColorSupport mode)
Sets the color mode used when emitting colors during flush.
Definition screen.h:125
int rows() const
Returns the number of rows.
Definition screen.h:79
void flush(AnsiStream &stream)
Diffs front vs back buffer and emits minimal ANSI updates.
Visual properties of a TUI cell (everything except the character).
Definition style.h:29
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
A single cell in the TUI screen buffer.
Definition screen.h:27
Char ch
The Unicode character in this cell.
Definition screen.h:28
bool operator==(const TuiCell &other) const
Returns true if both character and style match.
Definition screen.h:32
TuiStyle style
Visual style (colors and attributes).
Definition screen.h:29
bool operator!=(const TuiCell &other) const
Returns true if character or style differ.
Definition screen.h:36