App-colorxform

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


    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:

     % ledger -f myledger.dat --color --force-color balance | colorxform -P ledger

    You can create a shell alias for convenience:

     % function ledger() { C<which ledger> --color --force-color "$@" | colorxform -P ledger; }

    so you can just issue this to get the colors transformed:

README  view on Meta::CPAN

     % 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").

    Returns an enveloped result (an array).

    First element (status) is an integer containing HTTP status code (200
    means OK, 4xx caller error, 5xx function error). Second element (msg) is
    a string containing error message, or 'OK' if status is 200. Third
    element (result) is optional, the actual result. Fourth element (meta)
    is called result metadata and is optional, a hash that contains extra
    information.

lib/App/colorxform.pm  view on Meta::CPAN

sub _color_name_to_fg_code {
    my $name = lc(shift);
    if    ($name eq 'black'       ) { return 30 }
    elsif ($name eq 'red'         ) { return 31 }
    elsif ($name eq 'green'       ) { return 32 }
    elsif ($name eq 'yellow'      ) { return 33 }
    elsif ($name eq 'blue'        ) { return 34 }
    elsif ($name eq 'magenta'     ) { return 35 }
    elsif ($name eq 'cyan'        ) { return 36 }
    elsif ($name eq 'white' || $name eq 'grey' || $name eq 'gray') { return 37 }
    elsif ($name =~ /\A(bold|bright) black\z/   ) { return 90 }
    elsif ($name =~ /\A(bold|bright) red\z/     ) { return 91 }
    elsif ($name =~ /\A(bold|bright) green\z/   ) { return 92 }
    elsif ($name =~ /\A(bold|bright) yellow\z/  ) { return 93 }
    elsif ($name =~ /\A(bold|bright) blue\z/    ) { return 94 }
    elsif ($name =~ /\A(bold|bright) magenta\z/ ) { return 95 }
    elsif ($name =~ /\A(bold|bright) cyan\z/    ) { return 96 }
    elsif ($name =~ /\A(bold|bright) white\z/   ) { return 97 }
    undef;
}

sub _color_name_to_bg_code {
    my $code = _color_name_to_fg_code(@_);
    $code ? $code+10 : undef;
}

$SPEC{'colorxform'} = {
    v => 1.1,

lib/App/colorxform.pm  view on Meta::CPAN

    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:

    % ledger -f myledger.dat --color --force-color balance | colorxform -P ledger

You can create a shell alias for convenience:

    % function ledger() { `which ledger` --color --force-color "$@" | colorxform -P ledger; }

so you can just issue this to get the colors transformed:

lib/App/colorxform.pm  view on Meta::CPAN


_
    args => {
        fg_transforms => {
            schema => 'hash*',
            default => {},
            description => <<'_',

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
<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 = @_;

    my %codemaps;

lib/App/colorxform.pm  view on Meta::CPAN

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:

 % ledger -f myledger.dat --color --force-color balance | colorxform -P ledger

You can create a shell alias for convenience:

 % function ledger() { C<which ledger> --color --force-color "$@" | colorxform -P ledger; }

so you can just issue this to get the colors transformed:

lib/App/colorxform.pm  view on Meta::CPAN

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

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code
(200 means OK, 4xx caller error, 5xx function error). Second element
(msg) is a string containing error message, or 'OK' if status is
200. Third element (result) is optional, the actual result. Fourth
element (meta) is called result metadata and is optional, a hash

script/colorxform  view on Meta::CPAN

=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:

 % ledger -f myledger.dat --color --force-color balance | colorxform -P ledger

You can create a shell alias for convenience:

 % function ledger() { C<which ledger> --color --force-color "$@" | colorxform -P ledger; }

so you can just issue this to get the colors transformed:

script/colorxform  view on Meta::CPAN

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>

Default value:

 {}

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
<pm:Term::ANSIColor> (e.g. `blue` or `bold blue`).


=back

=head2 Configuration options

=over

=item B<--config-path>=I<filename>, B<-c>



( run in 1.257 second using v1.01-cache-2.11-cpan-c333fce770f )