Using Perl Ansi color to tint the entire screen

I am using Term :: ANSIColor along with Win32 :: Console :: ANSI on Windows. I often use color printing in my scripts to highlight some key information or something else.

For the first time, though, I tried something that works, but not quite the way I would like it to.

What it looks like when I print on a gray / white background:

What does it look like

And I want (edited to see how I want to print it):

How it should look

So, I am wondering if anyone knows how to use ANSI escape sequences. Ho, I’m filling in the entire fragment that I am printing with color, and not just with a new line.

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 is not a serious problem. I'm just wondering if anyone knows how I can achieve this.

+4
1

Term::Size::Any, , , Text::Tabs, \t . , , 4 8 .

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" );

.

enter image description here

+4

Source: https://habr.com/ru/post/1654022/


All Articles