Allasso has asked for the wisdom of the Perl Monks concerning the following question:

Hello, Monks,

I would like to know how to do either (or both) of the following:

1)
change the background color of an entire terminal screen

2)
detect the default background color of a terminal screen the user is currently using.

yes, I can

use Term::ANSIColor;

but I am only able to change the bg color of the text that is printed. I want to change the whole screen.

else, if I can detect the default bg color that term window is using, then I can choose the colors I print out to be readable with that bg.

thanks much...

A

  • Comment on change/detect term screen background color

Replies are listed 'Best First'.
Re: change/detect term screen background color
by Khen1950fx (Canon) on Feb 19, 2011 at 18:48 UTC
    I don't know of any module that can simply and quickly change color. I usually just do a system call. That is the crux of the problem. There's so many different systems, consoles, terms, and whatever that it's a real pain to try and find a general way to do it. Here's a script that changes the bgcolor(fullscreen) to black and text color to bold green:
    #!/usr/bin/perl use strict; use warnings; # change bgcolor and text system("echo -e"\e[1;32;40m black"); sleep 5; # revert to original color system("echo -e "\e[0m");
    Here's a script that I use to get info about my terminal colors and capabilites:
    #!/usr/bin/perl use strict; use warnings; use Term::Cap; use Term::ExtendedColor qw(fg get_colors lookup); use Data::Dumper::Concise; my $termcap = Term::Cap->Tgetent({ Term => 'undef' }); print "Capabilities found: ", join(', ', sort(keys %{$termcap})), "\n" +; print Dumper(my $colors = get_colors()); for(0 .. 255) { my $color_str = lookup($_); if(defined($color_str)) { printf("%25s => %s\n", fg($color_str, $color_str), $_); } }

      Your first script didn't work for me, it only changes the bg of the text.

      also, there is an error in your code:
      system("echo -e"\e[1;32;40m black"); system("echo -e "\e[0m");

      should be something like:

      system("echo -e '\e[1;32;40m black'"); system("echo -e '\e[0m'");

        okay, it works if I add this after the color change:

        system("clear");
      Here's a script that changes the bgcolor(fullscreen) to black and text color to bold green
      It does no such thing. This code (your posted code):
      #!/usr/bin/perl use strict; use warnings; # change bgcolor and text system("echo -e"\e[1;32;40m black"); sleep 5; # revert to original color system("echo -e "\e[0m");
      doesn't even compile

      When posting untested code, please mark it as such.

      When posting tested code, please post the code that you actually ran.

      Shame on you. You should know better.