Sista v3.0.0-alpha.1
Sista is a C++ lightweight OS-agnostic library for terminal animations and videogames
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
sista::ANSISettings Struct Reference

Represents a set of ANSI settings including colors and attributes. More...

#include <ansi.hpp>

Collaboration diagram for sista::ANSISettings:
Collaboration graph

Public Member Functions

 ANSISettings ()
 
 ANSISettings (const RGBColor &, const RGBColor &, const Attribute &)
 Parameterized constructor with RGBColor for both foreground and background.
 
 ANSISettings (const ForegroundColor &, const BackgroundColor &, const Attribute &)
 Parameterized constructor with ForegroundColor and BackgroundColor enums.
 
 ANSISettings (const RGBColor &, const BackgroundColor &, const Attribute &)
 Parameterized constructor with ForegroundColor enum and RGBColor for background.
 
 ANSISettings (const ForegroundColor &, const RGBColor &, const Attribute &)
 Parameterized constructor with RGBColor for foreground and BackgroundColor enum.
 
 ANSISettings (const RGBColor &, const RGBColor &, const std::bitset< 10 > &)
 Parameterized constructor with RGBColor for both foreground and background, and a bitset for attributes.
 
 ANSISettings (const ForegroundColor &, const RGBColor &, const std::bitset< 10 > &)
 Parameterized constructor with ForegroundColor and RGBColor, and a bitset for attributes.
 
 ANSISettings (const RGBColor &, const BackgroundColor &, const std::bitset< 10 > &)
 Parameterized constructor with RGBColor and BackgroundColor, and a bitset for attributes.
 
 ANSISettings (const ForegroundColor &, const BackgroundColor &, std::initializer_list< Attribute >)
 Parameterized constructor with ForegroundColor and BackgroundColor, and an initializer list for attributes.
 
 ANSISettings (const ForegroundColor &, const RGBColor &, std::initializer_list< Attribute >)
 Parameterized constructor with ForegroundColor and RGBColor, and an initializer list for attributes.
 
 ANSISettings (const RGBColor &, const BackgroundColor &, std::initializer_list< Attribute >)
 Parameterized constructor with RGBColor and BackgroundColor, and an initializer list for attributes.
 
 ANSISettings (const ForegroundColor &, const BackgroundColor &, const std::bitset< 10 > &)
 Parametrized constructor with an initializer for the bitset attribute.
 
 ANSISettings (const RGBColor &, const RGBColor &, std::initializer_list< Attribute >)
 Parametrized constructor with an initializer list for the bitset attribute.
 
 ANSISettings (const std::variant< ForegroundColor, RGBColor > &, const std::variant< BackgroundColor, RGBColor > &, const std::variant< Attribute, std::bitset< 10 > > &)
 Parametrized constructor with all variants.
 
void apply () const
 Applies the ANSI settings to the terminal.
 
void reset () const
 Resets all ANSI settings to default values.
 

Public Attributes

std::variant< ForegroundColor, RGBColorforegroundColor
 Foreground color, can be ForegroundColor or RGBColor.
 
std::variant< BackgroundColor, RGBColorbackgroundColor
 Background color, can be BackgroundColor or RGBColor.
 
std::variant< Attribute, std::bitset< 10 > > attribute
 Text attribute setting.
 

Detailed Description

Represents a set of ANSI settings including colors and attributes.

This struct holds the foreground color, background color, and text attribute settings for ANSI escape codes. It provides constructors for various combinations of color types (predefined enums and RGB colors) and a method to apply these settings to the terminal.

Constructor & Destructor Documentation

◆ ANSISettings() [1/14]

sista::ANSISettings::ANSISettings ( )

Default constructor initializing to white foreground, black background, and reset attribute.

◆ ANSISettings() [2/14]

sista::ANSISettings::ANSISettings ( const RGBColor foregroundColor_,
const RGBColor backgroundColor_,
const Attribute attribute_ 
)

Parameterized constructor with RGBColor for both foreground and background.

Parameters
foregroundColor_The RGBColor for the foreground.
backgroundColor_The RGBColor for the background.
attribute_The text Attribute.

◆ ANSISettings() [3/14]

sista::ANSISettings::ANSISettings ( const ForegroundColor foregroundColor_,
const BackgroundColor backgroundColor_,
const Attribute attribute_ 
)

Parameterized constructor with ForegroundColor and BackgroundColor enums.

Parameters
foregroundColor_The ForegroundColor for the foreground.
backgroundColor_The BackgroundColor for the background.
attribute_The text Attribute.

◆ ANSISettings() [4/14]

sista::ANSISettings::ANSISettings ( const RGBColor foregroundColor_,
const BackgroundColor backgroundColor_,
const Attribute attribute_ 
)

Parameterized constructor with ForegroundColor enum and RGBColor for background.

Parameters
foregroundColor_The ForegroundColor for the foreground.
backgroundColor_The RGBColor for the background.
attribute_The text Attribute.

◆ ANSISettings() [5/14]

sista::ANSISettings::ANSISettings ( const ForegroundColor foregroundColor_,
const RGBColor backgroundColor_,
const Attribute attribute_ 
)

Parameterized constructor with RGBColor for foreground and BackgroundColor enum.

Parameters
foregroundColor_The RGBColor for the foreground.
backgroundColor_The BackgroundColor for the background.
attribute_The text Attribute.

◆ ANSISettings() [6/14]

sista::ANSISettings::ANSISettings ( const RGBColor foregroundColor_,
const RGBColor backgroundColor_,
const std::bitset< 10 > &  attribute_ 
)

Parameterized constructor with RGBColor for both foreground and background, and a bitset for attributes.

Parameters
foregroundColor_The RGBColor for the foreground.
backgroundColor_The RGBColor for the background.
attribute_The text attributes as a bitset.

◆ ANSISettings() [7/14]

sista::ANSISettings::ANSISettings ( const ForegroundColor foregroundColor_,
const RGBColor backgroundColor_,
const std::bitset< 10 > &  attribute_ 
)

Parameterized constructor with ForegroundColor and RGBColor, and a bitset for attributes.

Parameters
foregroundColor_The ForegroundColor for the foreground.
backgroundColor_The RGBColor for the background.
attribute_The text attributes as a bitset.

◆ ANSISettings() [8/14]

sista::ANSISettings::ANSISettings ( const RGBColor foregroundColor_,
const BackgroundColor backgroundColor_,
const std::bitset< 10 > &  attribute_ 
)

Parameterized constructor with RGBColor and BackgroundColor, and a bitset for attributes.

Parameters
foregroundColor_The RGBColor for the foreground.
backgroundColor_The BackgroundColor for the background.
attribute_The text attributes as a bitset.

◆ ANSISettings() [9/14]

sista::ANSISettings::ANSISettings ( const ForegroundColor foregroundColor_,
const BackgroundColor backgroundColor_,
std::initializer_list< Attribute attribute_ 
)

Parameterized constructor with ForegroundColor and BackgroundColor, and an initializer list for attributes.

Parameters
foregroundColor_The ForegroundColor for the foreground.
backgroundColor_The BackgroundColor for the background.
attribute_The text attributes as an initializer list.

◆ ANSISettings() [10/14]

sista::ANSISettings::ANSISettings ( const ForegroundColor foregroundColor_,
const RGBColor backgroundColor_,
std::initializer_list< Attribute attribute_ 
)

Parameterized constructor with ForegroundColor and RGBColor, and an initializer list for attributes.

Parameters
foregroundColor_The ForegroundColor for the foreground.
backgroundColor_The RGBColor for the background.
attribute_The text attributes as an initializer list.

◆ ANSISettings() [11/14]

sista::ANSISettings::ANSISettings ( const RGBColor foregroundColor_,
const BackgroundColor backgroundColor_,
std::initializer_list< Attribute attribute_ 
)

