• Stars
    star
    17
  • Rank 1,257,181 (Top 25 %)
  • Language
    Perl
  • Created about 14 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Color screen output using extended escape sequences

NAME

Term::ExtendedColor - Color screen output using 256 colors

SYNOPSIS

use Term::ExtendedColor qw(:all);

# Or use the 'attributes' tag to only import the functions for setting
# attributes.
# This will import the following functions:

# fg(), bg(), bold(), underline(), inverse(), italic(), clear()
use Term::ExtendedColor ':attributes';

## Foreground colors

my $red_text = fg('red2', 'this is in red');
my $spring   = fg('springgreen3', 'this is green');

## Background colors

print bg('red5', "Default foreground text on dark red background"), "\n";
my $red_on_green = fg('red3', bg('green12', 'Red text on green background'));
print "$red_on_green\n";

## Fall-through attributes

Term::ExtendedColor::autoreset(0);
my $bold  = fg('bold', 'This is bold');
my $red   = fg('red2', 'This is red... and bold');
my $green = bg('green28', 'This is bold red on green background');

# Make sure to clear all attributes when autoreset turned OFF,
# or else the users shell will be messed up

my $clear = clear();
print "$bold\n";
print "$red\n";
print "$green $clear\n";

## Non-color attributes

# Turn on autoreset again
Term::ExtendedColor::autoreset(1);

for(qw(italic underline blink reverse bold)) {
  print fg($_, $_), "\n";
}

# For convenience

my $bolded = bold("Bold text!");
my $italic = italic("Text in italics!");

## Remove all attributes from input data
my @colored;
push(@colored, fg('bold', fg('red2', 'Bold and red')));
push(@colored, fg('green13', fg('italic', 'Green, italic')));

print "$_\n" for @colored;
print "$_\n" for uncolor(@colored);

DESCRIPTION

Term::ExtendedColor provides functions for sending so called extended escape sequences to the terminal. This ought to be used with a 256-color compatible terminal; see the NOTES section for a matrix of terminal emulators currently supporting this.

EXPORTS

None by default.

Two tags are provided for convience:

# Import all functions
use Term::ExtendedColor qw(:all);

# Import functions for setting attributes
# fg(), bg(), bold(), italic(), underline(), inverse(), clear()
use Term::ExtendedColor qw(:attributes);

FUNCTIONS

fg($color, $string)

my $green = fg('green2', 'green foreground');
my @blue  = fg('blue4',  ['takes arrayrefs as well']);

my $x_color = fg('mediumorchid1', 'Using mappings from the X11 rgb.txt');

my $arbitary_color = fg(4, 'This is colored in the fifth ANSI color');

my $raw_seq = fg('38;5;197;48;5;53;1;3;4;5;7', 'this works too');

Set foreground colors and attributes.

See "COLORS AND ATTRIBUTES" for valid first arguments. Additionally, colors can be specified using their index value:

my $yellow = fg(220, 'Yellow');

If the internal $AUTORESET variable is non-zero (default), every element in the list of strings will be wrapped in escape sequences in such a way that the requested attributes will be set before the string and reset to defaults after the string.

Fall-through attributes can be enabled by setting $AUTORESET to a false value.

Term::ExtendedColor::autoreset( 0 );
my $red   = fg('red1', 'Red');
my $green = fg('green1', 'Green');

print "Text after $red is red until $green\n";
print "Text is still green, ", bold('and now bold as well!');

# If you exit now without resetting the colors and attributes, chances are
# your prompt will be messed up.

clear(); # All back to normal

If an invalid attribute is passed, the original data will be returned unmodified.

If no attribute is passed, thrown an exception.

bg($color, $string)

my $green_bg = bg('green4', 'green background');
my @blue_bg  = bg('blue6',  ['blue background']);

Like fg(), but sets background colors.

uncolor($string) | uncolour($string)

my $stripped = uncolor($colored_data);
my @no_color = uncolor(\@colored);
my @no_color = uncolor(@colored);

Remove all attribute and color escape sequences from the input.

See uncolor for a command-line utility using this function.

get_colors() | get_colours()

my $colors = get_colors();

Returns a hash reference with all available attributes and colors.

clear()

When called in scalar context, returns the escape sequence that resets all attributes to their defaults.

When called in void context, prints it directly.

autoreset()

Turn autoreset on/off. Enabled by default.

Term::ExtendedColor::autoreset( 0 ); # Turn off autoreset

bold(\@data)

Convenience function that might be used in place of fg('bold', \@data);

When called without arguments, returns a a string that turns off the bold attribute.

italic(\@data)

Convenience function that might be used in place of fg('italic', \@data);

When called without arguments, returns a a string that turns off the italics attribute.

underline(\@data)

Convenience function that might be used in place of fg('underline', \@data);

When called without arguments, returns a a string that turns off the underline attribute.

inverse(\@data)

Reverse video / inverse. Convenience function that might be used in place of fg('inverse', \@data);

When called without arguments, returns a a string that turns off the inverse attribute.

NOTES

The codes generated by this module complies to the extension of the ANSI colors standard first implemented in xterm in 1999. The first 16 color indexes (0 - 15) is the regular ANSI colors, while index 16 - 255 is the extension. Not all terminal emulators support this extension, though I've had a hard time finding one that doesn't. :)

Terminal    256 colors
----------------------
aterm               no
eterm              yes
gnome-terminal     yes
konsole            yes
lxterminal         yes
mrxvt              yes
roxterm            yes
rxvt                no
rxvt-unicode       yes *
sakura             yes
terminal           yes
terminator         yes
vte                yes
xterm              yes
iTerm2             yes
Terminal.app        no

GNU Screen         yes
tmux               yes
TTY/VC              no

* Previously needed a patch. Full support was added in version 9.09.

There's no way to give these extended colors meaningful names.

Our first thought was to map them against some standard color names, like those in the HTML 4.0 specification or the SVG one. They didn't match.

Therefore, they are named by their base color (red, green, magenta) plus index; The first index (always 1) is the brightest shade of that particular color, while the last index is the darkest.

It's also possible to use some X color names, as defined in rgb.txt. Do note that the color values do not match exactly; it's just an approximation.

A full list of available colors can be retrieved with get_colors(). See "COLORS AND ATTRIBUTES" for full list. All mapped colors can also be retrieved programmatically with get_colors().

COLORS AND ATTRIBUTES

Attributes

reset, clear, normal        reset all attributes
bold, bright                bold or bright, depending on implementation
faint                       decreased intensity (not widely supported)
italic, cursive             italic or cursive
underline, underscore       underline
blink                       slow blink
blink_ms                    rapid blink (only supported in MS DOS)
reverse, inverse, negative  reverse video
conceal                     conceal, or hide (not widely supported)

Standard color map

FIRST       LAST

red1        red5
blue1       blue17
cyan1       cyan24
gray1       gray24
green1      green28
orange1     orange5
purple1     purple30
yellow1     yellow18
magenta1    magenta26

X color names

aquamarine1
aquamarine3
blueviolet
cadetblue1
cadetblue2
chartreuse1
chartreuse2
chartreuse3
chartreuse4
cornflowerblue
cornsilk1
darkblue
darkcyan
darkgoldenrod
darkgreen
darkkhaki
darkmagenta1
darkmagenta2
darkolivegreen1
darkolivegreen2
darkolivegreen3
darkolivegreen4
darkolivegreen5
darkorange3
darkorange4
darkorange1
darkred1
darkred2
darkseagreen1
darkseagreen2
darkseagreen3
darkseagreen4
darkslategray1
darkslategray2
darkslategray3
darkturquoise
darkviolet
deeppink1
deeppink2
deeppink3
deeppink4
deepskyblue1
deepskyblue2
deepskyblue3
deepskyblue4
deepskyblue4
dodgerblue1
dodgerblue2
dodgerblue3
gold1
gold3
greenyellow
grey0
grey100
grey11
grey15
grey19
grey23
grey27
grey30
grey3
grey35
grey37
grey39
grey42
grey46
grey50
grey53
grey54
grey58
grey62
grey63
grey66
grey69
grey70
grey74
grey7
grey78
grey82
grey84
grey85
grey89
grey93
honeydew2
hotpink2
hotpink3
hotpink
indianred1
indianred
khaki1
khaki3
lightcoral
lightcyan1
lightcyan3
lightgoldenrod1
lightgoldenrod2
lightgoldenrod3
lightgreen
lightpink1
lightpink3
lightpink4
lightsalmon1
lightsalmon3
lightsalmon3
lightseagreen
lightskyblue1
lightskyblue3
lightskyblue3
lightslateblue
lightslategrey
lightsteelblue1
lightsteelblue3
lightsteelblue
lightyellow3
mediumorchid1
mediumorchid3
mediumorchid
mediumpurple1
mediumpurple2
mediumpurple3
mediumpurple4
mediumpurple
mediumspringgreen
mediumturquoise
mediumvioletred
mistyrose1
mistyrose3
navajowhite1
navajowhite3
navyblue
orangered1
orchid1
orchid2
orchid
palegreen1
palegreen3
paleturquoise1
paleturquoise4
palevioletred1
pink1
pink3
plum1
plum2
plum3
plum4
purple
rosybrown
royalblue1
salmon1
sandybrown
seagreen1
seagreen2
seagreen3
skyblue1
skyblue2
skyblue3
slateblue1
slateblue3
springgreen1
springgreen2
springgreen3
springgreen4
steelblue1
steelblue3
steelblue
tan
thistle1
thistle3
turquoise2
turquoise4
violet
wheat1
wheat4

