Skip to content

ftxui::Color ​

cpp
#include <ftxui/screen/color.hpp>

Color is a class that represents a color in the terminal user interface.

Examples: component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/dropdown_custom, component/flexbox_gallery, component/focus, component/homescreen, component/input_style, component/linear_gradient_gallery, component/maybe, component/menu_entries (+22 more)

Summary ​

SymbolDescription
Palette1
Palette16
Palette256
ColorBuild a transparent color.
operator==
operator!=
Print
PrintToAppend the ANSI color code to a string (zero-allocation fast path).
IsOpaque
GetRedThe red component of the color [0,255]. Palette colors are resolved to their RGB approximation. Returns 0 for the default (transparent) color.
GetGreenThe green component of the color [0,255]. Palette colors are resolved to their RGB approximation. Returns 0 for the default (transparent) color.
GetBlueThe blue component of the color [0,255]. Palette colors are resolved to their RGB approximation. Returns 0 for the default (transparent) color.
GetAlphaThe alpha component of the color [0,255]. 0 is fully transparent.
RGBBuild a Color from its RGB representation. https://en.wikipedia.org/wiki/RGB_color_model.
HSVBuild a Color from its HSV representation. https://en.wikipedia.org/wiki/HSL_and_HSV.
RGBABuild a Color from its RGBA representation. https://en.wikipedia.org/wiki/RGB_color_model.
HSVABuild a Color from its HSV representation. https://en.wikipedia.org/wiki/HSL_and_HSV.
Interpolate
BlendBlend two colors together using the alpha channel.

Public Types ​

Palette1 ​

cpp
enum Palette1 { Default };

Palette16 ​

cpp
enum Palette16 { Black, Red, Green, Yellow, Blue, Magenta, Cyan, GrayLight, GrayDark, RedLight, GreenLight, YellowLight, BlueLight, MagentaLight, CyanLight, White };

Palette256 ​

cpp
enum Palette256 { Aquamarine1, Aquamarine1Bis, Aquamarine3, Blue1, Blue3, Blue3Bis, BlueViolet, CadetBlue, CadetBlueBis, Chartreuse1, Chartreuse2, Chartreuse2Bis, Chartreuse3, Chartreuse3Bis, Chartreuse4, CornflowerBlue, Cornsilk1, Cyan1, Cyan2, Cyan3, DarkBlue, DarkCyan, DarkGoldenrod, DarkGreen, DarkKhaki, DarkMagenta, DarkMagentaBis, DarkOliveGreen1, DarkOliveGreen1Bis, DarkOliveGreen2, DarkOliveGreen3, DarkOliveGreen3Bis, DarkOliveGreen3Ter, DarkOrange, DarkOrange3, DarkOrange3Bis, DarkRed, DarkRedBis, DarkSeaGreen, DarkSeaGreen1, DarkSeaGreen1Bis, DarkSeaGreen2, DarkSeaGreen2Bis, DarkSeaGreen3, DarkSeaGreen3Bis, DarkSeaGreen4, DarkSeaGreen4Bis, DarkSlateGray1, DarkSlateGray2, DarkSlateGray3, DarkTurquoise, DarkViolet, DarkVioletBis, DeepPink1, DeepPink1Bis, DeepPink2, DeepPink3, DeepPink3Bis, DeepPink4, DeepPink4Bis, DeepPink4Ter, DeepSkyBlue1, DeepSkyBlue2, DeepSkyBlue3, DeepSkyBlue3Bis, DeepSkyBlue4, DeepSkyBlue4Bis, DeepSkyBlue4Ter, DodgerBlue1, DodgerBlue2, DodgerBlue3, Gold1, Gold3, Gold3Bis, Green1, Green3, Green3Bis, Green4, GreenYellow, Grey0, Grey100, Grey11, Grey15, Grey19, Grey23, Grey27, Grey3, Grey30, Grey35, Grey37, Grey39, Grey42, Grey46, Grey50, Grey53, Grey54, Grey58, Grey62, Grey63, Grey66, Grey69, Grey7, Grey70, Grey74, Grey78, Grey82, Grey84, Grey85, Grey89, Grey93, Honeydew2, HotPink, HotPink2, HotPink3, HotPink3Bis, HotPinkBis, IndianRed, IndianRed1, IndianRed1Bis, IndianRedBis, Khaki1, Khaki3, LightCoral, LightCyan1Bis, LightCyan3, LightGoldenrod1, LightGoldenrod2, LightGoldenrod2Bis, LightGoldenrod2Ter, LightGoldenrod3, LightGreen, LightGreenBis, LightPink1, LightPink3, LightPink4, LightSalmon1, LightSalmon3, LightSalmon3Bis, LightSeaGreen, LightSkyBlue1, LightSkyBlue3, LightSkyBlue3Bis, LightSlateBlue, LightSlateGrey, LightSteelBlue, LightSteelBlue1, LightSteelBlue3, LightYellow3, Magenta1, Magenta2, Magenta2Bis, Magenta3, Magenta3Bis, Magenta3Ter, MediumOrchid, MediumOrchid1, MediumOrchid1Bis, MediumOrchid3, MediumPurple, MediumPurple1, MediumPurple2, MediumPurple2Bis, MediumPurple3, MediumPurple3Bis, MediumPurple4, MediumSpringGreen, MediumTurquoise, MediumVioletRed, MistyRose1, MistyRose3, NavajoWhite1, NavajoWhite3, NavyBlue, Orange1, Orange3, Orange4, Orange4Bis, OrangeRed1, Orchid, Orchid1, Orchid2, PaleGreen1, PaleGreen1Bis, PaleGreen3, PaleGreen3Bis, PaleTurquoise1, PaleTurquoise4, PaleVioletRed1, Pink1, Pink3, Plum1, Plum2, Plum3, Plum4, Purple, Purple3, Purple4, Purple4Bis, PurpleBis, Red1, Red3, Red3Bis, RosyBrown, RoyalBlue1, Salmon1, SandyBrown, SeaGreen1, SeaGreen1Bis, SeaGreen2, SeaGreen3, SkyBlue1, SkyBlue2, SkyBlue3, SlateBlue1, SlateBlue3, SlateBlue3Bis, SpringGreen1, SpringGreen2, SpringGreen2Bis, SpringGreen3, SpringGreen3Bis, SpringGreen4, SteelBlue, SteelBlue1, SteelBlue1Bis, SteelBlue3, Tan, Thistle1, Thistle3, Turquoise2, Turquoise4, Violet, Wheat1, Wheat4, Yellow1, Yellow2, Yellow3, Yellow3Bis, Yellow4, Yellow4Bis };

Examples: component/homescreen, dom/color_gallery, dom/color_info_palette256

Public Member Functions ​

Color ​

cpp
Color();

Build a transparent color.

Examples: component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/dropdown_custom, component/flexbox_gallery, component/focus, component/homescreen, component/input_style, component/linear_gradient_gallery, component/maybe, component/menu_entries (+22 more)

Color ​

cpp
Color(Palette1 index);

Build a transparent color.

Examples: component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/dropdown_custom, component/flexbox_gallery, component/focus, component/homescreen, component/input_style, component/linear_gradient_gallery, component/maybe, component/menu_entries (+22 more)

Color ​

cpp
Color(Palette16 index);

Build a color using the Palette16 colors.

Examples: component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/dropdown_custom, component/flexbox_gallery, component/focus, component/homescreen, component/input_style, component/linear_gradient_gallery, component/maybe, component/menu_entries (+22 more)

Color ​

cpp
Color(Palette256 index);

Build a color using Palette256 colors.

Examples: component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/dropdown_custom, component/flexbox_gallery, component/focus, component/homescreen, component/input_style, component/linear_gradient_gallery, component/maybe, component/menu_entries (+22 more)

Color ​

cpp
Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);

Build a Color from its RGB representation. https://en.wikipedia.org/wiki/RGB_color_model.

Parameters:

  • red: The quantity of red [0,255]
  • green: The quantity of green [0,255]
  • blue: The quantity of blue [0,255]
  • alpha: The quantity of alpha [0,255]

Examples: component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/dropdown_custom, component/flexbox_gallery, component/focus, component/homescreen, component/input_style, component/linear_gradient_gallery, component/maybe, component/menu_entries (+22 more)

operator== ​

cpp
bool operator==(const Color & rhs) const;

operator!= ​

cpp
bool operator!=(const Color & rhs) const;

Print ​

cpp
std::string Print(bool is_background_color) const;

PrintTo ​

cpp
void PrintTo(std::string & out, bool is_background_color) const;

Append the ANSI color code to a string (zero-allocation fast path).

Parameters:

  • out: The string to append to.
  • is_background_color: Whether this is a background color code.

PrintTo ​

cpp
void PrintTo(std::string & out, bool is_background_color, Terminal::Color color_support) const;

Append the ANSI color code to a string, degraded to the given terminal color support.

Parameters:

  • out: The string to append to.
  • is_background_color: Whether this is a background color code.
  • support: The terminal color support.

IsOpaque ​

cpp
bool IsOpaque() const;

GetRed ​

cpp
uint8_t GetRed() const;

The red component of the color [0,255]. Palette colors are resolved to their RGB approximation. Returns 0 for the default (transparent) color.

GetGreen ​

cpp
uint8_t GetGreen() const;

The green component of the color [0,255]. Palette colors are resolved to their RGB approximation. Returns 0 for the default (transparent) color.

GetBlue ​

cpp
uint8_t GetBlue() const;

The blue component of the color [0,255]. Palette colors are resolved to their RGB approximation. Returns 0 for the default (transparent) color.

GetAlpha ​

cpp
uint8_t GetAlpha() const;

The alpha component of the color [0,255]. 0 is fully transparent.

Static Functions ​

RGB ​

cpp
static Color RGB(uint8_t red, uint8_t green, uint8_t blue);

Build a Color from its RGB representation. https://en.wikipedia.org/wiki/RGB_color_model.

Parameters:

  • red: The quantity of red [0,255]
  • green: The quantity of green [0,255]
  • blue: The quantity of blue [0,255]

HSV ​

cpp
static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value);

Build a Color from its HSV representation. https://en.wikipedia.org/wiki/HSL_and_HSV.

Parameters:

  • h: The hue of the color [0,255]
  • s: The "colorfulness" [0,255].
  • v: The "Lightness" [0,255]

RGBA ​

cpp
static Color RGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);

Build a Color from its RGBA representation. https://en.wikipedia.org/wiki/RGB_color_model.

Parameters:

  • red: The quantity of red [0,255]
  • green: The quantity of green [0,255]
  • blue: The quantity of blue [0,255]
  • alpha: The quantity of alpha [0,255]

See also: Color::RGB

HSVA ​

cpp
static Color HSVA(uint8_t hue, uint8_t saturation, uint8_t value, uint8_t alpha);

Build a Color from its HSV representation. https://en.wikipedia.org/wiki/HSL_and_HSV.

Parameters:

  • h: The hue of the color [0,255]
  • s: The "colorfulness" [0,255].
  • v: The "Lightness" [0,255]
  • alpha: The quantity of alpha [0,255]

Interpolate ​

cpp
static Color Interpolate(float t, const Color & a, const Color & b);

Blend ​

cpp
static Color Blend(const Color & lhs, const Color & rhs);

Blend two colors together using the alpha channel.