Commit ae18b2d4 authored by echicken's avatar echicken
Browse files

Mouse support, for scrolling and clicking on clickable items.

parent 49dbd08a
load('sbbsdefs.js'); load('sbbsdefs.js');
load('scrollbox.js'); load('scrollbox.js');
load('typeahead.js'); load('typeahead.js');
require("mouse_getkey.js", "mouse_getkey");
const ansiterm = load({}, 'ansiterm_lib.js');
/* To do /* To do
* - Config file * - Config file
...@@ -58,6 +60,11 @@ const state = { ...@@ -58,6 +60,11 @@ const state = {
fn: '' fn: ''
}; };
function mouse_enable(enable) {
if (!console.term_supports(USER_ANSI)) return;
ansiterm.send('mouse', enable ? 'set' : 'clear', 'normal_tracking');
}
function is_link(str) { function is_link(str) {
return str.search(/[0-9\+gIT]/) > -1; return str.search(/[0-9\+gIT]/) > -1;
} }
...@@ -387,14 +394,34 @@ function print_document(auto_highlight) { ...@@ -387,14 +394,34 @@ function print_document(auto_highlight) {
} }
function main() { function main() {
js.on_exit('mouse_enable(false);');
js.on_exit('bbs.sys_status = ' + bbs.sys_status + ';');
js.on_exit('console.attributes = ' + console.attributes + ';');
scrollbox.init(); scrollbox.init();
reset_display(); reset_display();
mouse_enable(true);
go_get(state.host, state.port, state.selector, state.item_type); go_get(state.host, state.port, state.selector, state.item_type);
console.gotoxy(console.screen_columns, console.screen_rows); console.gotoxy(console.screen_columns, console.screen_rows);
var actioned = true;
do { do {
state.input = mouse_getkey(K_NONE, undefined, true);
if (!state.input) continue; if (!state.input) continue;
var actioned = true; if (state.input.mouse && state.input.mouse.press) {
switch (state.input) { var mret = scrollbox.getcmd(state.input);
if (typeof mret != 'number') {
console.gotoxy(console.screen_columns, console.screen_rows);
continue;
}
if (mret < state.doc.length && is_link(state.doc[mret].type)) {
lowlight(state.doc[state.item], state.item);
state.item = mret;
state.history[state.history_idx].item = mret;
highlight(state.doc[state.item], state.item);
state.input.key = '\r';
}
}
state.input.key = state.input.key.toLowerCase();
switch (state.input.key) {
// Highlight next link // Highlight next link
case '\t': case '\t':
if (state.item_type == '1' || state.item_type == '7') { if (state.item_type == '1' || state.item_type == '7') {
...@@ -484,7 +511,7 @@ function main() { ...@@ -484,7 +511,7 @@ function main() {
break; break;
} }
if (actioned) console.gotoxy(console.screen_columns, console.screen_rows); if (actioned) console.gotoxy(console.screen_columns, console.screen_rows);
} while ((state.input = console.getkey()).toLowerCase() != 'q'); } while (state.input.key != 'q');
scrollbox.close(); scrollbox.close();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment