Term::Caca - perl interface for libcaca (Colour AsCii Art library)
version 1.2.0
use Term::Caca; my $caca = Term::Caca->new; $caca->text( [5, 5], "pwn3d"); $caca->refresh; sleep 3;
Term::Caca is an API for the ASCII drawing library libcaca.
Term::Caca
This version of Term::Caca is compatible with the 1.x version of the libcaca library (development has been made against version 0.99.beta17 of the library).
# exports
use Term::Caca qw/ :all /; # import all # or use Term::Caca qw/ :colors /; # import specific group # or use Term::Caca qw/ $LIGHTRED /; # import specific constant
use Term::Caca qw/ :colors /; # import all colors # or use Term::Caca qw/ $WHITE $LIGHTRED /; # import specific colors # or use Term::Caca qw/ %COLORS /; # import colors as a hash # or print $Term::Caca::COLORS{WHITE} # use original array directly
The color constants used by set_ansi_color(). The available colors are
set_ansi_color()
BLACK BLUE GREEN CYAN RED MAGENTA BROWN LIGHTGRAY DARKGRAY LIGHTBLUE LIGHTGREEN LIGHTCYAN LIGHTRED LIGHTMAGENTA YELLOW WHITE DEFAULT TRANSPARENT
use Term::Caca qw/ :events /; # import all events # or use Term::Caca qw/ $NO_EVENT $KEY_RELEASE /; # import specific events # or use Term::Caca qw/ %EVENTS /; # import events as a hash # or print $Term::Caca::EVENTS{MOUSE_PRESS} # use original array directly
The event constants used by the mask of wait_for_event(). The available events are
wait_for_event()
NO_EVENT ANY_EVENT KEY_PRESS KEY_RELEASE MOUSE_PRESS MOUSE_RELEASE MOUSE_MOTION RESIZE QUIT
Returns an hash which keys are the available display drivers and the values their descriptions.
Returns the list of available drivers.
Instantiates a Term::Caca object.
The optional argument driver can be passed to select a specific display driver. If it's not given, the best available driver will be used.
Sets the window title to $title.
Returns the invocant Term::Caca object.
Refreshes the display.
Sets the refresh delay in seconds. The refresh delay is used by refresh to achieve constant framerate.
refresh
If the time is zero, constant framerate is disabled. This is the default behaviour.
Returns the average rendering time, which is measured as the time between two refresh() calls, in seconds. If constant framerate is enabled via set_refresh_delay(), the average rendering time will be close to the requested delay even if the real rendering time was shorter.
refresh()
set_refresh_delay()
Clears the canvas using the current background color.
Returns the invocant object.
Returns the width and height of the canvas, as a list in an array context, as a array ref in a scalar context.
Returns the canvas width.
Returns the canvas height.
Returns the position of the mouse. In a list context, returns the x, y coordinates, in a scalar context returns them as an array ref.
This function is not reliable if the ncurses or S-Lang drivers are being used, because mouse position is only detected when the mouse is clicked. Other drivers such as X11 work well.
Imports the drawing. The supported formats are
Returns the canvas in the given format.
Supported formats are
Sets the foreground and background colors used by primitives, using colors as defined by %COLORS.
%COLORS
$t->set_ansi_color( $LIGHTRED, $WHITE );
Sets the foreground and background colors used by primitives.
Each color is an array ref to a ARGB (transparency + RGB) set of values, all between 0 and 15. Alternatively, they can be given as a string of the direct hexadecimal value.
# red on white $t->set_color( [ 15, 15, 0, 0 ], 'ffff' );
Prints $text at the given coordinates.
Prints the character $char at the given coordinates. If $char is a string of more than one character, only the first character is printed.
Draws a line from @point_a to @point_b using the character $char or, if undefined, ascii art.
Draws the polyline defined by @points, where each point is an array ref of the coordinates. E.g.
$t->polyline( [ [ 0,0 ], [ 10,15 ], [ 20, 15 ] ] );
The lines are drawn using $char or, if not specified, using ascii art.
If $close is true, the end point of the polyline will be connected to the first point.
Draws a circle centered at @center with a radius of $radius using the character $char or, if not defined, ascii art. if $fill is set to true, the circle is filled with $char as well.
If $fill is defined but $char is not, $fill will be taken as the filling character. I.e.,
$c->circle( [10,10], 5, char => 'x', fill => 1 ); # equivalent to $c->circle( [10,10], 5, fill => 'x' );
Draws an ellipse centered at @center with an x-axis radius of $radius_x and a y-radius of $radius_y using the character $char or, if not defined, ascii art.
If $fill is defined but $char is not, $fill will be taken as the filling character.
Draws a rectangle of dimensions $width and $height with its upper-left corner at @top_corner, using the character $char or, if not defined, ascii art.
Draws a triangle defined by the three given points using the character $char or, if not defined, ascii art.
Waits and returns a Term::Caca::Event object matching the mask.
Term::Caca::Event
$timeout is in seconds. If set to 0, the method returns immediatly and, if no event was found, returns nothing. If $timeout is negative, the method waits forever for an event matching the mask.
$timeout
# wait for 5 seconds for a key press or the closing of the window my $event = $t->wait_for_event( mask => $KEY_PRESS | $QUIT, timeout => 5 ); say "user is idle" unless defined $event; exit if $event->isa( 'Term::Caca::Event::Quit' ); say "user typed ", $event->char;
libcaca - http://caca.zoy.org/
Term::Kaka
John Beppu <beppu@cpan.org>
Yanick Champoux <yanick@cpan.org>
This software is Copyright (c) 2011 by John Beppu.
This is free software, licensed under:
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE, Version 2, December 2004
To install Term::Caca, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Term::Caca
CPAN shell
perl -MCPAN -e shell install Term::Caca
For more information on module installation, please visit the detailed CPAN module installation guide.