/usr/share/perl5/Curses/UI/Progressbar.pm is in libcurses-ui-perl 0.9609-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | # ----------------------------------------------------------------------
# Curses::UI::Progressbar
#
# (c) 2001-2002 by Maurice Makaay. All rights reserved.
# This file is part of Curses::UI. Curses::UI is free software.
# You can redistribute it and/or modify it under the same terms
# as perl itself.
#
# Currently maintained by Marcus Thiesen
# e-mail: marcus@cpan.thiesenweb.de
# ----------------------------------------------------------------------
# TODO: fix dox
package Curses::UI::Progressbar;
use strict;
use Curses;
use Curses::UI::Common;
use Curses::UI::Widget;
use vars qw(
$VERSION
@ISA
);
@ISA = qw(
Curses::UI::Widget
Curses::UI::Common
);
$VERSION = '1.10';
sub new ()
{
my $class = shift;
my %userargs = @_;
keys_to_lowercase(\%userargs);
my %args = (
-min => 0, # minimal value
-max => 100, # maximum value
-pos => 0, # the current position
-nopercentage => 0, # show the percentage or not?
-nocenterline => 0, # show the center line or not?
-showvalue => 0, # show value instead of percentage
-border => 1,
-fg => -1,
-bg => -1,
%userargs,
-focusable => 0,
-nocursor => 1,
);
# Check that the lowest value comes first.
if ($args{-min} > $args{-max})
{
my $tmp = $args{-min};
$args{-min} = $args{-max};
$args{-max} = $tmp;
}
my $height = height_by_windowscrheight(1, %args);
$args{-height} = $height;
my $this = $class->SUPER::new( %args );
return $this;
}
sub get()
{
my $this = shift;
return $this->{-pos};
}
sub pos(;$)
{
my $this = shift;
my $pos = shift || 0;
$this->{-pos} = $pos;
$this->intellidraw;
return $this;
}
sub draw(;$)
{
my $this = shift;
my $no_doupdate = shift || 0;
# Draw the widget
$this->SUPER::draw(1) or return $this;
# Check bounds for the position.
$this->{-pos} = $this->{-max} if $this->{-pos} > $this->{-max};
$this->{-pos} = $this->{-min} if $this->{-pos} < $this->{-min};
if ($Curses::UI::color_support) {
my $co = $Curses::UI::color_object;
my $pair = $co->get_color_pair(
$this->{-fg},
$this->{-bg});
$this->{-canvasscr}->attron(COLOR_PAIR($pair));
}
# Compute percentage
my $perc = ($this->{-pos}-$this->{-min})
/($this->{-max}-$this->{-min})*100;
# Compute the number of blocks to draw. Only draw
# no blocks or all blocks if resp. the min. or the
# max. value is set.
my $blocks = int($perc * $this->canvaswidth / 100);
if ($blocks == 0 and
$this->{-pos} != $this->{-min}) { $blocks++ }
if ($blocks == $this->canvaswidth and
$this->{-pos} != $this->{-max}) { $blocks-- }
# Draw center line
$this->{-canvasscr}->addstr(0, 0, "-"x$this->canvaswidth)
unless $this->{-nocenterline};
# Draw blocks.
$this->{-canvasscr}->attron(A_REVERSE);
$this->{-canvasscr}->addstr(0, 0, " "x$blocks);
$this->{-canvasscr}->attroff(A_REVERSE);
# Draw percentage
if (not $this->{-nopercentage} or $this->{-showvalue})
{
my $str;
if ($this->{-showvalue}) {
$str = " $this->{-pos} ";
} else {
$str = " " . int($perc) . "% ";
}
my $len = length($str);
my $xpos = int(($this->canvaswidth - $len)/2);
my $revlen = $blocks - $xpos;
$revlen = 0 if $revlen < 0;
$revlen = $len if $revlen > $len;
my $rev = substr($str, 0, $revlen);
my $norev = substr($str, $revlen, $len-$revlen);
$this->{-canvasscr}->attron(A_REVERSE);
$this->{-canvasscr}->addstr(0, $xpos, $rev);
$this->{-canvasscr}->attroff(A_REVERSE);
$this->{-canvasscr}->addstr(0, $xpos+$revlen, $norev);
}
$this->{-canvasscr}->move(0,$this->canvaswidth-1);
$this->{-canvasscr}->noutrefresh();
doupdate() unless $no_doupdate;
return $this;
}
1;
=pod
=head1 NAME
Curses::UI::Progressbar - Create and manipulate progressbar widgets
=head1 CLASS HIERARCHY
Curses::UI::Widget
|
+----Curses::UI::Progressbar
=head1 SYNOPSIS
use Curses::UI;
my $cui = new Curses::UI;
my $win = $cui->add('window_id', 'Window');
my $progressbar = $win->add(
'myprogressbar', 'Progressbar',
-max => 250,
-pos => 42,
);
$progressbar->draw;
=head1 DESCRIPTION
Curses::UI::Progressbar is a widget that can be used to
provide some sort of progress information to the user
of your program. The progressbar looks like this:
+------------------------------------------+
|||||||||---------- 14% ------------------ |
+------------------------------------------+
See exampes/demo-Curses::UI::Progressbar in the distribution
for a short demo.
=head1 STANDARD OPTIONS
B<-parent>, B<-x>, B<-y>, B<-width>, B<-height>,
B<-pad>, B<-padleft>, B<-padright>, B<-padtop>, B<-padbottom>,
B<-ipad>, B<-ipadleft>, B<-ipadright>, B<-ipadtop>, B<-ipadbottom>,
B<-title>, B<-titlefullwidth>, B<-titlereverse>
For an explanation of these standard options, see
L<Curses::UI::Widget|Curses::UI::Widget>.
=head1 WIDGET-SPECIFIC OPTIONS
=over 4
=item * B<-min> < VALUE >
This opion sets the minimum value for the progress bar.
Default is 0.
=item * B<-max> < VALUE >
This opion sets the maximum value for the progress bar.
=item * B<-pos> < VALUE >
This option sets the startposition for the progress
bar.
=item * B<-nopercentage> < BOOLEAN >
This option controls if a percentage indicator should
be drawn in the widget. The default for the BOOLEAN
value is false, so a percentage incdicator will be drawn.
=item * B<-showvalue> < BOOLEAN >
If this option is set to a true value, the current
position value will be drawn in the widget.
=item * B<-nocenterline> < BOOLEAN >
This option controls if a horizontal line should
be drawn in the widget. The default for the BOOLEAN
value is false, so a horizontal line will be drawn.
=back
=head1 METHODS
=over 4
=item * B<new> ( OPTIONS )
=item * B<layout> ( )
=item * B<draw> ( BOOLEAN )
=item * B<intellidraw> ( )
=item * B<focus> ( )
These are standard methods. See L<Curses::UI::Widget|Curses::UI::Widget>
for an explanation of these.
=item * B<get> ( )
This method will return the current B<-pos> value of the widget.
=item * B<pos> ( VALUE )
This method will set the B<-pos> value of the widget to SCALAR.
=back
=head1 DEFAULT BINDINGS
Since a Progressbar is a non-interacting widget, it does not have
any bindings.
=head1 SEE ALSO
L<Curses::UI|Curses::UI>,
L<Curses::UI::Widget|Curses::UI::Widget>,
L<Curses::UI::Common|Curses::UI::Common>
=head1 AUTHOR
Copyright (c) 2001-2002 Maurice Makaay. All rights reserved.
Maintained by Marcus Thiesen (marcus@cpan.thiesenweb.de)
This package is free software and is provided "as is" without express
or implied warranty. It may be used, redistributed and/or modified
under the same terms as perl itself.
|