Image::ANSI::Pixel - Pixel object


Image-ANSI documentation Contained in the Image-ANSI distribution.

Index


Code Index:

NAME

Top

Image::ANSI::Pixel - Pixel object

SYNOPSIS

Top

	$pixel = Image::ANSI::Pixel->new;

	# foreground color
	$pixel->fg( $fg );

	# background color
	$pixel->bg( $bg );

	# blinking
	$pixel->blink( $blink );

	# or all 3 from an attribute byte
	$pixel->attr( $attr );

	# the character
	$pixel->char( $char );

METHODS

Top

new( %options )

Create a new pixel and set its attributes.

attr( [$attr] )

Set the foreground, background and blink properties from an attribute byte.

fg( [$fg] )

Set the foreground color

bg( [$bg] )

Set the background color

char( [$char] )

Set the character to be displayed

AUTHOR

Top

* Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top


Image-ANSI documentation Contained in the Image-ANSI distribution.
package Image::ANSI::Pixel;

use base qw( Class::Accessor );

use strict;
use warnings;

# Attribute byte constants
use constant ATTR_BLINK => 128;
use constant ATTR_BG    => 112;
use constant ATTR_FG    => 15;

our $VERSION = '0.10';

__PACKAGE__->mk_accessors( qw( char fg bg blink ) );

sub new {
	my $class   = shift;
	my %options = @_;
	my $self    = {};

	bless $self, $class;

	$self->$_( $options{ $_ } ) for keys %options;

	return $self;
}

sub attr {
	my $self = shift;
	my $attr = $_[ 0 ];

	if( @_ ) {
		$self->fg( $attr & ATTR_FG );
		$self->bg( ( $attr & ATTR_BG ) >> 4 );
		$self->blink( ( $attr & ATTR_BLINK ) >> 7 );
	}
	else {
		$attr  = 0;
		$attr |= $self->fg;
		$attr |= ( $self->bg << 4 );
		$attr |= ( $self->blink << 7 );
	}

	return $attr;
}

1;