User Tools

Site Tools


perl:ansi_color

if you want to avoid installing Term::ANSIColor:

sub ansi {
	my ($c) = @_;
	if (!$c) { return "\e[m"; }
	my %colors = qw(
		reset       0
		bold        1
		underline   4
		inverse     7
		black      30
		red        31
		green      32
		yellow     33
		blue       34
		violet     35
		magenta    35
		cyan       36
		white      37
		on_black   40
		on_red     41
		on_green   42
		on_yellow  43
		on_blue    44
		on_violet  45
		on_magenta 45
		on_cyan    46
		on_white   47
	);
	my $r = join(';',map {$colors{$_}} split(/\W+/,$c));
	return length($r) ? "\e[${r}m" : '';
}
perl/ansi_color.txt · Last modified: 2009/09/04 09:20 by tkbletsc

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki