Dotfiles, utilities, and other apparatus.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB

13 years ago
  1. #!/usr/bin/perl
  2. use strict;
  3. # taken from: http://www.steike.com/code/xterm-colors/
  4. # The command line arguments are:
  5. # xtfix 004000 set bgcol to greenish
  6. # xtfix 000000 555555 set bgcol to a random color between the two given values
  7. # xtfix -r reset the terminal (useful after 'cat /bin/sh' :-)
  8. # xtfix -f4 choose font size (3-6 are ok)
  9. # Default args (subtle random shade, reset, font 4):
  10. my $args = "@ARGV" || "080808 202020 -r -f4";
  11. # Basic color map, feel free to edit:
  12. my @cols = qw(000000 cc6666
  13. 33cc66 cc9933
  14. 3366cc cc33cc
  15. 33cccc cccccc
  16. 666666 ff6666
  17. 66ff66 ffff66
  18. 6699ff ff66ff
  19. 33ffff ffffff);
  20. # Full reset
  21. print "\033c" if $args =~ s/-r//;
  22. # Select font
  23. print "\033]50;#$1\007" if $args =~ s/-f(\d)//;
  24. # Parse the 'black' value
  25. my @ofs = map hex, $args =~ /([0-9a-f]{2})/gi;
  26. if(@ofs>3) {
  27. $ofs[$_] = $ofs[$_] + rand($ofs[$_+3]-$ofs[$_])
  28. for 0..2;
  29. }
  30. for my $i(0..15) {
  31. my $c = $cols[$i];
  32. my $Z;
  33. $c =~ s{..}{
  34. my $a = hex $&;
  35. my $b = $ofs[$Z++];
  36. sprintf("%02x", $a + $b - ($a*$b)/255);
  37. }ge;
  38. printf "\033[%d;3%dm(%d)", $i/8, $i&7, $i if $args =~ /show/;
  39. print "\033]4;$i;#$c\007";
  40. print "\033]11;#$c\007" if !$i; # 0 is also 'background color'
  41. print "\033]10;#$c\007" if $i==7; # 7 is also 'plain foreground color'
  42. }