| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
Debconf::Element::Teletype::Progress - Progress bar in a terminal |
| 6 |
|
| 7 |
=cut |
| 8 |
|
| 9 |
package Debconf::Element::Teletype::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 progress bar on any terminal. It won't |
| 17 |
look particularly good, but it will work. |
| 18 |
|
| 19 |
=cut |
| 20 |
|
| 21 |
sub start { |
| 22 |
my $this=shift; |
| 23 |
|
| 24 |
$this->frontend->title($this->question->description); |
| 25 |
$this->frontend->display(''); |
| 26 |
$this->last(0); |
| 27 |
} |
| 28 |
|
| 29 |
sub set { |
| 30 |
my $this=shift; |
| 31 |
my $value=shift; |
| 32 |
|
| 33 |
$this->progress_cur($value); |
| 34 |
|
| 35 |
use integer; |
| 36 |
my $new = ($this->progress_cur() - $this->progress_min()) * 100 / ($this->progress_max() - $this->progress_min()); |
| 37 |
$this->last(0) if $new < $this->last; |
| 38 |
# prevent verbose output |
| 39 |
return if $new / 10 == $this->last / 10; |
| 40 |
|
| 41 |
$this->last($new); |
| 42 |
$this->frontend->display("..$new%"); |
| 43 |
|
| 44 |
return 1; |
| 45 |
} |
| 46 |
|
| 47 |
sub info { |
| 48 |
return 1; |
| 49 |
} |
| 50 |
|
| 51 |
sub stop { |
| 52 |
my $this=shift; |
| 53 |
|
| 54 |
$this->frontend->display("\n"); |
| 55 |
$this->frontend->title($this->frontend->requested_title); |
| 56 |
} |
| 57 |
|
| 58 |
1; |