From 0410446c5b540a12251f71c8d3f0c6affcedd0b9 Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 1 Feb 2022 22:11:23 -0500 Subject: back() will load the cached paged. it only caches once (useful for slow search engine) --- gmi.pl | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/gmi.pl b/gmi.pl index 5102dc0..bcf901a 100755 --- a/gmi.pl +++ b/gmi.pl @@ -26,10 +26,7 @@ use warnings; use feature qw(refaliasing); no warnings qw(experimental::refaliasing); -our $VERSION = 'v1.0.0'; - -# TODO: -# back() only works once; should fix this +our $VERSION = 'v1.0.1'; # Modules use IO::Socket::SSL; # CPAN @@ -96,6 +93,7 @@ if (! -e $xdg_cache) { ### $xdg_config ### $xdg_data ### $xdg_cache +my @cache; load_config(); my $wrapper = Text::Wrapper->new(columns=>$config{textwrap}, body_start=>''); @@ -142,7 +140,7 @@ my %commands = ( 'hist' => [sub { hist() }, 'Returns history.' ], 'h' => [sub { hist() }, 'Alias of `hist\'.' ], - 'back' => [sub { back(0) }, 'Go back in history.' ], + 'back' => [sub { back(0) }, 'Go back in history, once. The previously accessed URI is cached.' ], 'b' => [sub { back(0) }, 'Alias of `back\'.' ], 'backnodisplay' => [sub { back(1) }, 'Go back in history but do not display the page' . @@ -306,6 +304,9 @@ sub url { ### $current_url ### $url + if (@doc) { + @cache = @doc; + } undef(@doc); if (peer_cert($cl, $url->{host})) { @@ -823,7 +824,17 @@ sub back { $config{doc_out} = 0 if ($display == 1); if (@history >= 2) { - url("$history[-2][0]"); + $current_url="$history[-2][0]"; + if (@cache) { + my @array = @doc; + @doc = @cache; + @cache = @array; + display(); + } + else { + # when the user just started the program and types 'back' and has history + url("$history[-2][0]"); + } } else { print $OUT "No such history there."; -- cgit v1.2.3