Parameterized constructor with RGBColor and BackgroundColor, and an initializer list for attributes.

Parameters
foregroundColor_The RGBColor for the foreground.
backgroundColor_The BackgroundColor for the background.
attribute_The text attributes as an initializer list.

◆ ANSISettings() [12/14]

sista::ANSISettings::ANSISettings ( const ForegroundColor foregroundColor_,
const BackgroundColor backgroundColor_,
const std::bitset< 10 > &  attribute_ 
)

Parametrized constructor with an initializer for the bitset attribute.

Parameters
foregroundColor_The ForegroundColor for the foreground.
backgroundColor_The BackgroundColor for the background.
attribute_The text attributes as a bitset.

◆ ANSISettings() [13/14]

sista::ANSISettings::ANSISettings ( const RGBColor foregroundColor_,
const RGBColor backgroundColor_,
std::initializer_list< Attribute attribute_ 
)

Parametrized constructor with an initializer list for the bitset attribute.

Parameters
foregroundColor_The RGBColor for the foreground.
backgroundColor_The RGBColor for the background.
attribute_The text attributes as a bitset.

◆ ANSISettings() [14/14]

sista::ANSISettings::ANSISettings ( const std::variant< ForegroundColor, RGBColor > &  ,
const std::variant< BackgroundColor, RGBColor > &  ,
const std::variant< Attribute, std::bitset< 10 > > &   
)

Parametrized constructor with all variants.

Parameters
foregroundColor_The foreground color (ForegroundColor or RGBColor).
backgroundColor_The background color (BackgroundColor or RGBColor).
attribute_The text attribute (Attribute or bitset).

Member Function Documentation

◆ apply()

void sista::ANSISettings::apply ( ) const

Applies the ANSI settings to the terminal.

This method applies the stored foreground color, background color, and text attribute settings to the terminal by calling the appropriate functions to set each property.

The settings will be visible on characters printed after this call.

See also
setForegroundColor
setBackgroundColor
setAttribute

◆ reset()

void sista::ANSISettings::reset ( ) const

Resets all ANSI settings to default values.

This method resets the terminal's text attributes by disabling the ones that were set in this ANSISettings instance.

It also tries to reset the foreground color to WHITE and the background color to BLACK, which are the defaults.

See also
Attribute

Member Data Documentation

◆ attribute

std::variant<Attribute, std::bitset<10> > sista::ANSISettings::attribute

Text attribute setting.

This variant holds either a single Attribute enum value or a bitset representing multiple attributes.

The bitset uses the following mapping:

  • Bit 0: RESET
  • Bit 1: BRIGHT
  • Bit 2: FAINT
  • Bit 3: ITALIC
  • Bit 4: UNDERSCORE
  • Bit 5: BLINK
  • Bit 6: RAPID_BLINK
  • Bit 7: REVERSE
  • Bit 8: HIDDEN
  • Bit 9: STRIKETHROUGH

    Setting a bit to 1 enables the corresponding attribute.

    Note
    In case of conflict, the last applied attribute takes precedence.
    Not all terminals support all attributes. RAPID_BLINK and HIDDEN are particularly unsupported.
    See also
    make_attr_bitset
    Attribute

◆ backgroundColor

std::variant<BackgroundColor, RGBColor> sista::ANSISettings::backgroundColor

Background color, can be BackgroundColor or RGBColor.

This variant holds either a predefined BackgroundColor enum value or an RGBColor struct for custom colors.

See also
BackgroundColor
RGBColor

◆ foregroundColor

std::variant<ForegroundColor, RGBColor> sista::ANSISettings::foregroundColor

Foreground color, can be ForegroundColor or RGBColor.

This variant holds either a predefined ForegroundColor enum value or an RGBColor struct for custom colors.

See also
ForegroundColor
RGBColor

The documentation for this struct was generated from the following files: