App-colorxform
view release on metacpan or search on metacpan
0.002 2018-09-07 (PERLANCAR)
- [bugfix] Fix generated background code.
- [bugfix] Fix regex.
- [dist] Remove unnecessary dependency.
0.001 2018-09-07 (PERLANCAR)
- First, early release.
FUNCTIONS
colorxform
Usage:
colorxform(%args) -> [status, msg, result, meta]
Transform colors on the CLI.
Some CLI programs output horrible colors (e.g. hard to read on terminal
with black background) and the colors are either uncustomizable or
cumbersome to customize. This is where "colorxform" comes in. You pipe
the output and it will replace some colors with another, per your
specification.
An example, put this in your "~/.config/colorxform.conf":
[profile=ledger]
fg_transforms = {"blue":"#18b2b2", "red":"bold red"}
then:
so you can just issue this to get the colors transformed:
% ledger -f myledger.dat balance
This function is not exported.
Arguments ('*' denotes required arguments):
* bg_transforms => *hash* (default: {})
List of background colors to replace with other colors. You can
specify color using RGB code (e.g. "#123456") or color names like
those recognized by Term::ANSIColor (e.g. "blue" or "bold blue").
* fg_transforms => *hash* (default: {})
List of foreground colors to replace with other colors. You can
specify color code using RGB code (e.g. "#123456") or color names
like those recognized by Term::ANSIColor (e.g. "blue" or "bold
blue").
lib/App/colorxform.pm view on Meta::CPAN
my $code = _color_name_to_fg_code(@_);
$code ? $code+10 : undef;
}
$SPEC{'colorxform'} = {
v => 1.1,
summary => 'Transform colors on the CLI',
description => <<'_',
Some CLI programs output horrible colors (e.g. hard to read on terminal with
black background) and the colors are either uncustomizable or cumbersome to
customize. This is where `colorxform` comes in. You pipe the output and it will
replace some colors with another, per your specification.
An example, put this in your `~/.config/colorxform.conf`:
[profile=ledger]
fg_transforms = {"blue":"#18b2b2", "red":"bold red"}
then:
lib/App/colorxform.pm view on Meta::CPAN
code using RGB code (e.g. `#123456`) or color names like those recognized by
<pm:Term::ANSIColor> (e.g. `blue` or `bold blue`).
_
},
bg_transforms => {
schema => 'hash*',
default => {},
description => <<'_',
List of background colors to replace with other colors. You can specify color
using RGB code (e.g. `#123456`) or color names like those recognized by
<pm:Term::ANSIColor> (e.g. `blue` or `bold blue`).
_
},
},
};
sub colorxform {
my %args = @_;
lib/App/colorxform.pm view on Meta::CPAN
}
$codemaps{$code} = $xformcode;
}
for my $k (keys %{$args{bg_transforms}}) {
my $code;
{
$code = _color_name_to_bg_code($k);
last if defined $code;
# XXX support transforming 8-bit and 24-bit input colors
die "Unrecognized background color name/code '$k'";
}
my $xformcode;
{
my $v = $args{bg_transforms}{$k};
$xformcode = _color_name_to_bg_code($v);
last if defined $xformcode;
if ($v =~ /\A#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})\z/) {
$xformcode = sprintf "48;2;%d;%d;%d",
hex($1), hex($2), hex($3);
last;
}
die "Unrecognized background transform color name/code '$v'";
}
$codemaps{$code} = $xformcode;
}
my $transform = sub {
my $codes = shift;
my @codes;
while ($codes =~ /(38;2;[0-9]+;[0-9]+;[0-9]+|38;5;[0-9]+|[0-9]+)/g) {
push @codes, $1;
}
lib/App/colorxform.pm view on Meta::CPAN
=head2 colorxform
Usage:
colorxform(%args) -> [status, msg, result, meta]
Transform colors on the CLI.
Some CLI programs output horrible colors (e.g. hard to read on terminal with
black background) and the colors are either uncustomizable or cumbersome to
customize. This is where C<colorxform> comes in. You pipe the output and it will
replace some colors with another, per your specification.
An example, put this in your C<~/.config/colorxform.conf>:
[profile=ledger]
fg_transforms = {"blue":"#18b2b2", "red":"bold red"}
then:
lib/App/colorxform.pm view on Meta::CPAN
% ledger -f myledger.dat balance
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<bg_transforms> => I<hash> (default: {})
List of background colors to replace with other colors. You can specify color
using RGB code (e.g. C<#123456>) or color names like those recognized by
L<Term::ANSIColor> (e.g. C<blue> or C<bold blue>).
=item * B<fg_transforms> => I<hash> (default: {})
List of foreground colors to replace with other colors. You can specify color
code using RGB code (e.g. C<#123456>) or color names like those recognized by
L<Term::ANSIColor> (e.g. C<blue> or C<bold blue>).
=back
script/colorxform view on Meta::CPAN
=head1 SYNOPSIS
Usage:
% colorxform [options]
=head1 DESCRIPTION
Some CLI programs output horrible colors (e.g. hard to read on terminal with
black background) and the colors are either uncustomizable or cumbersome to
customize. This is where C<colorxform> comes in. You pipe the output and it will
replace some colors with another, per your specification.
An example, put this in your C<~/.config/colorxform.conf>:
[profile=ledger]
fg_transforms = {"blue":"#18b2b2", "red":"bold red"}
then:
script/colorxform view on Meta::CPAN
=item B<--bg-transforms-json>=I<s>
See C<--bg-transforms>.
=item B<--bg-transforms>=I<s>
Default value:
{}
List of background colors to replace with other colors. You can specify color
using RGB code (e.g. `#123456`) or color names like those recognized by
<pm:Term::ANSIColor> (e.g. `blue` or `bold blue`).
=item B<--fg-transforms-json>=I<s>
See C<--fg-transforms>.
=item B<--fg-transforms>=I<s>
( run in 2.243 seconds using v1.01-cache-2.11-cpan-f56aa216473 )