Monday, July 2, 2012

How could you write colorful text on console in Windows?


#!C:/Perl/bin/perl -w

use Win32::Console;

my $CONSOLE = Win32::Console->new(STD_OUTPUT_HANDLE);

# Get current console colors
my $attr = $CONSOLE->Attr();

# Yellow text on green
$CONSOLE->Attr($FG_YELLOW | $BG_GREEN);
print "This is a test\n";

$CONSOLE->Attr($FG_GREEN | $BG_BLACK);
print "This is a test\n";

# Set console colors back to original
$CONSOLE->Attr($attr);

No comments :