#! /usr/bin/perl -w # # file: banner-1.pl # purpose: try to write a scrolling banner # details: this script shows how to implement a scrolling banner # that will run in a xterm window. # # author: chad c d clark # created: 2006-05-21 # # based on the following code by Chris Angell: # perl -e'$|++; 1 while select("","","",.04), # print "\b", qw(/ - \ |)[$i++%4]' # # $Id$ use strict; use POSIX; # ceil() # my $MESG = "This is my test message. "; # my $SIZE = 70; # #my $SIZE = 10; # my $MESG = " " . `/usr/bin/w | /usr/bin/sed 2d`; chomp $MESG; # my $SIZE = 70; my $MESG = qq{ The reason I'm so excited is it looks like if you plot price against profit, you get a nice curve with a big hump in the middle! And we all know what humps mean! Humps mean local maxima! Or camels. But here they mean local maxima! - Joel Spolsky }; my $SIZE = 70; $|++; # do not buffer output I/O # remove "non-printable" characters (for example newlines) if ($MESG =~ s/[^[:print:]]/ /g) { print STDERR "$0: Warning removing non-printable characters from message.\n"; } my $offset = 0; # start at beginning of the message my $length = length $MESG; # get the length of the message # to simulate a circular buffer the idea is to append the message string # to itself until we have enough extra to cover the display window. my $mult = ceil( ($length + $SIZE) / $length ); $MESG = $MESG x $mult; print "Text: "; # prime the loop for the space where the message will be printed print " " x $SIZE; while (1) { # get a chunk of the message my $chunk = substr $MESG, $offset, $SIZE; # print the chunk over the the last iteration print "\b" x $SIZE, $chunk; select("","","",.15); # sleep for part of a second # advance/wrap the offset pointer if (++$offset >= $length) { $offset = 0 }; } exit(0);