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
|
package urpm::prompt;
# $Id$
use strict;
(our $VERSION) = q($Revision$) =~ /(\d+)/;
sub new {
my ($class, $title, $prompts, $defaults, $hidden) = @_;
bless {
title => $title,
prompts => $prompts,
defaults => $defaults,
hidden => $hidden,
}, $class;
}
sub write {
my (undef, $msg) = @_;
print STDOUT $msg;
}
sub prompt {
my ($self) = @_;
my @answers;
$self->write($self->{title});
foreach my $i (0 .. $#{$self->{prompts}}) {
$self->write($self->{prompts}[$i]);
$self->{hidden}[$i] and system("/bin/stty", "-echo");
my $input = <STDIN>;
$self->{hidden}[$i] and do { system("/bin/stty", "echo"); $self->write("\n") };
defined $input or return @answers;
chomp $input;
$input eq '' and $input = defined $self->{defaults}[$i] ? $self->{defaults}[$i] : '';
push @answers, $input;
}
@answers;
}
1;
__END__
=head1 NAME
urpm::prompt - base class to prompt the user for data
=head1 SYNOPSIS
=head1 DESCRIPTION
=head1 COPYRIGHT
Copyright (C) 2005 MandrakeSoft SA
Copyright (C) 2005-2009 Mandriva SA
=cut
|