Sista v3.0.0-alpha.1
Sista is a C++ lightweight OS-agnostic library for terminal animations and videogames
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Enumerations | Functions
ansi.hpp File Reference

ANSI escape code utilities and types for terminal formatting. More...

#include <variant>
Include dependency graph for ansi.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  sista::RGBColor
 Represents an RGB color with red, green, and blue components in True Color (24-bit). More...
 
struct  sista::ANSISettings
 Represents a set of ANSI settings including colors and attributes. More...
 

Namespaces

namespace  sista
 Sista library namespace.
 

Macros

#define ESC   "\x1b"
 Escape character for ANSI escape codes.
 
#define CSI   "\x1b["
 Control Sequence Introducer for ANSI escape codes.
 
#define CLS   "\x1b[2J"
 Clear Screen ANSI escape code.
 
#define SSB   "\x1b[3J"
 Erase Scrollback Buffer ANSI escape code.
 
#define HIDE_CURSOR   "\x1b[?25l"
 Hide Cursor ANSI escape code.
 
#define SHOW_CURSOR   "\x1b[?25h"
 Show Cursor ANSI escape code.
 
#define TL   "\x1b[H"
 Top Left ANSI escape code.
 

Enumerations

enum class  sista::ForegroundColor : int {
  sista::BLACK = 30 , sista::RED = 31 , sista::GREEN = 32 , sista::YELLOW = 33 ,
  sista::BLUE = 34 , sista::MAGENTA = 35 , sista::CYAN = 36 , sista::WHITE = 37
}
 Enumeration of foreground colors for ANSI escape codes. More...
 
enum class  sista::BackgroundColor : int {
  sista::BLACK = 40 , sista::RED = 41 , sista::GREEN = 42 , sista::YELLOW = 43 ,
  sista::BLUE = 44 , sista::MAGENTA = 45 , sista::CYAN = 46 , sista::WHITE = 47
}
 Enumeration of background colors for ANSI escape codes. More...
 
enum class  sista::Attribute : int {
  sista::RESET = 0 , sista::BRIGHT = 1 , sista::FAINT = 2 , sista::ITALIC = 3 ,
  sista::UNDERSCORE = 4 , sista::BLINK = 5 , sista::RAPID_BLINK = 6 , sista::REVERSE = 7 ,
  sista::HIDDEN = 8 , sista::STRIKETHROUGH = 9
}
 Enumeration of text attributes for ANSI escape codes. More...
 
enum class  sista::ScreenMode : int {
  sista::MONOCROME_TEXT_40_25 = 0 , sista::COLOR_TEXT_40_25 = 1 , sista::MONOCROME_TEXT_80_25 = 2 , sista::COLOR_TEXT_80_25 = 3 ,
  sista::FOUR_COLORS_GRAPHICS_320_200 = 4 , sista::MONOCROME_GRAPHICS_320_200 = 5 , sista::MONOCROME_GRAPHICS_640_200 = 6 , sista::LINE_WRAPPING = 7 ,
  sista::COLOR_GRAPHICS_320_200 = 13 , sista::COLOR_16_COLORS_GRAPHICS_640_200 = 14 , sista::MONOCROME_2_COLORS_GRAPHICS_640_350 = 15 , sista::COLOR_16_COLORS_GRAPHICS_640_350 = 16 ,
  sista::MONOCROME_2_COLORS_GRAPHICS_640_480 = 17 , sista::COLOR_16_COLORS_GRAPHICS_640_480 = 18 , sista::COLOR_256_COLORS_GRAPHICS_320_200 = 19
}
 Represents various ANSI screen modes. More...
 

Functions

void sista::setForegroundColor (ForegroundColor)
 Sets the foreground color using a predefined ForegroundColor enum.
 
void sista::setBackgroundColor (BackgroundColor)
 Sets the background color using a predefined BackgroundColor enum.
 
void sista::setAttribute (Attribute)
 Sets a text attribute using a predefined Attribute enum.
 
void sista::resetAttribute (Attribute)
 Resets a text attribute using a predefined Attribute enum.
 
void sista::resetAnsi ()
 Resets all ANSI settings to default values.
 
void sista::setForegroundColor (const RGBColor &)
 Sets the foreground color using an RGBColor struct.
 
void sista::setBackgroundColor (const RGBColor &)
 Sets the background color using an RGBColor struct.
 
void sista::setForegroundColor (unsigned short int, unsigned short int, unsigned short int)
 Sets the foreground color using RGB values.
 
void sista::setBackgroundColor (unsigned short int, unsigned short int, unsigned short int)
 Sets the background color using RGB values.
 
void sista::setForegroundColor (unsigned short int)
 Sets the foreground color using a 256-color palette index.
 
void sista::setBackgroundColor (unsigned short int)
 Sets the background color using a 256-color palette index.
 
void sista::setScreenMode (ScreenMode)
 Sets a specific screen mode.
 
void sista::unsetScreenMode (ScreenMode)
 Unsets a specific screen mode.
 

Detailed Description

ANSI escape code utilities and types for terminal formatting.

This header provides macros, enums, structs, and functions for working with ANSI escape codes, including color, attribute, and screen mode settings. It is part of the Sista library and is intended for use in terminal-based applications requiring advanced text formatting and control.

Author
FLAK-ZOSO
Date
2022-2025
Version
3.0.0
Note
Many niche features are not implemented, see references for more details.
Not all terminals support all ANSI features.
See also
https://en.wikipedia.org/wiki/ANSI_escape_code
https://gist.github.com/ConnerWill/d4b6c776b509add763e17f9f113fd25b

Macro Definition Documentation

◆ CLS

#define CLS   "\x1b[2J"

Clear Screen ANSI escape code.

This macro defines the ANSI escape code for clearing the screen. It is represented as a string literal containing the appropriate escape sequence.

See also
ESC
CSI
SSB
TL

◆ CSI

#define CSI   "\x1b["

Control Sequence Introducer for ANSI escape codes.

This macro defines the Control Sequence Introducer (CSI) used in ANSI escape codes. It is represented as a string literal containing the escape character followed by the '[' character.

See also
ESC
CLS
SSB
TL

◆ ESC

#define ESC   "\x1b"

Escape character for ANSI escape codes.

This macro defines the escape character used in ANSI escape codes. It is represented as a string literal containing the escape character.

See also
CSI
CLS
SSB
HIDE_CURSOR
SHOW_CURSOR
TL

◆ HIDE_CURSOR

#define HIDE_CURSOR   "\x1b[?25l"

Hide Cursor ANSI escape code.

This macro defines the ANSI escape code for hiding the cursor. It is represented as a string literal containing the appropriate escape sequence.

See also
ESC
CSI
SHOW_CURSOR

◆ SHOW_CURSOR

#define SHOW_CURSOR   "\x1b[?25h"

Show Cursor ANSI escape code.

This macro defines the ANSI escape code for showing the cursor. It is represented as a string literal containing the appropriate escape sequence.

See also
ESC
CSI
HIDE_CURSOR

◆ SSB

#define SSB   "\x1b[3J"

Erase Scrollback Buffer ANSI escape code.

This macro defines the ANSI escape code for erasing the scrollback buffer. It is represented as a string literal containing the appropriate escape sequence.

See also
ESC
CSI
CLS
TL

◆ TL

#define TL   "\x1b[H"

Top Left ANSI escape code.

This macro defines the ANSI escape code for moving the cursor to the top-left corner of the screen. It is represented as a string literal containing the appropriate escape sequence.

See also
ESC
CSI
CLS
SSB