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

Add mouse support.

This does have a terrible hack where it mangles ESC sequences going into
ungetstr() because inkey() will mangle them coming out... inkey() puts ESC
arguments at the end of the key buffer.  If the key buffer isn't empty,
this results in a re-ordering.
parent 867ab899
Branches
Tags
No related merge requests found
...@@ -51,6 +51,17 @@ var lastmessage_type=0; ...@@ -51,6 +51,17 @@ var lastmessage_type=0;
var orig_passthru=console.ctrlkey_passthru; var orig_passthru=console.ctrlkey_passthru;
var hangup_now=false; var hangup_now=false;
/*
* TODO: This mangles the ANSI sequence so it will pass through inkey()
* properly... inkey re-inserts ESC back into the stream using ungetkey()
* which changes the order of if the string, putting sequence arguments
* at the end.
*/
function mangle_mouse_seq(seq)
{
return seq[0]+seq[5]+seq.substr(1,4);
}
function handle_a_ctrlkey(key) function handle_a_ctrlkey(key)
{ {
var i; var i;
...@@ -233,6 +244,7 @@ ShellLB.prototype.rpadding="\xb3"; ...@@ -233,6 +244,7 @@ ShellLB.prototype.rpadding="\xb3";
ShellLB.prototype.timeout=100; ShellLB.prototype.timeout=100;
ShellLB.prototype.callback = message_callback; ShellLB.prototype.callback = message_callback;
ShellLB.prototype.hotkeys = KEY_LEFT+KEY_RIGHT+"\b\x7f\x1b"+ctrl('O')+ctrl('U')+ctrl('T')+ctrl('K')+ctrl('P'); ShellLB.prototype.hotkeys = KEY_LEFT+KEY_RIGHT+"\b\x7f\x1b"+ctrl('O')+ctrl('U')+ctrl('T')+ctrl('K')+ctrl('P');
ShellLB.prototype.mouse_miss_key = '\b';
function Mainbar() function Mainbar()
{ {
...@@ -241,6 +253,7 @@ function Mainbar() ...@@ -241,6 +253,7 @@ function Mainbar()
this.xpos=2; this.xpos=2;
this.ypos=1; this.ypos=1;
this.hotkeys=KEY_DOWN+";"+ctrl('O')+ctrl('U')+ctrl('T')+ctrl('K')+ctrl('P'); this.hotkeys=KEY_DOWN+";"+ctrl('O')+ctrl('U')+ctrl('T')+ctrl('K')+ctrl('P');
this.mouse_miss_key = undefined;
this.add("|File","F",undefined,undefined,undefined,bbs.compare_ars("REST T")); this.add("|File","F",undefined,undefined,undefined,bbs.compare_ars("REST T"));
this.add("|Messages","M"); this.add("|Messages","M");
this.add("|Email","E",undefined,undefined,undefined,bbs.compare_ars("REST SE")); this.add("|Email","E",undefined,undefined,undefined,bbs.compare_ars("REST SE"));
...@@ -639,8 +652,13 @@ while(bbs.online) { ...@@ -639,8 +652,13 @@ while(bbs.online) {
main_right(); main_right();
break; break;
} }
if(x_sec=='\b' || x_sec=='\x7f' || x_sec=='\x1b') if(x_sec=='\b' || x_sec=='\x7f' || x_sec=='\x1b') {
if (xtrnsec.mouse_miss_str !== undefined) {
console.ungetstr(mangle_mouse_seq(xtrnsec.mouse_miss_str));
delete xtrnsec.mouse_miss_str;
}
break; break;
}
if(x_sec==ctrl('O') if(x_sec==ctrl('O')
|| x_sec==ctrl('U') || x_sec==ctrl('U')
|| x_sec==ctrl('T') || x_sec==ctrl('T')
...@@ -663,6 +681,10 @@ while(bbs.online) { ...@@ -663,6 +681,10 @@ while(bbs.online) {
} }
if(x_prog==KEY_RIGHT || x_prog=='\b' || x_prog=='\x7f' || x_prog=='\x1b') { if(x_prog==KEY_RIGHT || x_prog=='\b' || x_prog=='\x7f' || x_prog=='\x1b') {
this_xtrnsec.erase(); this_xtrnsec.erase();
if (this_xtrnsec.mouse_miss_str !== undefined) {
console.ungetstr(mangle_mouse_seq(this_xtrnsec.mouse_miss_str));
delete this_xtrnsec.mouse_miss_str;
}
break; break;
} }
if(x_prog==ctrl('O') if(x_prog==ctrl('O')
...@@ -758,6 +780,10 @@ while(bbs.online) { ...@@ -758,6 +780,10 @@ while(bbs.online) {
break infoloop; break infoloop;
case KEY_RIGHT: case KEY_RIGHT:
case '\b': case '\b':
if (userlists.mouse_miss_str !== undefined) {
console.ungetstr(mangle_mouse_seq(userlists.mouse_miss_str));
delete userlists.mouse_miss_str;
}
case '\x7f': case '\x7f':
case '\x1b': case '\x1b':
userlists.erase(); userlists.erase();
...@@ -797,6 +823,10 @@ while(bbs.online) { ...@@ -797,6 +823,10 @@ while(bbs.online) {
done=1; done=1;
break infoloop; break infoloop;
case '\b': case '\b':
if (infomenu.mouse_miss_str !== undefined) {
console.ungetstr(mangle_mouse_seq(infomenu.mouse_miss_str));
delete infomenu.mouse_miss_str;
}
case '\x7f': case '\x7f':
case '\x1b': case '\x1b':
break infoloop; break infoloop;
...@@ -914,6 +944,10 @@ function show_filemenu() ...@@ -914,6 +944,10 @@ function show_filemenu()
menus_displayed.pop(); menus_displayed.pop();
return; return;
case '\b': case '\b':
if (filemenu.mouse_miss_str !== undefined) {
console.ungetstr(mangle_mouse_seq(filemenu.mouse_miss_str));
delete filemenu.mouse_miss_str;
}
case '\x7f': case '\x7f':
case '\x1b': case '\x1b':
filemenu.erase(); filemenu.erase();
...@@ -1571,6 +1605,10 @@ function show_messagemenu() ...@@ -1571,6 +1605,10 @@ function show_messagemenu()
main_left(); main_left();
return; return;
case '\b': case '\b':
if (messagemenu.mouse_miss_str !== undefined) {
console.ungetstr(mangle_mouse_seq(messagemenu.mouse_miss_str));
delete messagemenu.mouse_miss_str;
}
case '\x7f': case '\x7f':
case '\x1b': case '\x1b':
cleararea(messagemenu.xpos,messagemenu.ypos,messagemenu.items[0].text.length,messagemenu.items.length,true); cleararea(messagemenu.xpos,messagemenu.ypos,messagemenu.items[0].text.length,messagemenu.items.length,true);
...@@ -1975,6 +2013,10 @@ function show_emailmenu() ...@@ -1975,6 +2013,10 @@ function show_emailmenu()
menus_displayed.pop(); menus_displayed.pop();
return; return;
case '\b': case '\b':
if (emailmenu.mouse_miss_str !== undefined) {
console.ungetstr(mangle_mouse_seq(emailmenu.mouse_miss_str));
delete emailmenu.mouse_miss_str;
}
case '\x7f': case '\x7f':
case '\x1b': case '\x1b':
cleararea(emailmenu.xpos,emailmenu.ypos,emailmenu.items[0].text.length,emailmenu.items.length,true); cleararea(emailmenu.xpos,emailmenu.ypos,emailmenu.items[0].text.length,emailmenu.items.length,true);
...@@ -2133,6 +2175,10 @@ function show_chatmenu() ...@@ -2133,6 +2175,10 @@ function show_chatmenu()
menus_displayed.pop(); menus_displayed.pop();
return; return;
case '\b': case '\b':
if (chatmenu.mouse_miss_str !== undefined) {
console.ungetstr(mangle_mouse_seq(chatmenu.mouse_miss_str));
delete chatmenu.mouse_miss_str;
}
case '\x7f': case '\x7f':
case '\x1b': case '\x1b':
cleararea(chatmenu.xpos,chatmenu.ypos,chatmenu.items[0].text.length,chatmenu.items.length,true); cleararea(chatmenu.xpos,chatmenu.ypos,chatmenu.items[0].text.length,chatmenu.items.length,true);
...@@ -2290,6 +2336,10 @@ function show_settingsmenu() ...@@ -2290,6 +2336,10 @@ function show_settingsmenu()
menus_displayed.pop(); menus_displayed.pop();
return; return;
case '\b': case '\b':
if (settingsmenu.mouse_miss_str !== undefined) {
console.ungetstr(mangle_mouse_seq(settingsmenu.mouse_miss_str));
delete settingsmenu.mouse_miss_str;
}
case '\x7f': case '\x7f':
case '\x1b': case '\x1b':
settingsmenu.erase(); settingsmenu.erase();
......
...@@ -76,6 +76,8 @@ Lightbar.prototype.hblanks=2; ...@@ -76,6 +76,8 @@ Lightbar.prototype.hblanks=2;
Lightbar.prototype.hotkeys=''; Lightbar.prototype.hotkeys='';
Lightbar.prototype.callback=undefined; Lightbar.prototype.callback=undefined;
Lightbar.prototype.timeout=0; Lightbar.prototype.timeout=0;
Lightbar.prototype.mouse_miss_key=undefined;
Lightbar.prototype.mouse_miss_str=undefined;
Lightbar.prototype.add = function(txt, retval, width, lpadding, rpadding, disabled, nodraw) Lightbar.prototype.add = function(txt, retval, width, lpadding, rpadding, disabled, nodraw)
{ {
...@@ -138,22 +140,80 @@ Lightbar.prototype.getval = function(current,key) ...@@ -138,22 +140,80 @@ Lightbar.prototype.getval = function(current,key)
var ret=undefined; var ret=undefined;
var last_cur; var last_cur;
var ansi = ''; var ansi = '';
var button;
var x;
var y;
function restuff()
{
console.ungetstr(ansi.substr(1));
ansi = '';
}
if(!this.nodraw) if(!this.nodraw)
this.draw(); this.draw();
delete this.mouse_miss_str;
/* Main loop */ /* Main loop */
while(bbs.online) { while(bbs.online) {
last_cur=this.current; last_cur=this.current;
/* Get input */ /* Get input */
if(key==undefined || key=='' || key==null || ansi.length > 0) { if(key==undefined || key=='' || key==null || ansi.length > 0) {
if(this.callback != undefined) if(this.callback != undefined)
this.callback(); this.callback();
console.write("\x1b[?1000h");
if(this.timeout>1) if(this.timeout>1)
key=console.inkey(K_UPPER,this.timeout); key=console.inkey(K_UPPER,this.timeout);
else else
key=console.getkey(K_UPPER|K_NOSPIN); key=console.getkey(K_UPPER|K_NOSPIN);
console.write("\x1b[?1000l");
if (key !== '') {
if (key === '\x1b') {
if (ansi.length > 0) {
ansi += key;
restuff();
key = '\x1b';
}
else {
ansi += key;
key = undefined;
}
}
else if (ansi.length === 1) {
if (key === '[') {
ansi += key;
key = undefined;
}
else {
ansi += key;
restuff();
key = '\x1b';
}
}
else if (ansi.length === 2) {
if (key === 'M') {
ansi += key;
key = undefined;
}
else {
ansi += key;
restuff();
key = '\x1b';
}
}
else if (ansi.length > 2) {
ansi += key;
key = undefined;
if (ansi.length >= 6) {
button = ascii(ansi[3]) - ascii(' ');
x = ascii(ansi[4]) - ascii('!') + 1;
y = ascii(ansi[5]) - ascii('!') + 1;
key = 'Mouse';
this.mouse_miss_str = ansi;
ansi = '';
}
}
}
} }
else { else {
...@@ -163,6 +223,27 @@ Lightbar.prototype.getval = function(current,key) ...@@ -163,6 +223,27 @@ Lightbar.prototype.getval = function(current,key)
} }
switch(key) { switch(key) {
case 'Mouse':
ansi = '';
if (button === 0) {
var hit = this.mouse_hit(x, y);
if (hit === -1) {
if (this.mouse_miss_key !== undefined) {
return this.mouse_miss_key;
}
}
else {
delete this.mouse_miss_str;
this.draw(hit);
this.nodraw=false;
if(this.items[this.current].retval==undefined)
return(undefined);
return(this.items[this.current].retval);
}
}
else
delete this.mouse_miss_str;
break;
case KEY_UP: case KEY_UP:
if(this.direction==0) { if(this.direction==0) {
do { do {
...@@ -248,6 +329,77 @@ Lightbar.prototype.getval = function(current,key) ...@@ -248,6 +329,77 @@ Lightbar.prototype.getval = function(current,key)
} }
}; };
Lightbar.prototype.mouse_hit = function(x, y)
{
if(this.direction < 0 || this.direction > 1) {
alert("Unknown lightbar direction!");
return -1;
}
var i;
var curx=this.xpos;
var cury=this.ypos;
for(i=0; i<this.items.length; i++) {
var width;
// Some basic validation.
if(this.items[i]==undefined) {
alert("Sparse items array!");
return -1;
}
if(this.items[i].text==undefined) {
alert("No text for item "+i+"!");
return -1;
}
// Set up a cleaned version for length calculations.
var cleaned=this.items[i].text;
cleaned=cleaned.replace(/\|/g,'');
/*
* Calculate the width. Forced width, item width, text width
* In that order. First one wins.
*/
if(this.force_width>0)
width=this.force_width;
else {
if(this.items[i].width!=undefined)
width=this.items[i].width;
else
width=cleaned.length;
}
var lpadding=this.lpadding;
if(this.items[i].lpadding!=undefined)
lpadding=this.items[i].lpadding;
if(lpadding != undefined && lpadding != null) {
curx+=lpadding.length;
}
if (cury === y) {
if (x >= curx && x <= curx + width)
return i;
}
curx += width;
var rpadding=this.rpadding;
if(this.items[i].rpadding!=undefined)
rpadding=this.items[i].rpadding;
curx += rpadding.length;
if(this.direction==0) {
cury++;
curx=this.xpos;
}
else {
curx += this.hblanks;
}
}
return -1;
};
Lightbar.prototype.draw = function(current) Lightbar.prototype.draw = function(current)
{ {
var attr=this.bg<<4|this.fg; var attr=this.bg<<4|this.fg;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment