NAME

TAttrPair - pair of color attributes value type

SYNOPSIS

use TUI::Drivers;

my $cNormal = TColorAttr->new( fg => ['#234983'], bg => ['#267232'] );
my $cHigh   = TColorAttr->new( fg => ['#309283'], bg => ['#127844'] );
my $attrs   = TAttrPair->new( lo => $cNormal, hi => $cHigh );

my $b = TDrawBuffer->new();
$b->moveCStr( 0, "Normal text, ~Highlighted text~", $attrs );

DESCRIPTION

TUI::Drivers::AttrPair provides TAttrPair, a value type that represents a pair of color attributes.

A TAttrPair is a blessed array reference of two TColorAttr elements, conventionally called the "low" (index 0) and "high" (index 1) attribute. Some API functions, such as TDrawBuffer->moveCStr, use a TAttrPair to pass both a normal and a highlighted attribute at once.

CONSTRUCTOR

new

Creates a color attribute pair.

With no arguments, both attributes use default colors and no style flags:

my $attrs = TAttrPair->new();

With a BIOS color attribute pair, the low byte becomes the low attribute and the high byte becomes the high attribute:

my $attrs = TAttrPair->new( bios => 0x1e3d );

With explicit low and optional high attributes:

my $attrs = TAttrPair->new(
  lo => $cNormal,
  hi => $cHigh,
);

If hi is omitted, it defaults to a BIOS attribute of 0. The lo and hi arguments must be TColorAttr values, but a plain integer is also accepted as a shorthand for a BIOS attribute.

METHODS

asBIOS

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

Returns a BIOS attribute pair, with the low attribute in the low byte and the high attribute in the high byte.

rshift

my $result = $self->rshift($shift);

Shifts the asBIOS value right by $shift bits.

As a special case, shifting by 8 returns a new TAttrPair whose low attribute is this pair's high attribute, for compatibility with legacy code that used >> 8 on an attribute pair to extract the higher attribute.

setLo

$self->setLo($attr);

Sets the low attribute, for compatibility with legacy code that used |= on an attribute pair to set the lower attribute.

Returns $self.

OPERATORS

Numeric conversion

my $bios = 0+ $attrs;

Returns the asBIOS value of this pair.

Right shift

my $result = $attrs >> $shift;

Calls "rshift".

Bitwise-or assignment

$attrs |= $attr;

Calls "setLo".

Array element access

Being a blessed array reference, the individual attributes can be accessed and replaced directly with $attrs->[0] (low) and $attrs->[1] (high):

my $lo = $attrs->[0];
$attrs->[1] = TColorAttr->new( bios => 0x70 );

SEE ALSO

TColorAttr

AUTHORS

  • magiblot <magiblot@hotmail.com> (original attribute pair 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).