Paul Miller > Term-ANSIColorx-ColorNicknames-2.7188 > Term::ANSIColorx::ColorNicknames

Download:
Term-ANSIColorx-ColorNicknames-2.7188.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 2.7188   Source  

NAME ^

Term::ANSIColorx::ColorNicknames - nicknames for the ANSI colors

SYNOPSIS ^

    # use Term::ANSIColor qw(color colorvalid);
    use Term::ANSIColorx::ColorNicknames qw(color colorvalid);

DESCRIPTION ^

I have a hard time remembering the ANSI colors in terms of bolds and regulars, and also find them irritating to type. If I want the color yellow, why should I have to type "bright_yellow" to get it? yellow is really orange colored, yellow should always be bold.

HOW THIS WORKS ^

In the past, this module used to replace the exports of the Term::ANSIColor package. I was under the impression I am the only user of this package, so I felt comfortable breaking backwards compatability with versions prior to 2.7187. Lemme know if I jacked up your codes, but please adapt to the new setup. The old stuff was pretty janky. Kinda cool scope hacking, but janky.

This module exports the following functions, which “override” the functions from Term::ANSIColor. They use the word “fix” instead of translate because it’s short, not because it’s a political statement about the ANSI definitions or Term::ANSIColor.

fix_color

Re-writes the (correct) ANSI color to the new nickname color. Additionally, it re-writes various easy to type natural language (or css feeling) punctuations.

    "bold blue" eq fix_color("sky")

    "bold white on_blue" eq fix_color("bold-white on blue")

Note that white is really "bold white" under this package. fix_color automatically fixes "bold bold white" should it come up by accident. Actually, it tries to do something predictable when you use bold/faint/dark/bright in any combination. It just uses the first one.

    "bold blue" eq fix_color("bold dark bold faint dark bold blue");
    "dark blue" eq fix_color("dark bold bold faint dark bold blue");

clear (aka normal aka unbold) is an exception to this rule. If clear (aka normal etc) is the only “color” in the color, then it stands, otherwise, it is removed — presuming that a reset is usually used after some color sequence anyway..

    "bold black" eq fix_color("coal");
    "black"      eq fix_color("normal coal");
    "clear"      eq fix_color("normal");

Which means, you get the following. Notice that we get \e[30m, not \e[0;30m like you might expect.

    say "result: "
    Data::Dump::dump([
        map { colored( " $_ ", $_ ) }

        "coal",
        "normal coal",
        "normal"

    ]);

    result: [
      "\e[1;30m coal \e[0m",
      "\e[30m normal coal \e[0m",
      "\e[0m clear \e[0m",
    ]

Additionally, fix_color uses the prototype _, so one can do this:

    @xlated = map{fix_color} qw(sky ocean blood umber);

which gives:

    ("bold blue", "cyan", "red", "bold red")

and of course, this:

    "bold blue" eq fix_color "sky";

Lastly, there's a secret code to disable the re-writing. If you decide you hate one of the nicknames, or just want to disable it for a single color, intoduce a bell character anywhere in the string.

    "bold black" eq fix_color "coal";
    "black" eq fix_color "\ablack";

(This makes more sense if you export /color below.

color

This is just an export of "color" in Term::ANSIColor. It runs /fix_color on the given string and then invokes Term::ANSIColor::color(). Additionally, color() is defined with the _ prototype, which means it can be invoked this way:

    say color "violet", "test test test test", color "reset"

Or like this:

    while(<$colorstream>) {
        chomp;
        print color if colorvalid;
        say "TEST: o rly? (color=$_)";
    }

    print color("reset");
colorvalid

Like above, this is just a _ prototyped and fix_color() translated export of "colorvalid" in Term::ANSIColor.

colored

Translated (but not _ prototyped) export of "colored" in Term::ANSIColor.

colorstrip

Boring re-import of "colorstrip" in Term::ANSIColor. This is not translated or prototyped.

uncolor

Boring re-import of "uncolor" in Term::ANSIColor. This is not translated or prototyped.

THE NICKNAMES ^

blood

Alias for the color red.

umber

Alias for bold red.

sky

Alias for bold blue.

ocean

Replaces the color cyan, which should be very bright.

lightblue

Alias for ocean.

cyan

Cyan is the bold of the ocean. It's a bright cyan color.

lime

Bolded green. It's really a lime color.

orange brown

Orange. Most correctly, what ANSI calls "yellow", but is really more of a brown-orange.

yellow

Yellow. Technically bolded yellow.

purple

Alias for magenta. I can never remember which is right, probably thanks to CSS.

violet

Bolded purple.

pink

Bolded purple.

pitch coal

Bolded black.

grey gray

Unbolded white.

white

Bolded white.

dire

Scary yellow on red warning color.

alert

Scary white on red color.

todo

Iconic black on orange todo coloring.

mc_dir nc_dir

The white on blue directory coloring from Midnight Commander.

mc_file nc_file

The grey on blue file coloring.

mc_exe nc_exe mc_exec nc_exec

The lime on blue executable coloring.

mc_curs nc_curs

The cursor bar black on cyan coloring.

mc_pwd nc_pwd mc_cwd nc_cwd

The black on white coloring of the current directory on the current panel.

normal unbold un-bold

I can never remember that clear is un-bold or normal. dark and bright work ratehr like bold and clear, except that they don't work from real text consoles (they're really half-bold and extra-bold).

FAQ ^

    Q: This is dumb.
    A: Yeah. OK, you have a point. Sorry?

REPORTING BUGS ^

You can report bugs either via rt.cpan.org or via the issue tracking system on github. I'm likely to notice either fairly quickly.

AUTHOR ^

Paul Miller <jettero@cpan.org>

COPYRIGHT ^

Copyright 2014 Paul Miller -- released under the GPL

SEE ALSO ^

perl(1), Term::ANSIColor

syntax highlighting: