diff options
author | jake <jake@jakes-mail.top> | 2022-01-13 11:32:23 -0500 |
---|---|---|
committer | jake <jake@jakes-mail.top> | 2022-01-13 11:32:23 -0500 |
commit | 4bbcced541c85e887456d861357dc0d76f6c7c5b (patch) | |
tree | e0ba0e0fc24b9e3f111a2ae0f35d35ad3c4a57b8 /gmi.pl | |
parent | 872d9c323dead343dbee22d4a3e228d924c6be50 (diff) |
Better navigation (relative paths). More alias.
Diffstat (limited to 'gmi.pl')
-rwxr-xr-x | gmi.pl | 59 |
1 files changed, 42 insertions, 17 deletions
@@ -9,13 +9,11 @@ use bytes; use feature qw(refaliasing); no warnings qw(experimental::refaliasing); -our $VERSION = 'v0.0.10'; +our $VERSION = 'v0.0.11'; -#TODO: +# TODO: # back() only works once; should fix this -# nav() should add current_url's root before links that don't -# have a scheme since that implies the author is linking -# to himself eg: '=> /data/stuff.gmi' +# url() should also handle relative paths # Modules use IO::Socket::SSL; # CPAN @@ -25,9 +23,9 @@ use IO::Pager; # CPAN require Text::Wrapper; # CPAN use Term::ReadKey; # CPAN use Term::ANSIColor; # Core +use Path::Naive qw(normalize_path); # CPAN use Smart::Comments; # CPAN -#my ($wchar) = GetTerminalSize(); my $wrapper = Text::Wrapper->new(columns=>70, body_start=>''); $ENV{pager} = 'less'; my $use_pager = 1; @@ -48,20 +46,25 @@ my %modes = "url" => [ "Make a request to a URL\nThis will set the current working URL" . "\nExample: [gemini://]capsule.com/", \&url ], + "u" => ["Alias of `url'", \&url ], "cwu" => ["Returns current working URL", \&cwu ], + "c" => ["Alias of `cwu'", \&cwu ], "links" => ["Current working URL's links", \&links ], + "l" => ["Alias of `links'", \&links ], - "nav" => ["Follow a link.\n" . - "Sets current working URL.", \&nav, 0 ], + "nav" => ["Follow a link.\nSets current working URL", \&nav, 0 ], + "n" => ["Alias of `nav'", \&nav, 0 ], - "navh" => ["Follow a link from history.\n", \&nav, 1 ], + "navh" => ["Follow a link from history.\nSets current working URL", \&nav, 1 ], + "nh" => ["Alias of `navh'", \&nav, 1 ], - "root" => ["Go to current working URL root\n" . + "root" => ["Navigate to current working URL root\n" . "E.G. gemini://capsule.com/blog/20220112.gmi -> gemini://capsule.com/", \&root ], "hist" => ["Returns history.", \&hist ], + "h" => ["Alias of `hist'", \&hist ], "back" => ["Go back to the previous URL (uses history)", \&back, 0 ], "b" => ["Alias of `back'", \&back, 0 ], @@ -79,7 +82,7 @@ my %modes = }, "config" => {".HELP" => "Config settings to your liking.", "usepager" => ["This toggles pager use.\n" . - "1 = use pager, 0 = stdout\n", \&toggle, 'pager'], + "1 = use pager, 0 = stdout", \&toggle, 'pager'], "textwrap" => ["Input must be an interger or 'auto'. No\n". "input returns the current text-wrap.", \&textwrap], @@ -215,6 +218,10 @@ sub nav { # Setting 0: from links # Setting 1: from history my ($setting,$n) = @_; + if (! $n) { + TUI_Out("Try 'links' or 'hist' then 'nav x', where x is the number.\n"); + return 1; + } $n -= 1; ### $n @@ -228,23 +235,42 @@ sub nav { $link = $history[$n][0]; } + # This implies it is valid if (has_scheme($link)) { url("$link"); - 0; } else { - url("$current_url$link"); - 0; + if ($link =~ m|\.{1,2}/.*|) { + my $new_url = parse_url($current_url); + my $parsed_url_path = split_url_path($new_url->{path}, 256); + my $url_path; + + # request doc will be different + pop(@$parsed_url_path); + for (@$parsed_url_path) { + $url_path .= "/$_"; + } + ### $url_path + ### $link + my $path = normalize_path("$url_path/$link"); + + url("$new_url->{scheme}://$new_url->{host}$path"); + } + else { + my $new_url = parse_url($current_url); + url("$new_url->{scheme}://$new_url->{host}/$link"); + } } } sub has_scheme { - print ($_[0]); + #print ($_[0]); return ($_[0] =~ m|^.*(://)|); } sub root { - TUI_Out("Not implimented yet."); + my $new_url = parse_url($current_url); + url("$new_url->{scheme}://$new_url->{host}/"); } sub back { @@ -304,7 +330,6 @@ sub textwrap { my ($c) = @_; if ($c and $c =~ m/^\d+$/) { $wrapper->columns($c); - #$wchar = $c; $pager_text_wrap_auto = 0; } elsif ($c and $c eq 'auto') { $pager_text_wrap_auto = 1; |