1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
#! /usr/bin/perl
#########################################################################
# This Perl script is Copyright (c) 2002, Peter J Billam #
# c/o P J B Computing, www.pjb.com.au #
# #
# This script is free software; you can redistribute it and/or #
# modify it under the same terms as Perl itself. #
#########################################################################
use utf8;
use open ':locale'; # when was the open pragma introduced ?
#my $EncodingString = q{};
#if (($ENV{LANG} =~ /utf-?8/i) || ($ENV{LC_TYPE} =~ /utf-?8/i)) {
# $EncodingString = ':encoding(utf8)';
# binmode STDERR, $EncodingString;
# binmode STDOUT, $EncodingString;
#}
if (($ENV{LANG} =~ /utf-?8/i) || ($ENV{LC_TYPE} =~ /utf-?8/i)) {
$Brillouin = "Léon Brillouin";
$Delbrueck = "Max Delbrück";
$Descartes = "René Descartes";
$Goedel = "Kurt Gödel";
$Levy = "Paul Lévy";
$Poincare = "Henri Poincaré";
$Schroedinger = "Erwin Schrödinger";
} else {
$Brillouin = "L\x{e9}on Brillouin";
$Delbrueck = "Max Delbr\x{fc}ck";
$Descartes = "Ren\x{e9} Descartes";
$Goedel = "Kurt G\x{f6}del";
$Levy = "Paul L\x{e9}vy";
$Poincare = "Henri Poincar\x{e9}";
$Schroedinger = "Erwin Schr\x{f6}dinger";
}
eval "require './lib/Term/Clui.pm'";
if (!$@) {
warn "using Term::Clui\n";
} else {
eval "require '../Clui.pm'";
if (!$@) {
warn "using ../Clui.pm\n";
} else {
eval "require 'Clui.pm'";
if (!$@) {
warn "using ./Clui.pm\n";
} else {
die "can't find Clui.pm in this dir, parent dir, or INC path\n";
}
}
}
import Term::Clui;
eval "require './lib/Term/Clui/FileSelect.pm'";
if ($@) { eval "require '../Clui/FileSelect.pm'"; }
if ($@) { eval "require 'Clui/FileSelect.pm'"; }
if ($@) {
die "can't find FileSelect.pm in this dir, parent dir, or INC path\n";
}
import Term::Clui::FileSelect;
my $colour = "";
my $paint = "";
my $name = "";
while (1) {
my $task = &choose('Test which Clui.pm subroutine ?',
'ask','choose','confirm','edit','view','select_file',
);
exit unless $task;
eval "&test_$task()"; if ($@) { print STDERR "$@\n"; }
}
sub test_choose {
my @colours = ('Red','Orange','Black','Grey','Blue');
my @paints = (
'Bizzare extremely long name that certainly will never occur on any real artist pallette',
'Alizarin Crimson', 'Burnt Sienna', 'Cadmium Yellow', 'Cobalt Blue',
'Flake White', 'Indian Red', 'Indian Yellow', 'Ivory Black', 'Lemon Yellow',
'Naples Yellow', 'Prussian Blue', 'Raw Sienna', 'Raw Umber', 'Red Ochre',
'Rose Madder', 'Ultramarine Blue', 'Vandyke Brown', 'Viridian Green',
'Yellow Ochre',
);
my @scientists = (
'Luis Alvarez', 'Alain Aspect', 'Michael Barnsley', 'Johann Bernouilli',
'Nicolas Bernouilli', 'Friedrich Wilhelm Bessel', 'John Bell',
'Antoine Becquerel', 'Hans Bethe', 'David Bohm', 'Niels Bohr',
'Ludwig Boltzmann', 'Hermann Bondi', 'George Boole', 'Max Born',
'Satyendra Bose', 'Robert Boyle', $Brillouin, 'Eugenio Calabi',
'Georg Cantor', 'James Chadwick', 'Gregory Chaitin',
'Subrahmanyan Chandrasekar', 'Geoffrey Chew', 'Alonzo Church',
'John Horton Conway', 'Francis Crick', 'Marie Curie', 'Charles Darwin',
'Humphrey Davy', 'Richard Dawkins', 'Louis de Broglie', $Delbrueck,
$Descartes, 'Willem de Sitter', 'Bruce DeWitt', 'Paul Dirac',
'Freeman Dyson', 'Arthur Stanley Eddington', 'Albert Einstein',
'Leonhard Euler', 'Hugh Everett', 'Michael Faraday', 'Pierre Fatou',
'Mitchell Feigenbaum', 'Pierre de Fermat', 'Enrico Fermi',
'Richard Feynman', 'Joseph Fraunhofer', 'Galileo Galilei',
'Evariste Galois', 'George Gamov', 'Carl Friedrich Gauss',
'Murray Gell-Mann', $Goedel, 'Alan Guth', 'Stephen Hawking',
'Felix Hausdorff', 'Werner Heisenberg', 'Charles Hermite',
'Peter Higgs', 'David Hilbert', 'Fred Hoyle', 'Edwin Hubble',
'Christian Huygens', 'David Hilbert', 'Edwin Hubble', 'Pascual Jordan',
'Gaston Julia', 'Marc Kac', 'Theodor Kaluza', 'Stuart Kauffman',
'William Lord Kelvin', 'Gustav Robert Kirchhoff', 'Oskar Klein',
'Helge von Kock', 'Willis Lamb', 'Lev Davidovich Landau', 'Paul Langevin',
'Pierre Simon de Laplace', 'Gottfried Wilhelm Leibnitz', $Levy,
'Hendrik Lorentz', 'James Clark Maxwell', 'Marston Morse',
'Benoit Mandelbrot', 'Gregor Mendel', 'Dmitri Mendeleev', 'Robert Millikan',
'Hermann Minkowski', 'John von Neumann', 'Isaac Newton', 'Emmy Noether',
'Hans Christian Oersted', 'Lars Onsager', 'Robert Oppenheimer',
'Abraham Pais', 'Heinz Pagels', 'Vilfredo Pareto', 'Louis Pasteur',
'Wolfgang Pauli', 'Linus Pauling', 'Guiseppe Peano', 'Rudolf Peierls',
'Roger Penrose', 'Arno Penzias', 'Jean Perrin', 'Max Planck',
'Boris Podolsky', $Poincare, 'Isidor Rabi', 'Srinivasa Ramanujan',
'Lord Rayleigh', 'Lewis Fry Richardson', 'B. Riemann', 'Nathan Rosen',
'Ernest Rutherford', 'Abdus Salam', $Schroedinger,
'Karl Schwarzschild', 'Julian Schwinger', 'Claude Shannon',
'Waclaw Sierpinski', 'Leo Szilard', 'Kip Thorne', 'Alan Turning',
'Sin-itro Tomonaga', 'Stanislaw Ulam', 'James Watson', 'Karl Weierstrauss',
'Hermann Weyl', 'Steven Weinberg', 'John Wheeler', 'Charles Weiner',
'Norbert Wiener', 'Eugene Wigner', 'Robert Wilson', 'Edward Witten',
'Shing-Tung Yau', 'Chen-Ning Yang', 'Hideki Yukawa', 'George Kingsley Zipf',
);
my $multi = &choose('Mode ?', 'Single-choice', 'Multi-choice');
return unless $multi;
if ($multi eq 'Single-choice') {
$paint = &choose("Your favourite paint ?\n".help_text(), @paints);
my $scientist = &choose("Your favourite scientist ?", @scientists);
$colour = &choose(<<'EOT', @colours);
Your favourite colour ?
This tests how the 'choose' subroutine handles multi-line
questions. After you choose, all but the first line should disappear,
leaving the question and answer on the screen as a record of the dialogue.
The other lines should only get displayed if there is room.
EOT
&inform("paint=$paint, scientist=$scientist, colour=$colour\n");
} else {
my @fav_paints
= &choose("Your favourite paints ?\n".help_text('multi'),@paints);
my @fav_scientists = &choose("Your favourite scientists ?",@scientists);
warn "paints = ".join(', ',@fav_paints) .
"\nscientists = ".join(', ',@fav_scientists)."\n";
}
return;
}
sub test_confirm {
&confirm(<<EOT) || return;
OK to proceed with the test ?
This step checks the 'confirm' subroutine and whether it handles
a multiline question OK. After you choose Yes or No all but the
first line should disappear, leaving the question and answer on
the screen as a record of the dialogue.
EOT
&confirm('Did the text vanish except for the 1st line ?');
}
sub test_ask {
my $question = <<EOT;
Enter a string :
The point of this test is to check out the behaviour of &ask
with multi-line questions; subsequent lines after the initial
question should be formatted within the window width ...
EOT
my $string = &ask($question.help_text('ask'));
my @colours = ('Red','Orange','Black','Grey','Blue');
$colour = &choose('Your favourite colour ?', @colours);
return unless $colour;
%names = (
Red=>'Fred', Orange=>'Solange', Black=>'Jack', Grey=>'May', Blue=>'Sue',
);
$name = &ask("Choose a name which rhymes with $colour :", $names{$colour});
warn "string=$string, name=$name\n";
my $passwd = ask_password("Enter some password:");
warn "that password was ".length($passwd)." chars long\n";
my $f = ask_filename("filename ?\n\ntry out the tab-filename-completion");
warn "that filename was $f\n";
}
sub test_edit {
$text = &edit('Your limerick', <<EOT);
There was a brave soul called $name,
Whose favourite colour was $colour;
But some $paint
...
And that was the end of $name.
EOT
}
sub test_view {
&view('Your limerick:', $text||'try testing "ask" and "edit" first :-)');
}
sub test_select_file {
my @bool_opts = ('-Chdir','-Create','-ShowAll','-DisableShowAll',
'-SelDir','-TextFile','-Readable','-Writeable','-Executable','-Owned',
'-Directory');
my @text_opts = ('-FPat','-File','-Path','-Title','-TopDir');
my $multiple = &choose('Select','Single file','Multiple files');
if ($multiple eq 'Multiple files') { shift @bool_opts; shift @bool_opts; }
my %opts;
foreach (@bool_opts) {
$opts{$_} = &choose("option $_ ?",'default','0','1');
return unless defined $opts{$_};
if ($opts{$_} eq 'default') { delete $opts{$_}; }
}
foreach (@text_opts) {
$opts{$_} = &ask("option $_ ?", $opts{$_});
if (! $opts{$_}) { delete $opts{$_}; }
}
if ($multiple eq 'Multiple files') {
my @files = &select_file(-Chdir=>0, %opts);
print STDERR "You selected @files\n";
} else {
print STDERR "You selected " .&select_file(%opts), "\n";
}
}
|