Skip to content
Snippets Groups Projects
Commit d6b1cff8 authored by deuce's avatar deuce
Browse files

Fixed up and happy... still have console.aborted to deal with however.

parent 1e621ab3
Branches
Tags
No related merge requests found
// Support functions for cold/hot keys in JS shells. // Support functions for cold/hot keys in JS shells.
load("sbbsdefs.js"); load("sbbsdefs.js");
var coldfuncs_last_hotkey='';
function get_next_key() function get_next_key()
{ {
var retchar; var retchar;
var bytes=1; var bytes=1;
if(bbs.command_str.substr(0,1)=="\r")
bbs.command_str='';
if(!bbs.command_str.length) { // Nothing in STR already? if(!bbs.command_str.length) { // Nothing in STR already?
if(user.settings & USER_COLDKEYS) if(user.settings & USER_COLDKEYS)
bbs.command_str=console.getstr("",60,0)+"\r"; bbs.command_str=console.getstr("",60,0);
else else
bbs.command_str=getkeye(); bbs.command_str=getkeye();
} }
...@@ -27,34 +26,42 @@ function get_next_keys(keys, have_part) ...@@ -27,34 +26,42 @@ function get_next_keys(keys, have_part)
var ret=''; var ret='';
var i; var i;
// If there is something in STR, and coldkeys, grab from STR if(have_part) {
if((bbs.command_str.length && (user.settings & USER_COLDKEYS)) || (have_part && !(user.settings & USER_COLDKEYS))) { bbs.command_str=coldfuncs_last_hotkey;
if((i=keys.indexOf(bbs.command_str.substr(0,1)))!=-1) { coldfuncs_last_hotkey='';
bbs.command_str=bbs.command_str.substr(i); }
} while(ret=get_next_key()) {
if(keys.indexOf(bbs.command_str.substr(0,1))!=-1) { if(keys.indexOf(ret)!=-1) {
ret=bbs.command_str.substr(0,1);
bbs.command_str=bbs.command_str.substr(1);
return(ret); return(ret);
} }
bbs.command_str='';
} }
return(console.getkeys(keys));
} }
function get_next_num(max, have_part) function get_next_num(max, have_part)
{ {
var ret=''; var ret='';
var use_str=false; var use_str=false;
var ch;
if(have_part) {
bbs.command_str=coldfuncs_last_hotkey;
coldfuncs_last_hotkey='';
have_part=false;
}
if(bbs.command_str.length && (user.settings & USER_COLDKEYS)) if(bbs.command_str.length && (user.settings & USER_COLDKEYS))
use_str=true; use_str=true;
while(ret+=get_next_keys("0123456789\r\n",have_part)) { while(1) {
if(parseInt(ret+'0') > max) ch=get_next_keys("0123456789\r\n",have_part);
return(parseInt(ret)); if(ch==undefined || ch=='')
if(ret.search(/[\r\n]/)!=-1) return(-1);
return(parseInt(ret)); if(parseInt(ret+ch)<=max) {
ret+=ch;
write(ch);
if(parseInt(ret+'0') > max)
return(parseInt(ret));
if(ret.search(/[\r\n]/)!=-1)
return(parseInt(ret));
}
// Using coldkeys and there was something in STR and there was a number // Using coldkeys and there was something in STR and there was a number
if(use_str && !bbs.command_str.length && parseInt(ret)>0) if(use_str && !bbs.command_str.length && parseInt(ret)>0)
return(parseInt(ret)); return(parseInt(ret));
...@@ -67,9 +74,15 @@ function get_next_str(def_val, max_len, mode_bits, have_part) ...@@ -67,9 +74,15 @@ function get_next_str(def_val, max_len, mode_bits, have_part)
var ret=''; var ret='';
var use_str=false; var use_str=false;
if(have_part) {
bbs.command_str=coldfuncs_last_hotkey;
coldfuncs_last_hotkey='';
have_part=false;
}
if(bbs.command_str.length && (user.settings & USER_COLDKEYS)) if(bbs.command_str.length && (user.settings & USER_COLDKEYS))
use_str=true; use_str=true;
while(ret+=get_next_key()) { while(ret+=get_next_key()) {
write(ret.substr(-1));
if(ret.search(/[\r\n]/)!=-1) if(ret.search(/[\r\n]/)!=-1)
return(ret.replace(/[\r\n]/g,'')); return(ret.replace(/[\r\n]/g,''));
// Using coldkeys and there was something in STR // Using coldkeys and there was something in STR
...@@ -94,7 +107,9 @@ function getkeye() ...@@ -94,7 +107,9 @@ function getkeye()
} }
key=key+key2; key=key+key2;
} }
break; if(key != '')
break;
} }
coldfuncs_last_hotkey=key.substr(-1);
return(key); return(key);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment