Fixed add_history to fix history (so it doesn't contain the link you are about to navigate to).

Updated README just slightly.
This commit is contained in:
peteyboy 2024-03-05 02:10:53 -05:00
parent 28a86d9a5b
commit 2dec7bf629
2 changed files with 28 additions and 22 deletions

View File

@ -1,3 +1,3 @@
# Connex # Connex
A nex browser in perl A TUI nex browser in perl using Curses

46
connex.pl Normal file → Executable file
View File

@ -6,6 +6,8 @@ use warnings;
use strict; use strict;
use Curses::UI; use Curses::UI;
use Net::Telnet; use Net::Telnet;
use URI::Split;
my $HOST_DEFAULT = "nightfall.city"; my $HOST_DEFAULT = "nightfall.city";
my $PATHSPEC_DEFAULT = ''; my $PATHSPEC_DEFAULT = '';
@ -32,10 +34,10 @@ my $connect = new Net::Telnet (Timeout => 10,
my @menu = ( my @menu = (
{ -label => 'File', { -label => 'File',
-submenu => [ -submenu => [
{ -label => 'Go to Link ^G', -value =>\&goto_link_dialog }, { -label => 'Go to Link ^G', -value => \&goto_link_dialog },
{ -label => 'Change Site ^C', -value =>\&goto_site_dialog }, { -label => 'Change Site ^C', -value => \&goto_site_dialog },
{ -label => 'Back ^B', -value => \&goto_back }, { -label => 'Back ^B', -value => \&goto_back },
{ -label => 'History ^H', -value => \&history_status_dialog }, { -label => 'History ^H', -value => "\&history_status_dialog" },
{ -label => 'Exit ^Q', -value => \&exit_dialog } { -label => 'Exit ^Q', -value => \&exit_dialog }
] ]
}, },
@ -85,11 +87,12 @@ sub goto_site_dialog()
sub goto_back() sub goto_back()
{ {
my $fetched = fetch_history(); my $fetched = fetch_history();
if($fetched) { #if($fetched) {
$pathspec =$fetched; $pathspec =$fetched;
load($pathspec); load($pathspec);
update_status_bar(); update_status_bar();
} history_status_dialog();
#}
} }
@ -97,26 +100,28 @@ sub goto_back()
sub navigate{ sub navigate{
my $link = shift; my $link = shift;
if ($link){ #if ($link){
if($link ne ''){ # if($link ne ''){
add_history($pathspec); #add last link to history before going forward!
$pathspec = $link; $pathspec = $link;
add_history($pathspec);
load($pathspec); load($pathspec);
}else { # }else {
$pathspec = ''; # $pathspec = '';
} # }
update_status_bar(); update_status_bar();
} #}
} }
sub update_status_bar sub update_status_bar
{ {
my $browser = $win1->getobj("browser");
my $statusbar = $win1->getobj("status"); my $statusbar = $win1->getobj("status");
$statusbar->text("Current site: $host, current link: [$pathspec]"); $statusbar->text("Current site: $host, current link: [$pathspec]");
$statusbar->draw(); $statusbar->draw();
$browser->focus();
} }
@ -139,16 +144,16 @@ sub fetch_history
}else{ }else{
return($PATHSPEC_DEFAULT); return($PATHSPEC_DEFAULT);
} }
history_status_dialog();
} }
sub history_status_dialog sub history_status_dialog
{ {
if(@history){ if(@history){
my $browser = $win1->getobj("browser");
$browser->focus();
my $history_list = join(", ", @history); my $history_list = join(", ", @history);
my $return = $cui->status(-message => $history_list); my $return = $cui->status("$history_list");
} }
} }
@ -203,10 +208,10 @@ $cui->set_binding( \&goto_link_dialog , "\cG");
$cui->set_binding( \&goto_back , "\cB"); $cui->set_binding( \&goto_back , "\cB");
$cui->set_binding( \&goto_site_dialog , "\cC"); $cui->set_binding( \&goto_site_dialog , "\cC");
#start up
$texteditor->focus(); $texteditor->focus();
load('');
navigate('');
$cui->mainloop(); $cui->mainloop();
@ -256,6 +261,7 @@ sub load
$ok= $connect->print($pathspec); $ok= $connect->print($pathspec);
@lines =$connect->getlines(ErrMode=> 'return'); @lines =$connect->getlines(ErrMode=> 'return');
print $connect->eof(); print $connect->eof();
#handle non-existant request?
die unless $connect->eof(); die unless $connect->eof();
$connect->close(); $connect->close();
my $widget= $texteditor; my $widget= $texteditor;
@ -265,7 +271,7 @@ sub load
foreach $currentline (@lines){ foreach $currentline (@lines){
if ($currentline =~ m/^=>/){ if ($currentline =~ m/^=>/){
$count+=1; $count+=1;
$currentline =~ s/^=>(.*$)/[$count\]$1/; $currentline =~ s/(^=>.*$)/$1 [\>$count\]/;
} }
$loaded_text= $loaded_text . $currentline; $loaded_text= $loaded_text . $currentline;
} }