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
A nex browser in perl
A TUI nex browser in perl using Curses

48
connex.pl Normal file → Executable file
View File

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