Perl Advent Calendar 2007-12-18

Here we come a wascrolling

by Jerrad Pierce

You've all been good little boys and girls this year haven't you? Well, it's a special day regardless so you get your toy early this year: Acme::Curses::Marquee1. While Marquee is very easy to use, I've committed a faux-pas and essentially stolen the sample code form the POD. However, I did make some adapations, as well as discover a few fatal flaws in the code. You'll need to apply this patch I submitted in a bug report to get it working; I guess it really is an under-appreciated module, eh? I deviated from the script somewhat though. I started by removing the seemingly pointless call to getch(). This sent the marquee spinning like a top, at which point I realized I could lose hacky curses calls an employ Time::HiRes's usleep for more control over the scrolling speed.

If you'd like to get a feel for the results without the hassle of installing the module and it's dependencies, then patching it, you can view a movie on a vt100 comptaible terminal like so

kringle> slowcat.pl mod18.vt100

if some combination of stty and cat doesn't do the trick for you. You can adjust the speed by changing the baud rate (set to 3000 here), and after you've gone through all the trouble of downloading that line of code, or adjusting your TERM settings, you might be interested in some other holiday cheer.

Finally, here's a slightly more portable version of today's example that uses a pure perl implementation of FIGlet, by yours truly, and does not rely upon a binary being in your PATH: mod18b.pl.

mod18a.pl


   1 use Acme::Curses::Marquee;
   2 use Curses;
   3 use Time::HiRes 'usleep';
   4 
   5 #Set height and width of scroll area
   6 use constant {X=>80, Y=>9};
   7 
   8 #Start your engines
   9 initscr;
  10 
  11 #Create the scrolling area half-way down the standard terminal
  12 #Unfortunately, instantiating it in the marquee maker segfaults
  13 my $w = subwin(Y,X,8,0);
  14 
  15 #Make the marquee
  16 my $m = Acme::Curses::Marquee->new( window => $w,
  17                                     height => Y,
  18                                     width  => X,
  19                                     font   => 'larry3d', #Nyuck nyuck
  20                                     text   => 'Happy Birthday Perl!' );
  21 #Wheeeee!
  22 while (1) {
  23   usleep(75_000);
  24   $m->scroll;
  25 }

1. I've had an entry on my round tuit list to create an Acme::Curses::Marquee::Extensions module since I first stumbled across this little nugget when I was writing my first advent calendar two years ago.