Debian Codegraph @

Debconf/Element/Dialog/Multiselect.pm

raw
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 Debconf::Element::Dialog::Multiselect - a check list in a dialog box
6
7 =cut
8
9 package Debconf::Element::Dialog::Multiselect;
10 use warnings;
11 use strict;
12 use base qw(Debconf::Element::Multiselect);
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 check list in
19 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 @params=();
34 my @choices=$this->question->choices_split;
35 my %value = map { $_ => 1 } $this->translate_default;
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 if ($menu_height < 3 && $#choices + 1 > 2) {
45 # Don't display a tiny menu.
46 $this->frontend->showtext($this->question, $this->question->extended_description);
47 ($text, $lines, $columns)=$this->frontend->sizetext($this->question->description);
48 $menu_height=$#choices + 1;
49 if ($lines + $#choices + 2 >= $screen_lines) {
50 $menu_height = $screen_lines - $lines - 4;
51 }
52 }
53 }
54
55 $lines=$lines + $menu_height + $this->frontend->spacer;
56 my $selectspacer = $this->frontend->selectspacer;
57 my $c=1;
58 my %unellipsized;
59 foreach (@choices) {
60 my $choice = $this->frontend->ellipsize($_);
61
62 if (exists $unellipsized{$choice}) {
63 debug 'developer' => sprintf
64 'Ambiguous ellipsized choice "%s": "%s" or "%s". Overflow.',
65 $choice, $unellipsized{$choice}, $_;
66 $choice = $_;
67 }
68 $unellipsized{$choice} = $_;
69
70 push @params, ($choice, "");
71 push @params, ($value{$_} ? 'on' : 'off');
72
73 # Choices wider than the description text? (Only needed for
74 # whiptail BTW.)
75 if ($columns < width($choice) + $selectspacer) {
76 $columns = width($choice) + $selectspacer;
77 }
78 }
79
80 if ($this->frontend->dashsep) {
81 unshift @params, $this->frontend->dashsep;
82 }
83
84 @params=('--separate-output', '--checklist',
85 $text, $lines, $columns, $menu_height, @params);
86
87 my $value=$this->frontend->showdialog($this->question, @params);
88
89 if (defined $value) {
90 # Dialog returns the selected items, each on a line.
91 # Translate back to C, and turn into our internal format.
92 $this->value(join(", ", $this->order_values(
93 map { $this->translate_to_C($unellipsized{$_}) }
94 split(/\n/, $value))));
95 }
96 else {
97 my $default='';
98 $default=$this->question->value
99 if defined $this->question->value;
100 $this->value($default);
101 }
102 }
103
104 1