libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
terminal.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <functional>
12#include <promeki/core/size2d.h>
14#include <promeki/core/error.h>
15#include <promeki/core/result.h>
16
18
28class Terminal {
29 public:
31 using ResizeCallback = std::function<void(int cols, int rows)>;
32
63
66
69
70 Terminal(const Terminal &) = delete;
71 Terminal &operator=(const Terminal &) = delete;
72
78
84
86 bool isRawMode() const { return _rawMode; }
87
96
103 Error windowSize(int &cols, int &rows) const;
104
109
115
121
123 bool isMouseTrackingEnabled() const { return _mouseTracking; }
124
130
136
142
148
154
162
180
188 Result<int> writeOutput(const char *data, int len);
189
190 private:
191 bool _rawMode = false;
192 bool _mouseTracking = false;
193 bool _bracketedPaste = false;
194 bool _alternateScreen = false;
195 ResizeCallback _resizeCallback;
196
197 // Opaque storage for platform-specific terminal state.
198 // On POSIX this holds a struct termios.
199 void *_origState = nullptr;
200};
201
Lightweight error code wrapper for the promeki library.
Definition error.h:39
Dynamic array container wrapping std::vector.
Definition list.h:40
Low-level terminal I/O abstraction.
Definition terminal.h:28
Error enableRawMode()
Enables raw terminal mode (disables line buffering, echo, etc).
Size2Di32 size() const
Returns the terminal size as a Size2Du32 (width x height).
Result< int > readInput(char *buf, int maxLen)
Reads available input bytes without blocking.
Error disableRawMode()
Restores the terminal to its original mode.
ColorSupport
Describes the color capability level of the terminal.
Definition terminal.h:54
@ GrayscaleTrue
Grayscale via 24-bit RGB with equal R=G=B (NO_COLOR + TrueColor).
Definition terminal.h:58
@ Basic
Basic 8/16 color support (standard ANSI).
Definition terminal.h:59
@ TrueColor
24-bit true color support.
Definition terminal.h:61
@ NoColor
No color support (e.g. dumb terminal).
Definition terminal.h:55
@ Color256
256 color support (xterm-256color and similar).
Definition terminal.h:60
@ Grayscale16
Grayscale via the 4 gray entries in the 16-color palette (NO_COLOR + Basic).
Definition terminal.h:56
@ Grayscale256
Grayscale via the 24-entry grayscale ramp in the 256-color palette (NO_COLOR + 256).
Definition terminal.h:57
bool isMouseTrackingEnabled() const
Returns true if mouse tracking is enabled.
Definition terminal.h:123
Error windowSize(int &cols, int &rows) const
Queries the current terminal window size.
Error disableAlternateScreen()
Switches back to the main screen buffer.
Result< int > writeOutput(const char *data, int len)
Writes raw bytes to stdout.
static ColorSupport colorSupport()
Detects the color support level of the terminal.
std::function< void(int cols, int rows)> ResizeCallback
Callback type for window resize notifications.
Definition terminal.h:31
void setResizeCallback(ResizeCallback cb)
Sets a callback for window resize events (SIGWINCH on POSIX).
Terminal()
Constructs a Terminal and saves the current terminal state.
Error disableMouseTracking()
Disables mouse tracking.
void installSignalHandlers()
Installs signal handlers for clean terminal restoration.
bool isRawMode() const
Returns true if raw mode is currently enabled.
Definition terminal.h:86
Error enableAlternateScreen()
Switches to the alternate screen buffer.
Error enableBracketedPaste()
Enables bracketed paste mode.
Error disableBracketedPaste()
Disables bracketed paste mode.
~Terminal()
Destructor. Restores terminal state and cleans up.
Error enableMouseTracking()
Enables xterm SGR mouse tracking.
#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