App-Colorist
view release on metacpan or search on metacpan
lib/App/Colorist/Colorizer.pm view on Meta::CPAN
=head2 selected_inputs
This is an L<IO::Select> built from the list of input file handles in L</inputs>.
=head2 input_buffers
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.
=head2 output
This is the fil ehandle to use for output. A builder lazily sets this to C<STDOUT> by default.
=head2 search_path
This contains the full search path. You do not normally want to set this yourself, but use L</include> instead. It is lazily instantiated to includ the values set in L</include>, the value of the C<COLORIST_CONFIG> environment variable, followed by F...
=head2 ruleset_file
This is set to the name of the actual ruleset file found by searching L</search_paths> and L</ruleset>.
=head2 colorset_file
This is the actual colorset file found by searching L</search_paths> for C<colorset>.
=head2 colors_mtime
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.
=head2 colors
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 L<App::Colorist/CONFIGURATION> for details.
=head2 rules_mtime
Whenever the rules are loaded, this mtime is recorded. If the file changes, the rules are reloaded.
=head2 rules
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 a...
=head1 METHODS
=head2 load_colorset_file
Loads the colorset configuration using L<YAML>.
=head2 refresh_colorset_file
Checks to see if the L</colors> need to be reloaded and calls L</load_colorset_file> if they do.
=head2 load_ruleset_file
Reads in the ruleset configuration using a Perl C<do>.
=head2 refresh_ruleset_file
Checks to see if the ruleset file has changed since it's last load and calls L<load_ruleset_file> to reload the configuration if it has.
=head2 print_reset_line
Prints the escape code to reset everything to the terminal default.
=head2 get_fg
my $code = $c->get_fg(10);
Returns the escape code required to change the foreground color to the given color number.
=head2 get_bg
my $code = $self->get_bg(10);
Returns the escape code that will change the background color to the given color code.
=head2 gray
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.
=head2 rgb
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.
=head2 eval_color
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.
=head2 fg
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.
=head2 bg
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.
=head2 c
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.
=head2 run
Runs the colorization process to colorize input and send that to the output.
=head2 readline
Given an L<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.
=head2 loop_and_colorize
Reads each line of input, reloads the ruleset and colorset configuration if they have changed, and calls L</colorize> to add color to the input and send it to the output.
=head2 colorize
$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.
=head1 AUTHOR
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2015 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.
=cut
( run in 0.531 second using v1.01-cache-2.11-cpan-39bf76dae61 )