Sista v3.0.0-alpha.1
Sista is a C++ lightweight OS-agnostic library for terminal animations and videogames
Loading...
Searching...
No Matches
ansi.hpp
Go to the documentation of this file.
1
19#pragma once
20
21#include <variant>
22
23
37#define ESC "\x1b"
50#define CSI "\x1b["
62#define CLS "\x1b[2J"
74#define SSB "\x1b[3J"
85#define HIDE_CURSOR "\x1b[?25l"
96#define SHOW_CURSOR "\x1b[?25h"
108#define TL "\x1b[H"
109
110
111namespace sista {
120 enum class ForegroundColor: int {
121 BLACK = 30,
122 RED = 31,
123 GREEN = 32,
124 YELLOW = 33,
125 BLUE = 34,
126 MAGENTA = 35,
127 CYAN = 36,
128 WHITE = 37
129 };
138 enum class BackgroundColor: int {
139 BLACK = 40,
140 RED = 41,
141 GREEN = 42,
142 YELLOW = 43,
143 BLUE = 44,
144 MAGENTA = 45,
145 CYAN = 46,
146 WHITE = 47
147 };
157 enum class Attribute: int {
158 RESET = 0,
159 BRIGHT = 1,
160 FAINT = 2,
161 ITALIC = 3,
162 UNDERSCORE = 4,
163 BLINK = 5,
164 RAPID_BLINK = 6,
165 REVERSE = 7,
166 HIDDEN = 8,
167 STRIKETHROUGH = 9
168 };
176 struct RGBColor {
177 unsigned short int red;
178 unsigned short int green;
179 unsigned short int blue;
182 RGBColor();
188 RGBColor(unsigned short int, unsigned short int, unsigned short int);
189 };
190
231
247 void resetAnsi();
248
258 void setForegroundColor(const RGBColor&);
268 void setBackgroundColor(const RGBColor&);
279 void setForegroundColor(unsigned short int, unsigned short int, unsigned short int);
290 void setBackgroundColor(unsigned short int, unsigned short int, unsigned short int);
300 void setForegroundColor(unsigned short int);
310 void setBackgroundColor(unsigned short int);
311
320 enum class ScreenMode: int {
328 LINE_WRAPPING = 7,
336 };
337
358
377 std::variant<ForegroundColor, RGBColor> foregroundColor;
387 std::variant<BackgroundColor, RGBColor> backgroundColor;
390
392 ANSISettings();
398 ANSISettings(const RGBColor&, const RGBColor&, const Attribute&);
410 ANSISettings(const RGBColor&, const BackgroundColor&, const Attribute&);
416 ANSISettings(const ForegroundColor&, const RGBColor&, const Attribute&);
417
430 void apply() const;
431 };
432};
Sista library namespace.
Definition: ansi.cpp:25
void resetAnsi()
Resets all ANSI settings to default values.
Definition: ansi.cpp:46
void resetAttribute(Attribute attribute)
Resets a text attribute using a predefined Attribute enum.
Definition: ansi.cpp:38
Attribute
Enumeration of text attributes for ANSI escape codes.
Definition: ansi.hpp:157
ForegroundColor
Enumeration of foreground colors for ANSI escape codes.
Definition: ansi.hpp:120
ScreenMode
Represents various ANSI screen modes.
Definition: ansi.hpp:320
@ COLOR_16_COLORS_GRAPHICS_640_350
@ COLOR_16_COLORS_GRAPHICS_640_480
@ MONOCROME_2_COLORS_GRAPHICS_640_480
@ MONOCROME_2_COLORS_GRAPHICS_640_350
@ COLOR_256_COLORS_GRAPHICS_320_200
@ COLOR_16_COLORS_GRAPHICS_640_200
void unsetScreenMode(ScreenMode mode)
Unsets a specific screen mode.
Definition: ansi.cpp:74
void setBackgroundColor(BackgroundColor color)
Sets the background color using a predefined BackgroundColor enum.
Definition: ansi.cpp:32
void setForegroundColor(ForegroundColor color)
Sets the foreground color using a predefined ForegroundColor enum.
Definition: ansi.cpp:29
BackgroundColor
Enumeration of background colors for ANSI escape codes.
Definition: ansi.hpp:138
void setScreenMode(ScreenMode mode)
Sets a specific screen mode.
Definition: ansi.cpp:71
void setAttribute(Attribute attribute)
Sets a text attribute using a predefined Attribute enum.
Definition: ansi.cpp:35
Represents a set of ANSI settings including colors and attributes.
Definition: ansi.hpp:367
Attribute attribute
Text attribute setting.
Definition: ansi.hpp:389
void apply() const
Applies the ANSI settings to the terminal.
Definition: ansi.cpp:92
std::variant< ForegroundColor, RGBColor > foregroundColor
Foreground color, can be ForegroundColor or RGBColor.
Definition: ansi.hpp:377
std::variant< BackgroundColor, RGBColor > backgroundColor
Background color, can be BackgroundColor or RGBColor.
Definition: ansi.hpp:387
ANSISettings()
Definition: ansi.cpp:78
Represents an RGB color with red, green, and blue components in True Color (24-bit).
Definition: ansi.hpp:176
unsigned short int green
Definition: ansi.hpp:178
unsigned short int blue
Definition: ansi.hpp:179
RGBColor()
Default constructor initializing color to black (0,0,0).
Definition: ansi.cpp:26
unsigned short int red
Definition: ansi.hpp:177