#!/usr/bin/perl -w

use strict;

$| = 1;

sub colorbars {
  # Print system colors

  for ( my $color = 0; $color < 8; $color++ ) {
    print "\x1b[48;5;${color}m  ";
  }
  print "\x1b[0m\n";
  for ( my $color = 8; $color < 16; $color++ ) {
    print "\x1b[48;5;${color}m  ";
  }
  print "\x1b[0m\n\n";  
}

print "Printing system colors: \n";
colorbars;

sleep 1;

# Set crazy colors

print "Changing system colors to red... ";
sleep 1;
for ( my $red = 0; $red < 16; $red++ ) {
  printf("\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\",
	 $red, $red * 16, 0, 0 );
}

print "done.\n\n";

print "The above (previously-printed) colors should now be red!\n";

sleep 2;

print "Now printing system colors again (should again be red): \n";
colorbars;

print "Now issuing hard reset.\n";

sleep 2;

printf( "\x1b" . "c" );

sleep 1;

print "Now printing system colors again (should be multihued): \n";
colorbars;
