diff options
Diffstat (limited to 'perl-install/interactive/curses.pm')
-rw-r--r-- | perl-install/interactive/curses.pm | 62 |
1 files changed, 53 insertions, 9 deletions
diff --git a/perl-install/interactive/curses.pm b/perl-install/interactive/curses.pm index b8da3c29a..64bdee5c7 100644 --- a/perl-install/interactive/curses.pm +++ b/perl-install/interactive/curses.pm @@ -3,7 +3,7 @@ # to debug, use something like # PERLDB_OPTS=TTY=`tty` LC_ALL=fr_FR.UTF-8 xterm -geometry 80x25 -e sh -c 'DISPLAY= perl -d t.pl' -package interactive::curses; # $Id$ +package interactive::curses; use diagnostics; use strict; @@ -32,13 +32,20 @@ sub new { open STDERR, ">", common::secured_file($stderr_file); $cui ||= Curses::UI->new('-color_support' => 1); + + # Set some default terminal size, for serial install + unless ($cui->{'-width'}) { + $cui->{'-width'} = $cui->{'-w'} = $cui->{'-bw'} = 80; + $cui->{'-height'} = $cui->{'-h'} = $cui->{'-bh'} = 25; + } + bless { cui => $cui }, $class; } sub enter_console { &suspend } sub leave_console { &end } -sub suspend { Curses::UI->leave_curses } -sub resume { Curses::UI->reset_curses } +sub suspend { $cui && $cui->leave_curses } +sub resume { $cui->reset_curses } sub end { &suspend; print $SAVEERR $_ foreach cat_($stderr_file); unlink $stderr_file } sub exit { end(); CORE::exit($_[1] || 0) } END { end() } @@ -80,7 +87,7 @@ sub filter_widget { #- combo does not allow modifications $e->{type} = 'entry' if $e->{type} eq 'combo' && !$e->{not_edit}; - $e->{formatted_list} = [ map { may_apply($e->{format}, $_) } @{$e->{list}} ]; + $e->{formatted_list} = [ map { my $t = warp_text(may_apply($e->{format}, $_), 80); $t } @{$e->{list}} ]; $e->{default_curses} ||= delete $e->{curses}; } @@ -163,14 +170,14 @@ sub compute_size { $e->{curses}{'-height'} ||= heights(map { $_ + 2 } int(@{$e->{formatted_list}}), 10, 4); $e->{curses}{'-width'} ||= max(map { length } @{$e->{formatted_list}}) + 7; } elsif ($e->{type} =~ /list/) { - $e->{curses}{'-height'} ||= heights(map { $_ + 2 } int(@{$e->{formatted_list}}), 5, 4); - $e->{curses}{'-width'} ||= max(map { length } @{$e->{formatted_list}}) + 3; + $e->{curses}{'-height'} ||= heights(map { $_ + 2 } int(map { split("\n", $_) } @{$e->{formatted_list}}), 5, 4); + $e->{curses}{'-width'} ||= max(map { length } map { split("\n", $_) } @{$e->{formatted_list}}) + 3; } elsif ($e->{type} eq 'button') { my $s = sprintf('< %s >', may_apply($e->{format}, ${$e->{val}})); $e->{curses}{'-width'} ||= length($s); } elsif ($e->{type} eq 'expander') { $e->{curses}{'-width'} ||= length("<+> $e->{text}"); - } elsif ($e->{type} eq 'text' || $e->{type} eq 'label' || $e->{type} eq 'only_label') { + } elsif (member($e->{type}, qw(text label only_label))) { my @text = _messages(min(80, $width_avail - 1), ${$e->{val}}); #- -1 because of the scrollbar $e->{curses}{'-focusable'} = 0; $e->{curses}{'-height'} ||= heights(int(@text), 10, 4); @@ -345,7 +352,7 @@ sub create_widget { $w->set_binding('focus-up', Curses::KEY_LEFT()); $w->set_binding('focus-down', Curses::KEY_RIGHT()); $set = sub { $w->set_label(0, sprintf('< %s >', may_apply($e->{format}, $_[0]))) }; - } elsif ($e->{type} eq 'list' || $e->{type} eq 'combo') { + } elsif (member($e->{type}, qw(list combo))) { $w = $win->add(undef, $e->{type} eq 'combo' ? 'Popupmenu' : 'Listbox', '-values' => $e->{formatted_list}, '-onchange' => $onchange->(sub { $e->{list}[$w->id] }), @@ -398,13 +405,26 @@ sub create_widget { } elsif ($e->{type} eq 'label' && $e->{curses}{'-height'} == 1) { $w = $win->add(undef, 'Label', %options); $set = sub { $w->text($_[0] || '') }; - } elsif ($e->{type} eq 'label' || $e->{type} eq 'only_label' || $e->{type} eq 'text') { + } elsif (member($e->{type}, qw(label only_label text))) { $w = $win->add(undef, 'TextViewer', %options); $set = sub { my ($text) = @_; my $width = $w->{'-sw'} - ($w->{'-vscrollbar'} ? 1 : 0); $w->text(join("\n", _messages($width, $text))); }; + } elsif ($e->{type} eq 'range') { + $w = $win->add(undef, 'TextEntry', + '-sbborder' => 1, + '-text' => '', + '-regexp' => '/^\d*$/', + '-onchange' => sub { + $w->text($e->{min}) if $w->text < $e->{min}; + $w->text($e->{max}) if $w->text > $e->{max}; + ${$e->{val}} = $w->text; + $changed->() if $changed; + }, + %options); + $set = sub { $w->text($_[0] || '') }; } else { $w = $win->add(undef, $e->{hidden} ? 'PasswordEntry' : 'TextEntry', '-sbborder' => 1, @@ -539,6 +559,30 @@ sub ask_fromW_ { $v eq '0 but true' ? 0 : $v; } +sub ask_fileW { + my ($o, $opts) = @_; + my ($file, $dir); + + $dir = $opts->{directory} || $opts->{file} && dirname($opts->{file}); + + if ($opts->{save}) { + $file = $o->{cui}->savefilebrowser('-title' => $opts->{title}, '-path' => $dir, '-file' => basename($file)); + } else { + $file = $o->{cui}->loadfilebrowser('-title' => $opts->{title}, '-path' => $dir, '-file' => basename($file)); + } + + my $err; + if (!$file) { + $err = N("No file chosen"); + } elsif (-f $file && $opts->{want_a_dir}) { + $file = dirname($file); + } elsif (-d $file && !$opts->{want_a_dir}) { + $err = N("You have chosen a directory, not a file"); + } elsif (!-e $file && !$opts->{save}) { + $err = $opts->{want_a_dir} ? N("No such directory") : N("No such file"); + } + $err and $o->ask_warn('', $err) or $file; +} sub wait_messageW { my ($o, $title, $message, $message_modifiable) = @_; |