Reputation: 146
I'm using Term::ANSIColor along with Win32::Console::ANSI in Windows. I often use colored printing in my scripts to highlight some key info or whatever.
For the first time though, I'v tried something that works, but not quite how I would want it to.
What it looks like when I print on grey/white background:
And what I want is (edited to look the way I want it to print):
Thus I'm wondering if anyone knows how to go about ANSI escape sequences. Ho do I fill the entire piece that I'm printing on with a color and not just to the newline.
Also, here is my script (two ways I tried):
print color('bold blue on_white'), "\tnr\tisiNdebele\n";
print colored ['bold blue on_white'], "\tnso\tSepedi\n";
This isn't a major issue. I'm just wondering if someone knows how I can achieve this.
Upvotes: 5
Views: 754
Reputation: 54373
My solution uses Term::Size::Any to figure out how big the terminal is, and Text::Tabs to convert the \t
s into spaces. We need to do that because a tabulator is only one character wide, but gets converted to 4, or 8 or whatever number of spaces when printed out.
use strict;
use warnings;
use Term::Size::Any 'chars';
use Term::ANSIColor;
use Text::Tabs 'expand';
my ($columns, $rows) = chars;
sub full_background {
my ($text) = @_;
chomp $text;
return sprintf(qq{%-${columns}s}, expand($text)) . "\n";
}
print color('bold blue on_white'), full_background( "\tnr\tisiNdebele\n" );
print colored ['bold blue on_red'], full_background( "\tnso\tSepedi\n" );
Here's what it looks like.
Upvotes: 5