App::Colorist::Colorizer - the brain behind App::Colorist
version 0.141760
my $colorizer = App::Colorist::Colorizer->enw( commandset => 'mycommand', ); $colorizer->run;
This is primarily engineered as a separate module to make testing easier. However, if you want to embed a colorizer in some other program for some reason or you want to extend colorizer, this provides the tools for that as well. This is why I decided to provide documentation for this module here.
If you do provide extensions, I would love to see them. Patches are welcome.
This is the name of the master configuration to use. This is usually the name of the command whose output you are colorizing. Each configuration must contain at least one ruleset and one colorset configuration. See "CONFIGURATION" in App::Colorist for details on how this is used to locate the configuration files.
This is the name of the rule set to use. See "CONFIGURATION" in App::Colorist for how rule sets are defined and located.
This is the name of the color set to use. See "CONFIGURATION" in App::Colorist for how color sets are defined and located.
This is an array of extra include paths to search when looking for colorist configuration files.
This is mostly useful for testing the app itself. When set to a true value, the colors are not output but a numeric representation like "{12}" is output instead.
This is an array of file handles to use for input. A builder lazily sets this to an array containing only the ARGV file handle by default. If more than one file handle is passed, this will capture output of all file handles and display from each as they come.
ARGV
This is an IO::Select built from the list of input file handles in "inputs".
This is an array of strings used as input buffers. This is used with the non-blocking I/O code to store any partially read lines encountered.
This is the fil ehandle to use for output. A builder lazily sets this to STDOUT by default.
STDOUT
This contains the full search path. You do not normally want to set this yourself, but use "include" instead. It is lazily instantiated to includ the values set in "include", the value of the COLORIST_CONFIG environment variable, followed by ~/.colorist and finally /etc/colorist.
COLORIST_CONFIG
This is set to the name of the actual ruleset file found by searching "search_paths" and "ruleset".
This is the actual colorset file found by searching "search_paths" for colorset.
colorset
When the colorset file is loaded, this mtime is set to the current mtime of the file. Every time a line is colored it checks to see if the colorset file has changed and will reload it automatically if it has.
This is the actual colorset configuration. It's a set of keys naming the various color names defined in the ruleset and the values are the color definitions. See "CONFIGURATION" in App::Colorist for details.
Whenever the rules are loaded, this mtime is recorded. If the file changes, the rules are reloaded.
This contains the actual rules. This is an array where the even number indices point to a regular expression used to match lines and group submatches. The odd indices contain an array of names matching the overall match and the group matches, which are looked up in the "colors" configuration. See "CONFIGURATION" in App::Colorist for details.
Loads the colorset configuration using YAML.
Checks to see if the "colors" need to be reloaded and calls "load_colorset_file" if they do.
Reads in the ruleset configuration using a Perl do.
do
Checks to see if the ruleset file has changed since it's last load and calls load_ruleset_file to reload the configuration if it has.
Prints the escape code to reset everything to the terminal default.
my $code = $c->get_fg(10);
Returns the escape code required to change the foreground color to the given color number.
my $code = $self->get_bg(10);
Returns the escape code that will change the background color to the given color code.
my $number = $c->gray(10);
Given a number identifying the desired shade of gray, returns that color number. Only works on terminals supporting 256 colors.
my $number = $c->rgb(1, 3, 4);
Given 3 numbers identifying the desired RGB color cube, returns that color number. Only works on terminals supporting 256 colors.
my $number = $c->eval_color('blue'); my $number = $c->eval_color(10); my $number = $c->eval_color([ 8 ]); my $number = $c->eval_color([ 1, 2, 3 ]);
Given one of the possible color configuration types from the color set configuration, returns a color number for it.
my $code = $c->fg('blue'); my $code = $c->fg(10); my $code = $c->fg([ 8 ]); my $code = $c->fg([ 1, 2, 3 ]);
Returns the escape code for changing the foreground color to the given color identifier.
my $code = $c->bg('blue'); my $code = $c->bg(10); my $code = $c->bg([ 8 ]); my $code = $c->bg([ 1, 2, 3 ]);
Returns the escape code for changing the background color to the given color identifier.
my $code = $c->c('rufus');
Given the name of a color defined in the colorset, returns the escape codes defined for that color to change the background and foreground as configured.
Runs the colorization process to colorize input and send that to the output.
Given an IO::Select object, returns the first line it finds from the selected file handles. This handles all buffering on the file handles and blocks until a complete line is available. It returns only the first line that comes available. It makes no guarantees about the order the file handles will be read or processed. It does try to conserve memory and keep the buffers relatively small.
Reads each line of input, reloads the ruleset and colorset configuration if they have changed, and calls "colorize" to add color to the input and send it to the output.
$c->colorize('some input');
Given a line of input, this method matches the ruleset rules agains the line until it finds a match. It then applies all the colors for the line and groups defined in the colorset and outputs that line to the output file handle.
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
This software is copyright (c) 2014 by Qubling Software LLC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install App::Colorist, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::Colorist
CPAN shell
perl -MCPAN -e shell install App::Colorist
For more information on module installation, please visit the detailed CPAN module installation guide.