Debian Codegraph @

Debconf/Element/Dialog/Progress.pm

raw
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 Debconf::Element::Dialog::Progress - A progress bar in a dialog box
6
7 =cut
8
9 package Debconf::Element::Dialog::Progress;
10 use warnings;
11 use strict;
12 use base qw(Debconf::Element);
13
14 =head1 DESCRIPTION
15
16 This is an element that can display a dialog box with a progress bar on it.
17
18 =cut
19
20 sub _communicate {
21 my $this=shift;
22 my $data=shift;
23 my $dialoginput = $this->frontend->dialog_input_wtr;
24
25 print $dialoginput $data;
26 }
27
28 sub _percent {
29 my $this=shift;
30
31 use integer;
32 return (($this->progress_cur() - $this->progress_min()) * 100 / ($this->progress_max() - $this->progress_min()));
33 }
34
35 sub start {
36 my $this=shift;
37
38 # Use the short description as the window title, matching cdebconf.
39 $this->frontend->title($this->question->description);
40
41 my ($text, $lines, $columns);
42 if (defined $this->_info) {
43 ($text, $lines, $columns)=$this->frontend->sizetext($this->_info->description);
44 } else {
45 # Make sure dialog allocates a bit of extra space, to allow
46 # for later PROGRESS INFO commands.
47 ($text, $lines, $columns)=$this->frontend->sizetext(' ');
48 }
49 # Force progress bar to full available width, to avoid windows
50 # flashing.
51 if ($this->frontend->screenwidth - $this->frontend->columnspacer > $columns) {
52 $columns = $this->frontend->screenwidth - $this->frontend->columnspacer;
53 }
54
55 my @params=('--gauge');
56 push @params, $this->frontend->dashsep if $this->frontend->dashsep;
57 push @params, ($text, $lines + $this->frontend->spacer, $columns, $this->_percent);
58
59 $this->frontend->startdialog($this->question, 1, @params);
60
61 $this->_lines($lines);
62 $this->_columns($columns);
63 }
64
65 sub set {
66 my $this=shift;
67 my $value=shift;
68
69 $this->progress_cur($value);
70 $this->_communicate($this->_percent . "\n");
71
72 return 1;
73 }
74
75 sub info {
76 my $this=shift;
77 my $question=shift;
78
79 $this->_info($question);
80
81 my ($text, $lines, $columns)=$this->frontend->sizetext($question->description);
82 if ($lines > $this->_lines or $columns > $this->_columns) {
83 # Start a new, bigger dialog if this won't fit.
84 $this->stop;
85 $this->start;
86 }
87
88 # TODO: escape the "XXX" marker required by dialog somehow? */
89
90 # The line immediately following the marker should be a new
91 # percentage, but whiptail (as of 0.51.6-17) looks for a percentage
92 # in the wrong buffer and fails to refresh the display as a result.
93 # To work around this bug, we give it the current percentage again
94 # afterwards to force a refresh.
95 $this->_communicate(
96 sprintf("XXX\n%d\n%s\nXXX\n%d\n",
97 $this->_percent, $text, $this->_percent));
98
99 return 1;
100 }
101
102 sub stop {
103 my $this=shift;
104
105 $this->frontend->waitdialog;
106 $this->frontend->title($this->frontend->requested_title);
107 }
108
109 1