Skip to content

Commit 7e1a64e

Browse files
committed
Perl terminal experiments
experimenting with Perl terminal modules on Windows
0 parents  commit 7e1a64e

File tree

8 files changed

+148
-0
lines changed

8 files changed

+148
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
local/*

bin/menu.pl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
6+
use Win32::Console::ANSI;
7+
use Term::ANSIMenu;
8+
9+
sub exec_item {
10+
my $itemnr = shift;
11+
12+
print "Executing item";
13+
print " ($itemnr)" if defined $itemnr;
14+
print "...\n";
15+
sleep 1;
16+
}
17+
18+
sub help_item {
19+
my $itemnr = shift;
20+
21+
print "Item help";
22+
print " ($itemnr)" if defined $itemnr;
23+
print "...\n";
24+
sleep 1;
25+
}
26+
27+
sub standard_help {
28+
my $itemnr = shift;
29+
30+
print "Standard help";
31+
print " ($itemnr)" if defined $itemnr;
32+
print "...\n";
33+
sleep 1;
34+
}
35+
36+
my $menu = Term::ANSIMenu->new(width => 40,
37+
help => [['', \&standard_help],
38+
['hint 1', \&help_item],
39+
['hint 2', \&standard_help],
40+
['hint 3', undef]
41+
],
42+
title => 'Menu testing',
43+
items => [['1', ' First menu item', \&exec_item],
44+
['2', ' This string is just too long to fit in the normal terminal width and thus it will be clipped.'],
45+
['3', ' Man', sub { system "type cpanfile" }]
46+
],
47+
status => 'Status',
48+
prompt => '>>');
49+
50+
$menu->print_menu();
51+
while (my $key = $menu->read_key()) {
52+
last unless defined $menu->do_key($key);
53+
$menu->update_status('') if $key eq 'S';
54+
$menu->update_status('New status') if $key eq 's';
55+
$menu->update_prompt('') if $key eq 'P';
56+
$menu->update_prompt('New prompt: ') if $key eq 'p';
57+
}
58+
$menu->pos($menu->line_after_menu() + 1, 1);
59+

bin/test.pl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
use utf8;
6+
7+
#use Win32::Console::ANSI;
8+
use Curses::UI;
9+
10+
#use Term::ANSIMenu;
11+
#
12+
#my $menu = Term::ANSIMenu->new(
13+
# width => 40,
14+
# help => [['', \&standard_help],
15+
# ['hint 1', \&help_item],
16+
# [ undef, \&standard_help],
17+
# ['hint 3', undef]
18+
# ],
19+
# title => 'title',
20+
# items => [
21+
# ['1', 'First menu item', \&exec_item],
22+
# ['2', 'This string is just too long to fit in a normal terminal and thus it will be clipped.'],
23+
# ['3', '', sub { system "man man" }]
24+
# ],
25+
# status => 'status',
26+
# prompt => 'prompt: ');
27+
#
28+
#$menu->print_menu();
29+
#while (my $key = $menu->read_key()) {
30+
# last unless defined $menu->do_key($key);
31+
# $menu->update_status('') if $key eq 'S';
32+
# $menu->update_status('New status') if $key eq 's';
33+
# $menu->update_prompt('') if $key eq 'P';
34+
# $menu->update_prompt('New prompt: ') if $key eq 'p';
35+
#}
36+
#$menu->pos($menu->line_after_menu() + 1, 1);
37+
38+
#----------------------------------------------------------------------------
39+
#use Term::ANSIColor;
40+
#print color 'bold blue';
41+
#print "This text is bold blue.\n";
42+
#print color 'reset';
43+
#print "This text is normal.\n";
44+
#print colored ("Bold yellow on magenta.\n", 'bold yellow on_magenta');
45+
#print "This text is normal.\n";
46+
#----------------------------------------------------------------------------
47+
#use Term::ANSIScreen qw/:color :cursor :screen/;
48+
#locate 1, 1; print "@ This is (1,1)", savepos;
49+
#print locate(24,60), "@ This is (24,60)"; loadpos;
50+
#print down(2), clline, "@ This is (3,16)\n";
51+
#color 'black on white'; clline;
52+
#print "This line is black on white.\n";
53+
#print color 'reset'; print "This text is normal.\n";
54+
#print colored ("This text is bold blue.\n", 'bold blue');
55+
#print "This text is normal.\n";
56+
#print colored ['bold blue'], "This text is bold blue.\n";
57+
#print "This text is normal.\n";

cpanfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
requires 'Win32::Console::ANSI';
2+
requires 'Term::ANSIScreen';
3+
requires 'Term::ANSIMenu';

cpanfile.snapshot

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# carton snapshot format: version 1.0
2+
DISTRIBUTIONS
3+
Win32-Console-ANSI-1.10
4+
pathname: J/JL/JLMOREL/Win32-Console-ANSI-1.10.tar.gz
5+
provides:
6+
Win32::Console::ANSI 1.10
7+
requirements:
8+
ExtUtils::MakeMaker 0
9+
Win32::Pipe 0
10+
Win32::Process 0
11+
Win32-Pipe-0.025
12+
pathname: J/JD/JDB/Win32-Pipe-0.025.tar.gz
13+
provides:
14+
Win32::Pipe 0.025
15+
requirements:
16+
ExtUtils::MakeMaker 0
17+
perl 5.006
18+
Win32-Process-0.16
19+
pathname: J/JD/JDB/Win32-Process-0.16.tar.gz
20+
provides:
21+
Win32::Process 0.16
22+
requirements:
23+
ExtUtils::MakeMaker 0
24+
perl 5.006

install.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
carton install
2+
pause

menu.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
perl -Ilocal\lib\perl5 bin\menu.pl

test.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
perl -Ilocal\lib\perl5 bin\test.pl

0 commit comments

Comments
 (0)