aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjake <jake@jakes-mail.top>2022-01-16 18:20:06 -0500
committerjake <jake@jakes-mail.top>2022-01-16 18:20:06 -0500
commit1d40fd5cf8bc79046a9de26d542da9c950499692 (patch)
treebdcffc81de6bee6b1a54e62590b73cc94ef2c165
parent7a0a49f6c20a31d0ef5d97db0871d223e7e9cc1e (diff)
Use Term::ReadLine
-rwxr-xr-xgmi.pl28
1 files changed, 18 insertions, 10 deletions
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 = <STDIN>);
+$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 <tab><tab> 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);