Skip to content
Snippets Groups Projects
Commit 2f4ff127 authored by echicken's avatar echicken
Browse files

Store currently selected item for locations in history stack. (For

directories anyway.)  Returns to where you were on the page.  Maybe
could do this for text files as well.
Allow download of text file currently being viewed with 'd'.
parent 165b5945
No related branches found
No related tags found
No related merge requests found
...@@ -50,7 +50,8 @@ const state = { ...@@ -50,7 +50,8 @@ const state = {
history_idx: -1, history_idx: -1,
host: 'gopher.floodgap.com', host: 'gopher.floodgap.com',
port: 70, port: 70,
selector: '' selector: '',
fn: ''
}; };
function is_link(str) { function is_link(str) {
...@@ -186,24 +187,34 @@ function go_for(host, port, selector, type, skip_cache) { ...@@ -186,24 +187,34 @@ function go_for(host, port, selector, type, skip_cache) {
state.host = host; state.host = host;
state.port = port; state.port = port;
state.selector = selector; state.selector = selector;
set_address();
set_status(format('%s %s:%s %s', type_map[type], host, port, selector)); set_status(format('%s %s:%s %s', type_map[type], host, port, selector));
return fn; return fn;
} }
function go_history() {
const loc = state.history[state.history_idx];
state.fn = go_for(loc.host, loc.port, loc.selector, loc.type);
print_document(false);
if (loc.type == '1') {
lowlight(state.doc[state.item], state.item);
state.item = loc.item;
state.history[state.history_idx].item = loc.item;
highlight(state.doc[state.item], state.item);
scrollbox.scroll_into_view(state.item);
}
}
function go_back() { function go_back() {
if (state.history_idx <= 0) return; if (state.history_idx <= 0) return;
state.history_idx--; state.history_idx--;
const loc = state.history[state.history_idx]; go_history();
const fn = go_for(loc.host, loc.port, loc.selector, loc.type);
print_document(fn);
} }
function go_forward() { function go_forward() {
if (state.history_idx >= state.history.length - 1) return; if (state.history_idx >= state.history.length - 1) return;
state.history_idx++; state.history_idx++;
const loc = state.history[state.history_idx]; go_history();
const fn = go_for(loc.host, loc.port, loc.selector, loc.type);
print_document(fn);
} }
function go_get(host, port, selector, type, skip_history, skip_cache) { function go_get(host, port, selector, type, skip_history, skip_cache) {
...@@ -214,31 +225,30 @@ function go_get(host, port, selector, type, skip_history, skip_cache) { ...@@ -214,31 +225,30 @@ function go_get(host, port, selector, type, skip_history, skip_cache) {
host: host, host: host,
port: port, port: port,
selector: selector, selector: selector,
type: type type: type,
item: -1
}; };
} }
const fn = go_for(host, port, selector, type, skip_cache); state.fn = go_for(host, port, selector, type, skip_cache);
print_document(fn); print_document(true);
} }
function next_link() { function next_link() {
var ret = state.item;
for (var n = state.item + 1; n < state.doc.length; n++) { for (var n = state.item + 1; n < state.doc.length; n++) {
if (!is_link(state.doc[n].type)) continue; if (!is_link(state.doc[n].type)) continue;
ret = n; state.item = n;
state.history[state.history_idx].item = n;
break; break;
} }
return ret;
} }
function previous_link() { function previous_link() {
var ret = state.item;
for (var n = state.item - 1; n >= 0; n--) { for (var n = state.item - 1; n >= 0; n--) {
if (!is_link(state.doc[n].type)) continue; if (!is_link(state.doc[n].type)) continue;
ret = n; state.item = n;
state.history[state.history_idx].item = n;
break; break;
} }
return ret;
} }
function lowlight(e, i) { function lowlight(e, i) {
...@@ -263,7 +273,7 @@ function highlight(e, i) { ...@@ -263,7 +273,7 @@ function highlight(e, i) {
function set_address() { function set_address() {
const a = console.attributes; const a = console.attributes;
console.home(); console.home();
console.putmsg(format('\0014\001h\001w%s:%s%s', state.host, state.port, state.selector)); console.putmsg(format('\0014\001h\001w%s:%s %s', state.host, state.port, state.selector));
console.cleartoeol(BG_BLUE|WHITE); console.cleartoeol(BG_BLUE|WHITE);
console.attributes = a; console.attributes = a;
} }
...@@ -285,12 +295,12 @@ function reset_display() { ...@@ -285,12 +295,12 @@ function reset_display() {
set_status(''); set_status('');
} }
function print_document(fn) { function print_document(auto_highlight) {
if (state.item_type == '1') { if (state.item_type == '1') {
var item; var item;
var line; var line;
reset_display(); reset_display();
const f = new File(fn); const f = new File(state.fn);
var arr = []; var arr = [];
f.open('r'); f.open('r');
while (!f.eof) { while (!f.eof) {
...@@ -312,14 +322,17 @@ function print_document(fn) { ...@@ -312,14 +322,17 @@ function print_document(fn) {
} }
f.close(); f.close();
scrollbox.load(arr); scrollbox.load(arr);
state.item = next_link(); if (auto_highlight) {
highlight(state.doc[state.item], state.item); next_link();
highlight(state.doc[state.item], state.item);
}
} else if (state.item_type == '0' || state.item_type == '6') { } else if (state.item_type == '0' || state.item_type == '6') {
scrollbox.load(fn); scrollbox.load(state.fn);
} else if (['4', '5', '9', 'g', 'I'].indexOf(state.item_type) > -1) { } else if (['4', '5', '9', 'g', 'I'].indexOf(state.item_type) > -1) {
console.clear(BG_BLACK|LIGHTGRAY);
bbs.send_file(state.fn);
reset_display(); reset_display();
bbs.send_file(fn); go_back();
set_status('');
} }
} }
...@@ -336,7 +349,7 @@ function main() { ...@@ -336,7 +349,7 @@ function main() {
case '\t': case '\t':
if (state.item_type == '1') { if (state.item_type == '1') {
lowlight(state.doc[state.item], state.item); lowlight(state.doc[state.item], state.item);
state.item = next_link(); next_link();
highlight(state.doc[state.item], state.item); highlight(state.doc[state.item], state.item);
scrollbox.scroll_into_view(state.item); scrollbox.scroll_into_view(state.item);
} }
...@@ -345,7 +358,7 @@ function main() { ...@@ -345,7 +358,7 @@ function main() {
case '`': case '`':
if (state.item_type == '1') { if (state.item_type == '1') {
lowlight(state.doc[state.item], state.item); lowlight(state.doc[state.item], state.item);
state.item = previous_link(); previous_link();
highlight(state.doc[state.item], state.item); highlight(state.doc[state.item], state.item);
scrollbox.scroll_into_view(state.item); scrollbox.scroll_into_view(state.item);
} }
...@@ -396,6 +409,14 @@ function main() { ...@@ -396,6 +409,14 @@ function main() {
case 'h': case 'h':
go_get('go-for', 0, 'help.txt', '0'); go_get('go-for', 0, 'help.txt', '0');
break; break;
case 'd':
if (state.item_type == '0' || state.item_type == '6') {
console.clear(BG_BLACK|LIGHTGRAY);
bbs.send_file(state.fn);
reset_display();
go_get(state.host, state.port, state.selector, state.item_type, true, false);
}
break;
default: default:
actioned = false; actioned = false;
break; break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment