From 1d40fd5cf8bc79046a9de26d542da9c950499692 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 16 Jan 2022 18:20:06 -0500 Subject: Use Term::ReadLine --- gmi.pl | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'gmi.pl') diff --git a/gmi.pl b/gmi.pl index c872597..9ed3f3b 100755 --- a/gmi.pl +++ b/gmi.pl @@ -10,7 +10,7 @@ use bytes; use feature qw(refaliasing); no warnings qw(experimental::refaliasing); -our $VERSION = 'v0.0.17'; +our $VERSION = 'v0.0.18'; # TODO: # back() only works once; should fix this @@ -23,6 +23,8 @@ require Text::Wrapper; # CPAN use Term::ReadKey; # CPAN use Term::ANSIColor; # Core use Path::Naive qw(normalize_path); # CPAN +use Text::ParseWords; # Core +use Term::ReadLine; # CPAN use Smart::Comments; # CPAN my $wrapper = Text::Wrapper->new(columns=>70, body_start=>''); @@ -87,18 +89,24 @@ my %commands = ( 'exit' => [sub {exit 0;}, "This exits the program with a status code of 0."], ); -print "Type 'cmds' to see available commands.\n"; -while () { +my $term=new Term::ReadLine "hmm, what goes here?"; +my @completions = keys %commands; +my $OUT = $term->OUT || \*STDOUT; - $prompt = "$current_url > "; - print "$prompt"; - chomp(my $input = ); +$term->Attribs->{'do_expand'}=1; +$term->Attribs->{'completion_entry_function'} = $term->Attribs->{'list_completion_function'}; +$term->Attribs->{'completion_word'} = \@completions; +$term->ornaments(0); + +$prompt = "$current_url > "; - # ## $input - if ($input) { - my ($command, $detail) = split(/\s/, $input); +print "Press to see available commands.\n"; +while ( defined ($_ = $term->readline($prompt)) ) { + if ($_) { + my ($command, $detail) = split(/\s/, $_); do_command(\$command, \$detail); } + $prompt = "$current_url > "; } sub do_command { @@ -150,7 +158,7 @@ sub url { # ## $url # relative movement - if ($mode eq 1) { + if ($mode and $mode eq 1) { if (!$current_url) {print "Relative movement impossible: no current URL.\n"; return 1;} my $c_url = parse_url($current_url); -- cgit v1.2.3