summaryrefslogtreecommitdiffstats
path: root/urpm/prompt.pm
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2005-04-26 15:45:54 +0000
committerRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2005-04-26 15:45:54 +0000
commitde7acdb4096997634ed3e459bc1e909f59b9c0ce (patch)
tree1ef5233e0626618ab6d48fc7e8af1bd63e0fe4e6 /urpm/prompt.pm
parentaa5b090a1c105963889a73afe8fc303b5b544f01 (diff)
downloadurpmi-de7acdb4096997634ed3e459bc1e909f59b9c0ce.tar
urpmi-de7acdb4096997634ed3e459bc1e909f59b9c0ce.tar.gz
urpmi-de7acdb4096997634ed3e459bc1e909f59b9c0ce.tar.bz2
urpmi-de7acdb4096997634ed3e459bc1e909f59b9c0ce.tar.xz
urpmi-de7acdb4096997634ed3e459bc1e909f59b9c0ce.zip
Allow to ask user for proxy credentials
Diffstat (limited to 'urpm/prompt.pm')
-rw-r--r--urpm/prompt.pm57
1 files changed, 57 insertions, 0 deletions
diff --git a/urpm/prompt.pm b/urpm/prompt.pm
new file mode 100644
index 00000000..b2896bde
--- /dev/null
+++ b/urpm/prompt.pm
@@ -0,0 +1,57 @@
+package urpm::prompt;
+
+use strict;
+
+sub new {
+ my ($class, $title, $prompts, $defaults, $hidden) = @_;
+ bless {
+ title => $title,
+ prompts => $prompts,
+ defaults => $defaults,
+ hidden => $hidden,
+ }, $class;
+}
+
+sub write {
+ my (undef, $msg) = @_;
+ if ($urpm::args::options{bug} || !defined fileno ::SAVEOUT) {
+ print STDOUT $msg;
+ } else {
+ print ::SAVEOUT $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 Mandriva
+
+=cut