In addition, it's also possible to pass raw color;attr strings like so:

my $foo = fg('48;5;89;38;5;197;1;3;4;7', 'foo');

Even though the fg() function is used, we set the following attributes:

background => 89
foreground => 197
bold
italic
underline
reverse

SEE ALSO

Term::ExtendedColor::Xresources Term::ExtendedColor::TTY Term::ANSIColor

AUTHOR

Magnus Woldrich
CPAN ID: WOLDRICH
[email protected]
http://github.com/trapd00r
http://japh.se

CONTRIBUTORS

Varadinsky

COPYRIGHT

Copyright 2010, 2011, 2018, 2019- the Term::ExtendedColor "AUTHOR" and "CONTRIBUTORS" as listed above.

LICENSE

This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

More Repositories

1

LS_COLORS

A collection of LS_COLORS definitions; needs your contribution!
Shell
1,987
star
2

ls--

ls on steroids
Perl
496
star
3

vidir

edit directory in $EDITOR (better than vim . with netrw)
Perl
173
star
4

zsh-syntax-highlighting-filetypes

zsh syntax highlighting with dircolors in realtime
Shell
147
star
5

configs

My ~/etc - configs, dotfiles
Vim Script
115
star
6

utils

Small useful utilities for everyday work
Perl
74
star
7

neverland-vim-theme

256 colors CLI and GUI. It doesn't suck.
Vim Script
66
star
8

win95-winxp_icons

default icons from win{95,98,2000,xp}
48
star
9

colorcoke

Change the extended (non-ANSI) color set. Generate tints and shades that can be applied in any range.
Shell
45
star
10

vimpoint

Damian Conway's presentation system, written in viml
39
star
11

vim-syntax-vidir-ls

dircolors in your vidir session
Vim Script
36
star
12

File-LsColor

Colorize input filenames just like ls(1) does
Perl
34
star
13

pimpd2

Perl Interface for the Music Player Daemon 2 | http://search.cpan.org/dist/App-Pimpd/
Perl
34
star
14

screenfo

Screenshot info tool
Perl
31
star
15

clipbored

Daemon that continuously collects all selections in Xorg's clipboard buffers and saves them in a plaintext file for later retrieval. Can be used with dmenu.
Perl
30
star
16

rmshit

Keep $HOME or other dir clean from unwanted tempfiles, configs and other crap you'll never use that's autocreated upon execution of bad behaving applications
Perl
26
star
17

ttycolor

Quickly switch colorscheme in the Linux Console / TTY
Perl
24
star
18

xkcd

View XKCD comics in your console
Perl
20
star
19

pickyfont

Change your console/terminal font on the fly
Perl
17
star
20

Documentation

Docs and notes for Vim, Zsh, Git, Terminal emulators, Perl ... that I've either written or collected over time
Vim Script
17
star
21

vimcat

cat files in style with vim
Shell
14
star
22

hr

<hr> for your terminal; define a thematic change in content
Perl
13
star
23

pnfo

Vim NFO Viewer
Perl
12
star
24

id3shit

Less sucky commandline-based ID3-editor.
Perl
12
star
25

rmcd

Run mplayer as a daemon and control it remotely
Perl
10
star
26

Term-ExtendedColor-Xresources

Query and set various X resources
Perl
7
star
27

irc.vim

syntax file for irc logs
Vim Script
7
star
28

vim-after-syntax-vim

after/syntax/vim.vim
Vim Script
6
star
29

vim-extendedcolors

Highlight extended color name strings with their color (vim)
Vim Script
6
star
30

time-spent-in-vim

Vim wrapper collecting statistics of the usage; time spent per project/file
Perl
6
star
31

rxvt-unicode

urxvt fork with support for defining colors > 16 using X resources
C
5
star
32

colortest-256-ng

prints table of available colors or colorize arbitary input for terminals supporting 256 colors
Perl
5
star
33

vim-highlight-default-highlight-groups

Highlight all the default highlighting groups in Vim by matching the group's literal name and placing it in its group (colorscheme preview)
Vim Script
5
star
34

dzen-scripts

Various scripts for dzen2
Perl
4
star
35

re.pl

Read, Eval, Print, Loop with tabcompletion
Perl
4
star
36

n900

scripts controlling the n900
Shell
4
star
37

x11colors.vim

Highlight X11 color name strings with appropriate colors (vim, gvim)
Vim Script
4
star
38

RPD

Radio Playing Daemon - Daemon that plays radio streams, using Mplayer as the backend.
Perl
4
star
39

fileutils-color

basic file management utils with color
Perl
4
star
40

vim-after-syntax-perl

after/syntax/perl.vim
Vim Script
4
star
41

rgbterm

Show RGB values of defined terminal colors
Perl
4
star
42

vim-xclipboard

