| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
Debconf::Element::Dialog::Select - A list of choices in a dialog box |
| 6 |
|
| 7 |
=cut |
| 8 |
|
| 9 |
package Debconf::Element::Dialog::Select; |
| 10 |
use warnings; |
| 11 |
use strict; |
| 12 |
use base qw(Debconf::Element::Select); |
| 13 |
use Debconf::Encoding qw(width); |
| 14 |
use Debconf::Log qw(debug); |
| 15 |
|
| 16 |
=head1 DESCRIPTION |
| 17 |
|
| 18 |
This is an input element that can display a dialog box with a list of choices |
| 19 |
on it. |
| 20 |
|
| 21 |
=cut |
| 22 |
|
| 23 |
sub show { |
| 24 |
my $this=shift; |
| 25 |
|
| 26 |
# Figure out how much space in the dialog box the prompt will take. |
| 27 |
# The -2 tells makeprompt to leave at least two lines to use to |
| 28 |
# display the list. |
| 29 |
my ($text, $lines, $columns)= |
| 30 |
$this->frontend->makeprompt($this->question, -2); |
| 31 |
|
| 32 |
my $screen_lines=$this->frontend->screenheight - $this->frontend->spacer; |
| 33 |
my $default=$this->translate_default; |
| 34 |
my @params=(); |
| 35 |
my @choices=$this->question->choices_split; |
| 36 |
|
| 37 |
# Figure out how many lines of the screen should be used to |
| 38 |
# scroll the list. Look at how much free screen real estate |
| 39 |
# we have after putting the description at the top. If there's |
| 40 |
# too little, the list will need to scroll. |
| 41 |
my $menu_height=$#choices + 1; |
| 42 |
if ($lines + $#choices + 2 >= $screen_lines) { |
| 43 |
$menu_height = $screen_lines - $lines - 4; |
| 44 |
} |
| 45 |
|
| 46 |
$lines=$lines + $menu_height + $this->frontend->spacer; |
| 47 |
my $c=1; |
| 48 |
my $selectspacer = $this->frontend->selectspacer; |
| 49 |
my %unellipsized; |
| 50 |
foreach (@choices) { |
| 51 |
my $choice = $this->frontend->ellipsize($_); |
| 52 |
|
| 53 |
if (exists $unellipsized{$choice}) { |
| 54 |
debug 'developer' => sprintf |
| 55 |
'Ambiguous ellipsized choice "%s": "%s" or "%s". Overflow.', |
| 56 |
$choice, $unellipsized{$choice}, $_; |
| 57 |
$choice = $_; |
| 58 |
} |
| 59 |
$unellipsized{$choice} = $_; |
| 60 |
|
| 61 |
push @params, $choice, ''; |
| 62 |
|
| 63 |
# Choices wider than the description text? (Only needed for |
| 64 |
# whiptail BTW.) |
| 65 |
if ($columns < width($choice) + $selectspacer) { |
| 66 |
$columns = width($choice) + $selectspacer; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
if ($this->frontend->dashsep) { |
| 71 |
unshift @params, $this->frontend->dashsep; |
| 72 |
} |
| 73 |
|
| 74 |
@params=('--default-item', $default, '--menu', |
| 75 |
$text, $lines, $columns, $menu_height, @params); |
| 76 |
|
| 77 |
my $value=$this->frontend->showdialog($this->question, @params); |
| 78 |
if (defined $value) { |
| 79 |
$this->value($this->translate_to_C($unellipsized{$value})); |
| 80 |
} |
| 81 |
else { |
| 82 |
my $default=''; |
| 83 |
$default=$this->question->value |
| 84 |
if defined $this->question->value; |
| 85 |
$this->value($default); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
1 |