#!/usr/bin/perl ## ## (c) th(at)bogus.net 2004, simple curses test in perl ## use Curses; InitScreen(); $SIG{'INT'}=sub { Quit("Caught SIGINT, quitting..") }; $SIG{'WINCH'}=sub { InitScreen(); }; # catch this if user resizes screen my($timeout)=100; #milliseconds $x=0; $y=0; ## main() ## while(1) { ## check for keyboard presses while ((my($key)=getch()) ne ERR) { Quit("Done.") if $key eq 'q'; last if $key; } $x++; addstr($win1,$LINES/2,$COLS/4-(length("$x")/2),' ' x length("$x")); addstr($win1,$LINES/2,$COLS/4-(length("$x")/2),$x); addstr($win2,$LINES/2,$COLS/4-(length("$x")/2),' ' x length("$x")); addstr($win2,$LINES/2,$COLS/4-(length("$x")/2),$x*2); refresh($win1); refresh($win2); napms($timeout); box($win1,"|","-"); box($win2,"|","-"); } ## all done? ## sub Quit { curs_set(1); echo(); endwin(); print @_,"\n"; exit(0); } ## initialise the screen ## sub InitScreen { endwin() if($win1); initscr(); noecho(); curs_set(0); cbreak(); nonl(); nodelay(1); ## not really needed for this test program Quit("Need 40 char or wider screen.") if($COLS < 40); Quit("Need 15 line or taller screen.") if($LINES < 15); ## set up two windows side by side ## $win1=newwin($LINES,($COLS/2-1),0,0); $win2=newwin($LINES,($COLS/2-1),0,$COLS/2); }