diff options
Diffstat (limited to 'urpm/prompt.pm')
-rw-r--r-- | urpm/prompt.pm | 57 |
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 |