Commit a3f120a1 authored by deuce's avatar deuce
Browse files

Turn the keybuf into an array rather than a string so that extended keys

can go into it.
Add support for (some) extended keys with the local console.
parent 1b4b3e5d
......@@ -9,7 +9,42 @@ if (js.global.conio !== undefined && dk.console.local) {
conio.setcursortype(2);
dk.console.input_queue_callback.push(function() {
'use strict';
var ch;
if (conio.kbhit) {
ch = conio.getch();
if (ch === 0) {
ch = conio.getch();
switch(ch) {
case 0x47:
return dk.console.key.KEY_HOME;
case 72:
return dk.console.key.KEY_UP;
case 0x4f:
return dk.console.key.KEY_END;
case 80:
return dk.console.key.KEY_DOWN;
case 0x52:
return dk.console.key.KEY_INS;
case 0x53:
return dk.console.key.KEY_DEL;
case 0x4b:
return dk.console.key.KEY_LEFT;
case 0x4d:
return dk.console.key.KEY_RIGHT;
case 0x49:
return dk.console.key.KEY_PGUP;
case 0x51:
return dk.console.key.KEY_PGDOWN;
default:
if (ch >= 0x3a && ch <= 0x44)
return dk.console.key['KEY_F'+(ch - 0x39)];
if (ch >= 0x7a && ch <= 0x7b)
return dk.console.key['KEY_F'+(ch - 0x6f)];
}
return;
}
return ascii(conio.getch());
}
});
......
......@@ -257,7 +257,7 @@ var dk = {
rows:24, // Rows in users terminal
cols:80, // Columns in users terminal
keybuf:'',
keybuf:[],
input_queue:new Queue("dorkit_input" + (js.global.bbs === undefined ? '' : bbs.node_num)),
/*
......@@ -392,7 +392,7 @@ var dk = {
*/
getblock:function(sx,sy,ex,ey) {
'use strict';
return this.remote_screen.graphic.get(sx,sy,ex,ey);
return this.local_io.screen.graphic.get(sx,sy,ex,ey);
},
/*
......@@ -480,7 +480,7 @@ var dk = {
for (i = 0; i < this.input_queue_callback.length; i += 1) {
d = this.input_queue_callback[i]();
if (d !== undefined) {
this.keybuf += d;
this.keybuf.push(d);
}
}
if (this.keybuf.length > 0) {
......@@ -505,8 +505,7 @@ var dk = {
var m;
if (this.keybuf.length > 0) {
ret = this.keybuf[0];
this.keybuf = this.keybuf.substr(1);
ret = this.keybuf.shift();
return ret;
}
if (!this.waitkey(0)) {
......@@ -553,21 +552,28 @@ var dk = {
'use strict';
var ret;
if (this.keybuf.length > 0) {
ret = this.keybuf[0];
this.keybuf = this.keybuf.substr(1);
return ret;
}
if (!this.waitkey(0)) {
return undefined;
}
ret = this.input_queue.read();
if (ret.length > 1) {
ret=ret.replace(/^.*\x00/,'');
this.keybuf = ret.substr(1);
ret = ret[0];
while (1) {
if (this.keybuf.length > 0) {
do {
ret = this.keybuf.shift();
} while(ret.length > 1 && ret.indexOf('\x00') === -1);
return ret;
}
if (!this.waitkey(0)) {
return undefined;
}
ret = this.input_queue.read();
if (ret.length > 1) {
if (ret.indexOf('\x00') > -1) {
ret=ret.replace(/^.*\x00/,'');
ret.split('').forEach(function(ch) {
this.keybuf.push(ch);
}, this);
}
}
else
return ret;
}
return ret;
},
getstr_defaults:{
timeout:undefined, // Timeout, undefined for "wait forever"
......
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