#!/usr/bin/perl ################ $| = 1; # No buffering plz. $SIG{INT} = \&sig; # Signal handler. $timeout = 0.20; # Timeout. $newline = 0; # Show newline on exit? $termwidth = 80; # Terminal Width? $color = "\e[0m"; $default_color = "\e[0m"; $command = ""; ################ sub sig { #~ Catches Interrupt Signals (defined above) print($default_color); if (!$newline) { print("\r" . " " x $termwidth . "\r"); } exit(); } sub bs { #~ The "backspace" routine. - scrolls everything #~ forward a bit. $str =~ s/^(.)(?{$f=$1;})//; $str .= $f; s/(\n|\t)/ /g; $str =~ s/(\n|\t)/ /g; s/$/$f/; s/^(.)//; if (length($_) > ($termwidth - 1)) { s/(.{$termwidth - 3}).*/$1\.\.\./; } print("\r" . " " x 80 . "\r"); $color = "\e[0m" if ($color eq "white"); $color = "\e[31m" if ($color eq "red"); $color = "\e[34m" if ($color eq "blue"); $color = "\e[32m" if ($color eq "green"); print("\r$color$_$default_color"); select(undef, undef, undef, $timeout); } sub init { #~ Load values ... map { if (/^--(.*)=(.*)/) { if (defined($$1)) { $$1 = $2; chomp($$1); } } elsif (/^--(.*)/) { if (defined($$1)) { $$1 = 1; } } } @ARGV; #~ Scroller initialization routine. $str = $_; $str =~ s/\n/ /g; s/\n/ /g; $_ = $"x($termwidth - 1); $str .= $"x($termwidth - 1 - length($str)); if (length($_) > ($termwidth - 1)) { s/(.{77}).*/$1\.\.\./; } print; } ################ #~ The main code if(defined($ARGV[0]) && $ARGV[0] ne "") { if ($ARGV[0] =~ /^--help/) { $| = 0; print("Use: $0 [--option[=value]]\n"); print("Options:\n"); print(" --timeout=\tThe timeout between each letter scroll. Default is 0.20\n"); print(" --newline\t\tMake a new line when exiting.\n"); print(" --color=\tColor the text this color. Default is \"white\"\n"); print(" \t\t\tColors: white, blue, red, green\n"); print(" --termwidth=\tThe terminal width. Default is 80\n"); print(" \t\t\tdo '--termwidth=`echo \$COLUMNS`' to autodetect\n"); print(" --command=\tA command to run every time the buffer is empty.\n"); print(" \t\t\tDefault is blank, which means no command. (just the\n"); print(" \t\t\ttext, over and over and over again.)\n"); exit(); } else { $_ = shift @ARGV; } } else { $_ = "Author: Smári P. McCarthy. Just Another Perl Hacker. E-mail: spm\@suse.eyjar.is Execute '$0 --help' for help. "; } init(); while(1) { for ($i = 0; $i < length($_); $i++) { bs(); } if ($command ne "") { $str = `$command` . " "; die("\nDead: Application '$command' not found, so I didn't know what to do.\n") if ($?); } }