box-o-sand/PracticingCurses/perl/09.pl

48 lines
891 B
Perl
Raw Normal View History

2009-11-19 00:01:16 +00:00
#!/usr/bin/perl
#
# Copyright (C) 2003 by Virtusa Corporation
# http://www.virtusa.com
#
# Anuradha Ratnaweera
# http://www.linux.lk/~anuradha/
#
use Curses;
initscr();
unless (has_colors()) {
endwin();
print "Your terminal does not support color\n";
exit 1;
}
start_color();
init_pair(1, COLOR_RED, COLOR_BLACK);
attron(COLOR_PAIR(1));
print_in_middle(stdscr, $LINES / 2, 0, 0, "Viola !!! In color ...");
attroff(COLOR_PAIR(1));
getch();
endwin();
sub print_in_middle {
$win = shift;
$starty = shift;
$startx = shift;
$width = shift;
$string = shift;
$win = stdscr unless ($win);
getyx($win, $y, $x);
2009-11-19 00:01:16 +00:00
$x = $startx if ($startx);
$y = $starty if ($starty);
$width = $COLS unless ($width);
$length = length($string);
$temp = ($width - $length) / 2;
$x = $startx + $temp;
addstr($y, $x, $string);
refresh();
}