From 86d8310d5724632f2cd54723e9a2ced66bb80ba9 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 16 May 2011 11:22:01 +0200 Subject: Use Term::ReadLine instead of builtin readline --- lib/App/Raps2/UI.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lib/App/Raps2/UI.pm') diff --git a/lib/App/Raps2/UI.pm b/lib/App/Raps2/UI.pm index 5192c43..089290b 100644 --- a/lib/App/Raps2/UI.pm +++ b/lib/App/Raps2/UI.pm @@ -7,12 +7,14 @@ use 5.010; use Carp qw(confess); use POSIX; +use Term::ReadLine; our $VERSION = '0.2'; sub new { my ($obj) = @_; my $ref = {}; + $ref->{term_readline} = Term::ReadLine->new('App::Raps2'); return bless($ref, $obj); } @@ -28,12 +30,12 @@ sub list { } sub read_line { - my ($self, $str) = @_; + my ($self, $str, $pre) = @_; - print "${str}: "; - my $input = readline(STDIN); + $pre //= q{}; + + my $input = $self->{term_readline}->readline("${str}: ${pre}"); - chomp $input; return $input; } @@ -43,8 +45,8 @@ sub read_multiline { say "${str} (^D to quit)"; - while (my $line = ) { - $in .= $line; + while (my $line = $self->read_line('multiline')) { + $in .= "${line}\n"; } return $in; } -- cgit v1.2.3