NAME

TColor - represents a color in any of the supported color types

SYNOPSIS

use TUI::Drivers;

my $default = TColor->new();

my $bios = TColor->new(
  bios => 0xF,
);

my $rgb = TColor->new(
  rgb => 0x7F00BB,
);

my $xterm = TColor->new(
  xterm => 196,
);

if ( $rgb->isRGB ) {
  my $value = $rgb->asRGB;
}

my $biosColor = $rgb->toBIOS(1);

DESCRIPTION

TUI::Drivers::Color provides TColor, a value type that represents one of several color kinds:

  • Terminal default color

  • BIOS color values

  • XTerm color values

  • 24-bit RGB colors

The purpose of this type is to describe either the foreground or background color of a screen cell.

In a terminal emulator, the default color represents text displayed without any explicit color attributes.

CONSTRUCTOR

new

Creates a desired color value.

With no arguments, a default terminal color is created:

my $color = TColor->new();

Create a BIOS color:

my $color = TColor->new(
  bios => 0xF,
);

Create an RGB color:

my $color = TColor->new(
  rgb => 0x7F00BB,
);

An RGB color may also be specified as an RGB triplet:

my $color = TColor->new(
  rgb => [ 127, 0, 187 ],
);

Create an XTerm color:

my $color = TColor->new(
  xterm => 196,
);

METHODS

asBIOS

my $bios = $self->asBIOS();

Returns the stored value as a BIOS color.

No conversion is performed. Make sure to verify the color type first.

asRGB

my $rgb = $self->asRGB();

Returns the stored value as an RGB color.

No conversion is performed. Make sure to verify the color type first.

asXTerm

my $xterm = $self->asXTerm();

Returns the stored value as an XTerm color.

No conversion is performed. Make sure to verify the color type first.

bitCast

my $bits = $self->bitCast();
$self->bitCast( $bits );

Returns or replaces the underlying integer representation.

No conversion is performed.

equals

my $bool = $self->equals(
  $other,
);

Returns true if both values represent exactly the same color value and type.

isDefault

my $bool = $self->isDefault();

Returns true if the value represents the terminal default color.

isBIOS

my $bool = $self->isBIOS();

Returns true if the value represents a BIOS color.

isRGB

my $bool = $self->isRGB();

Returns true if the value represents a 24-bit RGB color.

isXTerm

my $bool = $self->isXTerm();

Returns true if the value represents an XTerm color.

toBIOS

my $bios = $self->toBIOS(
  $isForeground,
);

Returns a BIOS color equivalent to the current value.

RGB and XTerm colors are quantized to the nearest BIOS-compatible color.

When the value represents the terminal default color, the returned value is the standard foreground or background BIOS color depending on the value of $isForeground.

OPERATORS

Numeric equality

$a == $b

Returns true when TColor values contain identical data; support typecast to a TColor value if one is a number.

Numeric conversion

my $bits = 0+ $color;

Returns the encoded color value as an integer.

The returned value contains both the color type and color data.

SEE ALSO

TUI::Drivers::Const, TColorAttr, TScreenCell, Convert::Color

AUTHORS

  • magiblot <magiblot@hotmail.com> (original color attribute design)

  • J. Schneider <brickpool@cpan.org> (Perl implementation and maintenance)

COPYRIGHT AND LICENSE

Copyright (c) 2019-2026 the "AUTHORS" listed above.

This software is licensed under the MIT license (see the LICENSE file, which is part of the distribution).