nxt::Rgba8 struct

Terminal color: packed into 32 bits.

Encoding (uses alpha=0 space for special values): alpha > 0: True color RGBA (24-bit color + alpha) 0x00000000-0x000000FF: 256-color palette (includes ANSI 16) 0x00000100: Terminal default (SGR 39/49)

This lets us represent all terminal color modes in a single uint32_t:

  • ANSI 16 colors (palette 0-15, respects terminal theme)
  • 256-color palette (0-255)
  • 24-bit true color with alpha
  • Terminal default (reset to user's configured color)

Public static functions

static auto black() →  Rgba8 constexpr noexcept
ANSI black.
static auto blue() →  Rgba8 constexpr noexcept
ANSI blue.
static auto bright_black() →  Rgba8 constexpr noexcept
ANSI bright black.
static auto bright_blue() →  Rgba8 constexpr noexcept
ANSI bright blue.
static auto bright_cyan() →  Rgba8 constexpr noexcept
ANSI bright cyan.
static auto bright_green() →  Rgba8 constexpr noexcept
ANSI bright green.
static auto bright_magenta() →  Rgba8 constexpr noexcept
ANSI bright magenta.
static auto bright_red() →  Rgba8 constexpr noexcept
ANSI bright red.
static auto bright_white() →  Rgba8 constexpr noexcept
ANSI bright white.
static auto bright_yellow() →  Rgba8 constexpr noexcept
ANSI bright yellow.
static auto cyan() →  Rgba8 constexpr noexcept
ANSI cyan.
static auto from_raw(std::uint32_t v) →  Rgba8 constexpr noexcept
Construct from an already-packed representation.
static auto green() →  Rgba8 constexpr noexcept
ANSI green.
static auto magenta() →  Rgba8 constexpr noexcept
ANSI magenta.
static auto palette(std::uint8_t index) →  Rgba8 constexpr noexcept
256-color palette (0-255, includes ANSI 16 at 0-15)
static auto red() →  Rgba8 constexpr noexcept
ANSI red.
static auto terminal_default() →  Rgba8 constexpr noexcept
Terminal default color (SGR 39 for fg, SGR 49 for bg)
static auto transparent() →  Rgba8 constexpr noexcept
Fully transparent (for compositing - layer below shows through)
static auto white() →  Rgba8 constexpr noexcept
ANSI white.
static auto yellow() →  Rgba8 constexpr noexcept
ANSI yellow.

Constructors, destructors, conversion operators

Rgba8(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a = 255) constexpr noexcept
Construct from RGBA components (true color)
Rgba8(Rgb8 rgb, std::uint8_t a = 255) constexpr noexcept
Construct from RGB components (opaque true color)

Public functions

auto a() const →  std::uint8_t constexpr noexcept
Alpha channel for true-color values.
auto b() const →  std::uint8_t constexpr noexcept
Blue channel for true-color values.
auto g() const →  std::uint8_t constexpr noexcept
Green channel for true-color values.
auto is_palette() const →  bool constexpr noexcept
True when this refers to the 256-color terminal palette.
auto is_terminal_default() const →  bool constexpr noexcept
True when this requests the terminal's configured default color.
auto is_transparent() const →  bool constexpr noexcept
True when this is the transparent compositing sentinel.
auto is_true_color() const →  bool constexpr noexcept
True when this is an explicit RGBA value.
auto operator<=>(const Rgba8&) const →  auto defaulted constexpr
auto palette_index() const →  std::uint8_t constexpr noexcept
Palette index for palette colors.
auto r() const →  std::uint8_t constexpr noexcept
Red channel for true-color values.
auto to_rgb() const →  Rgb8 constexpr noexcept
Convert to RGB (only meaningful for true color)

Public variables

std::uint32_t value
Packed representation containing either RGBA or a terminal sentinel.

Friends

auto operator<<(std::ostream& os, const Rgba8& c) →  std::ostream&