updated git and svn scripts
[xrzperl.git] / ui-select-list
blobd53862edd93d0a59542b6e9243cb138c2816c304
1 #!/usr/bin/perl -w
2 ###APPNAME: ui-select-list
3 ###APPAUTHOR: duel
4 ###APPDATE: 2009-02-08 19:31:24
5 ###APPVER: 0.1
6 ###APPDESC: ui-select-list
7 ###APPUSAGE: (title) (items ...)
8 ###APPEXAMPLE: ui-select-list
9 ###APPOPTION: ui-select-list "Where to go?" "goto hell" "goto heaven"
10 use strict;
12 #ENV variable MUST be defined somewhere,
13 #FOR perl to search modules from,
14 #OR nothing will work
15 use lib $ENV{XR_PERL_MODULE_DIR};
17 use MyPlace::Script::Usage qw/help_required help_even_empty/;
18 exit 0 if(help_required($0,@ARGV));
19 #exit 0 if(help_even_empty($0,@ARGV));
21 my $app = "whiptail";
22 my $title=shift;
23 my @items=@ARGV;
25 unless(@items) {
26 print STDERR ("Usage: $0 <title> <items...>\n");exit 0;
29 my $width=length($title) + 8;
30 my $list_height = 1 * @items;
31 my $height= $list_height + 8;
33 my @cmdline;
35 my $idx = 0;
36 foreach(@items) {
37 $idx++;
38 my $len = length($_) + 8;$width = $len if($len>$width);
39 push @cmdline,$idx,"- $_";
42 unshift @cmdline,$app,"--menu",$title,$height,$width,$list_height,"--";
43 use File::Temp qw/tempfile/;
44 my (undef,$filename) = tempfile();
45 my $fh;
46 my $olderr;
47 open $olderr,">&",\*STDERR;
48 open $fh,">",$filename;
49 open STDERR,">&",$fh;
50 my $r = system(@cmdline);
51 close $fh;
52 open STDERR,">&",$olderr;
55 exit 0 unless($r == 0);
57 open $fh,"<",$filename;
58 $r=<$fh> || 0;
59 close $fh;
60 $r =~ s/^\s*(\d+).*$/$1/;
61 exit $r;