Yank text from Vim to the X clipboard transparently
Perl
4
star
43

uberpaint

fork of uberpaint, a Deluxe Paint clone, patched for building on linux
C
3
star
44

pimpd

Perl Interface for the Music Player Daemon
Perl
3
star
45

currentline.vim

A Vim plugin that highlights the current line; like a marker pen
Vim Script
3
star
46

cgrep

grep with colors without the grep
Perl
3
star
47

accesstail

like tail -f, but prettier, for your access.log
Perl
3
star
48

sdorfehs-config

configuration and scripts for the sdorfehs window manager
Perl
3
star
49

vim-syntax-todo

Simple syntax file for TODO lists
Vim Script
3
star
50

sexpac

Makes the Archlinux package manager 'pacman' sexy. Well, at least her output.
Perl
3
star
51

vim

wim
C
2
star
52

ratpoison_hacks

hacks and utilities relevant for (c|r)atpoison
Perl
2
star
53

trapd00r.se

My personal site
Python
2
star
54

firefox-remote

Control Mozilla Firefox remotely
Perl
2
star
55

programmers_qwerty

Make characters often used in programming, Vim and the shell more accessible
Perl
2
star
56

themes

Random themes for applications / pages
CSS
2
star
57

matrix

C
2
star
58

beet2mpd

beets advanced queries -> mpd
Perl
2
star
59

apt-cache-search-color

Β·
Perl
2
star
60

makedist

make perl distribution making automatic
Perl
2
star
61

vim-syntax-ratpoison

An updated version of ratpoison.vim
Vim Script
2
star
62

pamixer

curses interface for pulseaudio, personal fork
Python
2
star
63

vim-formatprg

A collection of useful formatprg's for Vim
2
star
64

Term-ExtendedColor-TTY

Functions for changing and querying the TTY for various resources, such as colors
Perl
2
star
65

vimpager-perlmod

Use VIM as a PAGER. Custom syntax file for perldoc.
Vim Script
2
star
66

github-clone-all

clone all GITHUB_USER repos and gists in one go
Shell
2
star
67

pentadactyl-neverland

Neverland colorscheme for Pentadactyl
2
star
68

vim-syntax-github-recent

Vim syntax file for the Github (dashboard|recent) feed
Vim Script
2
star
69

windows

Shell
1
star
70

perl-test-suite

My tests, the base suite for all projects
Perl
1
star
71

SeTTY

Set terminal properties in XTerm compatible terminals
Perl
1
star
72

String-Utils

Perl
1
star
73

dontbeahero

Don't worry, someone else will save the planet
Perl
1
star
74

App-sync_cpantesters

Sync CPAN testers failure reports to local directories
Perl
1
star
75

with

Execute Perl code on files matching pattern
Perl
1
star
76

urxvt-change-bg-on-focus-event

change bg color on focus lost/gained
Perl
1
star
77

cc256

C
1
star
78

picam

RPi based surv cam that autoposts on twitter
Perl
1
star
79

abs

Archlinux ABS Git
C
1
star
80

File-Media-Sort

Perl Module that sorts a list of incoming names as music/musicvideos/tv-episodes etc
Perl
1
star
81

Term-hr

Perl module that lets you define a thematic change in content of a terminal session
Perl
1
star
82

rel

rel uses Flexget::Parse, Flexget::PatternMatch and Media::Sort to show and sort new media in log/dir by genre/type etc
1
star
83

zcompdef

zsh completion definitions
1
star
84

Mplayer-NowPlaying

Query a running mplayer process for metadata and other information
Perl
1
star
85

Daemon-Mplayer

Library that helps you run mplayer daemonized
Perl
1
star
86

99-Problems

99 Prolog problems in Perl
Perl
1
star
87

Acme-CPANAuthors-Swedish

We are swedish CPAN authors
Perl
1
star
88

Acme-DependOnEverything

depend on everything
Perl
1
star
89

configs-n950

configs and random hacks for the nokia n950
Shell
1
star
90

mpdcp

copy track or album from an mpd server to destination
Perl
1
star
91

perlinpython3

how to access the power of perl inside your python3 code
Python
1
star
92

cv

my cv
CSS
1
star
93

Yoghurt

Yoghurt is a fork of Yaourt for personal use only
Shell
1
star
94

vim-after-syntax-zsh

Vim Script
1
star
95

git-today

what did I accomplish today?
Perl
1
star
96

mpdmon-daemon

Monitor MPD and execute arbitary commands on song change
Perl
1
star
97

xterm2html

xterm colors visual representation in html
Perl
1
star
98

vim-how-many-times-do-i-write-a-day

how many times do you :w a day?
Perl
1
star
99

Mock-Person-SV

Generate random sets of Swedish names
Perl
1
star
100

github-neverland

Dark Github theme for the Firefox/Chrome extension Stylish
1
star