a grand renaming so that the most significant portion of the name comes first
This commit is contained in:
17
curses-practice/perl/01.pl
Executable file
17
curses-practice/perl/01.pl
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Copyright (C) 2003 by Virtusa Corporation
|
||||
# http://www.virtusa.com
|
||||
#
|
||||
# Anuradha Ratnaweera
|
||||
# http://www.linux.lk/~anuradha/
|
||||
#
|
||||
|
||||
use Curses;
|
||||
|
||||
initscr();
|
||||
printw("Hello world!");
|
||||
refresh();
|
||||
getch();
|
||||
endwin();
|
||||
|
33
curses-practice/perl/02.pl
Executable file
33
curses-practice/perl/02.pl
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Copyright (C) 2003 by Virtusa Corporation
|
||||
# http://www.virtusa.com
|
||||
#
|
||||
# Anuradha Ratnaweera
|
||||
# http://www.linux.lk/~anuradha/
|
||||
#
|
||||
|
||||
use Curses;
|
||||
|
||||
initscr();
|
||||
raw();
|
||||
keypad(1);
|
||||
noecho();
|
||||
|
||||
printw("Type any character to see it in bold\n");
|
||||
$ch = getch();
|
||||
|
||||
if ($ch == KEY_F(1)) {
|
||||
printw("F1 Key pressed");
|
||||
}
|
||||
else {
|
||||
printw("The pressed key is ");
|
||||
attron(A_BOLD);
|
||||
printw($ch);
|
||||
attroff(A_BOLD);
|
||||
}
|
||||
|
||||
refresh();
|
||||
getch();
|
||||
endwin();
|
||||
|
23
curses-practice/perl/03.pl
Executable file
23
curses-practice/perl/03.pl
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Copyright (C) 2003 by Virtusa Corporation
|
||||
# http://www.virtusa.com
|
||||
#
|
||||
# Anuradha Ratnaweera
|
||||
# http://www.linux.lk/~anuradha/
|
||||
#
|
||||
|
||||
# We use addstr() instead of printw()
|
||||
|
||||
use Curses;
|
||||
|
||||
$mesg = "Just a string";
|
||||
|
||||
initscr();
|
||||
getmaxyx($row, $col);
|
||||
addstr($row / 2, ($col - length($mesg)) / 2, $mesg);
|
||||
addstr($row - 2, 0, "This screen has $row rows and $col columns\n");
|
||||
refresh();
|
||||
getch();
|
||||
endwin();
|
||||
|
23
curses-practice/perl/04.pl
Executable file
23
curses-practice/perl/04.pl
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Copyright (C) 2003 by Virtusa Corporation
|
||||
# http://www.virtusa.com
|
||||
#
|
||||
# Anuradha Ratnaweera
|
||||
# http://www.linux.lk/~anuradha/
|
||||
#
|
||||
|
||||
# We use addstr() instead of printw()
|
||||
|
||||
use Curses;
|
||||
|
||||
$mesg = "Enter a string: ";
|
||||
|
||||
initscr();
|
||||
getmaxyx($row, $col);
|
||||
addstr($row / 2, ($col - length($mesg)) / 2, $mesg);
|
||||
getstr($str);
|
||||
addstr($LINES - 2, 0, "You Entered: $str");
|
||||
getch();
|
||||
endwin();
|
||||
|
32
curses-practice/perl/05.pl
Executable file
32
curses-practice/perl/05.pl
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Copyright (C) 2003 by Virtusa Corporation
|
||||
# http://www.virtusa.com
|
||||
#
|
||||
# Anuradha Ratnaweera
|
||||
# http://www.linux.lk/~anuradha/
|
||||
#
|
||||
|
||||
# We first read all the input into an array and join
|
||||
# it to a single string with newlines.
|
||||
|
||||
use Curses;
|
||||
|
||||
initscr();
|
||||
|
||||
@lines = <>;
|
||||
$lines = join "", @lines;
|
||||
|
||||
while ($lines =~ /\G(.*?)(\/\*.*?\*\/)?/gs) {
|
||||
addstr($1);
|
||||
if ($2) {
|
||||
attron(A_BOLD);
|
||||
addstr($2);
|
||||
attroff(A_BOLD);
|
||||
}
|
||||
}
|
||||
|
||||
refresh();
|
||||
getch();
|
||||
endwin();
|
||||
|
22
curses-practice/perl/06.pl
Executable file
22
curses-practice/perl/06.pl
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Copyright (C) 2003 by Virtusa Corporation
|
||||
# http://www.virtusa.com
|
||||
#
|
||||
# Anuradha Ratnaweera
|
||||
# http://www.linux.lk/~anuradha/
|
||||
#
|
||||
|
||||
use Curses;
|
||||
|
||||
initscr();
|
||||
start_color();
|
||||
|
||||
init_pair(1, COLOR_CYAN, COLOR_BLACK);
|
||||
printw("A Big string which i didn't care to type fully ");
|
||||
chgat(0, 0, -1, A_BLINK, 1, NULL);
|
||||
|
||||
refresh();
|
||||
getch();
|
||||
endwin();
|
||||
|
58
curses-practice/perl/07.pl
Executable file
58
curses-practice/perl/07.pl
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Copyright (C) 2003 by Virtusa Corporation
|
||||
# http://www.virtusa.com
|
||||
#
|
||||
# Anuradha Ratnaweera
|
||||
# http://www.linux.lk/~anuradha/
|
||||
#
|
||||
|
||||
use Curses;
|
||||
|
||||
initscr();
|
||||
cbreak();
|
||||
keypad(1);
|
||||
|
||||
$height = 3;
|
||||
$width = 10;
|
||||
$starty = ($LINES - $height) / 2;
|
||||
$startx = ($COLS - $width) / 2;
|
||||
printw("Press F1 to exit");
|
||||
refresh();
|
||||
$my_win = create_newwin($height, $width, $starty, $startx);
|
||||
|
||||
while (($ch = getch()) != KEY_F(1)) {
|
||||
if ($ch == KEY_LEFT) {
|
||||
destroy_win($my_win);
|
||||
$my_win = create_newwin($height, $width, $starty, --$startx);
|
||||
}
|
||||
elsif ($ch == KEY_RIGHT) {
|
||||
destroy_win($my_win);
|
||||
$my_win = create_newwin($height, $width, $starty, ++$startx);
|
||||
}
|
||||
elsif ($ch == KEY_UP) {
|
||||
destroy_win($my_win);
|
||||
$my_win = create_newwin($height, $width, --$starty, $startx);
|
||||
}
|
||||
elsif ($ch == KEY_DOWN) {
|
||||
destroy_win($my_win);
|
||||
$my_win = create_newwin($height, $width, ++$starty, $startx);
|
||||
}
|
||||
}
|
||||
|
||||
endwin();
|
||||
|
||||
sub create_newwin {
|
||||
$local_win = newwin(shift, shift, shift, shift);
|
||||
box($local_win, 0, 0);
|
||||
refresh($local_win);
|
||||
return $local_win;
|
||||
}
|
||||
|
||||
sub destroy_win {
|
||||
$local_win = shift;
|
||||
border($local_win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
|
||||
refresh($local_win);
|
||||
delwin($local_win);
|
||||
}
|
||||
|
112
curses-practice/perl/08.pl
Executable file
112
curses-practice/perl/08.pl
Executable file
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Copyright (C) 2003 by Virtusa Corporation
|
||||
# http://www.virtusa.com
|
||||
#
|
||||
# Anuradha Ratnaweera
|
||||
# http://www.linux.lk/~anuradha/
|
||||
#
|
||||
|
||||
# We use %win hash to store window parameters
|
||||
|
||||
use Curses;
|
||||
|
||||
initscr();
|
||||
start_color();
|
||||
cbreak();
|
||||
|
||||
keypad(1);
|
||||
noecho();
|
||||
init_pair(1, COLOR_CYAN, COLOR_BLACK);
|
||||
|
||||
%win = ();
|
||||
init_win_params(\%win);
|
||||
print_win_params(\%win);
|
||||
|
||||
attron(COLOR_PAIR(1));
|
||||
printw("Press F1 to exit");
|
||||
refresh();
|
||||
attroff(COLOR_PAIR(1));
|
||||
|
||||
create_box(\%win, 1);
|
||||
|
||||
while (($ch = getch()) != KEY_F(1)) {
|
||||
if ($ch == KEY_LEFT) {
|
||||
create_box(\%win, 0);
|
||||
$win{'startx'}--;
|
||||
create_box(\%win, 1);
|
||||
}
|
||||
elsif ($ch == KEY_RIGHT) {
|
||||
create_box(\%win, 0);
|
||||
$win{'startx'}++;
|
||||
create_box(\%win, 1);
|
||||
}
|
||||
elsif ($ch == KEY_UP) {
|
||||
create_box(\%win, 0);
|
||||
$win{'starty'}--;
|
||||
create_box(\%win, 1);
|
||||
}
|
||||
elsif ($ch == KEY_DOWN) {
|
||||
create_box(\%win, 0);
|
||||
$win{'starty'}++;
|
||||
create_box(\%win, 1);
|
||||
}
|
||||
}
|
||||
|
||||
endwin();
|
||||
|
||||
sub init_win_params {
|
||||
$p_win = shift;
|
||||
|
||||
$$p_win{'height'} = 3;
|
||||
$$p_win{'width'} = 10;
|
||||
$$p_win{'starty'} = ($LINES - $p_win{'height'}) / 2;
|
||||
$$p_win{'startx'} = ($COLS - $p_win{'width'}) / 2;
|
||||
$$p_win{'ls'} = '|';
|
||||
$$p_win{'rs'} = '|';
|
||||
$$p_win{'ts'} = '-';
|
||||
$$p_win{'bs'} = '-';
|
||||
$$p_win{'tl'} = '+';
|
||||
$$p_win{'tr'} = '+';
|
||||
$$p_win{'bl'} = '+';
|
||||
$$p_win{'br'} = '+';
|
||||
}
|
||||
|
||||
sub print_win_params {
|
||||
if ($_DEBUG) {
|
||||
$p_win = shift;
|
||||
addstr(25, 0,
|
||||
"$$p_win{startx} $$p_win{starty} $$p_win{width} $$p_win{height}");
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
sub create_box {
|
||||
$p_win = shift;
|
||||
$bool = shift;
|
||||
|
||||
$x = $$p_win{'startx'};
|
||||
$y = $$p_win{'starty'};
|
||||
$w = $$p_win{'width'};
|
||||
$h = $$p_win{'height'};
|
||||
|
||||
if ($bool) {
|
||||
addch($y, $x, $$p_win{'tl'});
|
||||
addch($y, $x + $w, $$p_win{'tr'});
|
||||
addch($y + $h, $x, $$p_win{'bl'});
|
||||
addch($y + $h, $x + $w, $$p_win{'br'});
|
||||
hline($y, $x + 1, $$p_win{'ts'}, $w - 1);
|
||||
hline($y + $h, $x + 1, $$p_win{'bs'}, $w - 1);
|
||||
vline($y + 1, $x, $$p_win{'ls'}, $h - 1);
|
||||
vline($y + 1, $x + $w, $$p_win{'rs'}, $h - 1);
|
||||
}
|
||||
else {
|
||||
for ($j = $y; $j <= $y + $h; $j++) {
|
||||
for ($i = $x; $i <= $x + $w; $i++) {
|
||||
addch($j, $i, ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
refresh();
|
||||
}
|
||||
|
47
curses-practice/perl/09.pl
Executable file
47
curses-practice/perl/09.pl
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/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);
|
||||
|
||||
$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();
|
||||
}
|
||||
|
98
curses-practice/perl/10.pl
Executable file
98
curses-practice/perl/10.pl
Executable file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Copyright (C) 2003 by Virtusa Corporation
|
||||
# http://www.virtusa.com
|
||||
#
|
||||
# Anuradha Ratnaweera
|
||||
# http://www.linux.lk/~anuradha/
|
||||
#
|
||||
|
||||
use Curses;
|
||||
|
||||
$width = 30;
|
||||
$height = 10;
|
||||
$startx = 0;
|
||||
$starty = 0;
|
||||
|
||||
@choices = (
|
||||
"Choice 1",
|
||||
"Choice 2",
|
||||
"Choice 3",
|
||||
"Choice 4",
|
||||
"Exit"
|
||||
);
|
||||
|
||||
$n_choices = @choices;
|
||||
|
||||
$highlight = 1;
|
||||
$choice = 0;
|
||||
|
||||
initscr();
|
||||
clear();
|
||||
noecho();
|
||||
cbreak();
|
||||
$startx = ($COLS - $width) / 2;
|
||||
$starty = ($LINES - $height) / 2;
|
||||
|
||||
$menu_win = newwin($height, $width, $starty, $startx);
|
||||
keypad(1);
|
||||
keypad($menu_win, 1);
|
||||
addstr(0, 0, "Use arrow keys to go up and down, Press enter to select a choice");
|
||||
refresh();
|
||||
print_menu($menu_win, $highlight);
|
||||
|
||||
while (1) {
|
||||
$c = getch($menu_win);
|
||||
if ($c == KEY_UP) {
|
||||
if ($highlight == 1) {
|
||||
$highlight = $n_choices;
|
||||
}
|
||||
else {
|
||||
$highlight--;
|
||||
}
|
||||
}
|
||||
elsif ($c == KEY_DOWN) {
|
||||
if ($highlight == $n_choices) {
|
||||
$highlight = 1;
|
||||
}
|
||||
else {
|
||||
$highlight++;
|
||||
}
|
||||
}
|
||||
elsif ($c == '\n') {
|
||||
$choice = $highlight;
|
||||
}
|
||||
else {
|
||||
addstr($LINES - 2, 0, "Character pressed is $c");
|
||||
refresh();
|
||||
}
|
||||
print_menu($menu_win, $highlight);
|
||||
last if ($choice);
|
||||
}
|
||||
|
||||
addstr($LINES - 2, 0, "You chose choice $choice with choice string $choices[$choice-1]");
|
||||
clrtoeol();
|
||||
refresh();
|
||||
endwin();
|
||||
|
||||
sub print_menu {
|
||||
$menu_win = shift;
|
||||
$highlight = shift;
|
||||
|
||||
$x = 2;
|
||||
$y = 2;
|
||||
box($menu_win, 0, 0);
|
||||
for ($i = 0; $i < $n_choices; $i++) {
|
||||
if ($highlight == $i + 1) {
|
||||
attron($menu_win, A_REVERSE);
|
||||
addstr($menu_win, $y, $x, $choices[$i]);
|
||||
attroff($menu_win, A_REVERSE);
|
||||
}
|
||||
else {
|
||||
addstr($menu_win, $y, $x, $choices[$i]);
|
||||
}
|
||||
$y++;
|
||||
}
|
||||
refresh($menu_win);
|
||||
}
|
||||
|
2
curses-practice/perl/COPYING
Normal file
2
curses-practice/perl/COPYING
Normal file
@@ -0,0 +1,2 @@
|
||||
These programmes can be distributed under the same terms as
|
||||
ncurses (MIT style license).
|
6
curses-practice/perl/README
Normal file
6
curses-practice/perl/README
Normal file
@@ -0,0 +1,6 @@
|
||||
The license was changed from GNU/GPL to MIT style license
|
||||
which is of course compatible with GPL, in order to include
|
||||
them in the official ncurses-HOWTO.
|
||||
|
||||
Anuradha Ratnaweera (anuradha at gnu org OR gnu.slash.linux at
|
||||
gmail com OR anuradha at linux lk).
|
Reference in New Issue
Block a user