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

Add new POSITION_REPORT key. If this key is returned from getkey(), indicates

that a position report was received, and the result stored in
dk.console.last_pos.x and dk.console.last_pos.y.
parent e77b123e
Branches
Tags
No related merge requests found
...@@ -7,6 +7,7 @@ var ai={ ...@@ -7,6 +7,7 @@ var ai={
var i; var i;
var q; var q;
var byte; var byte;
var m;
if (ch == '\x1b') { if (ch == '\x1b') {
if (this.ansi_started) { if (this.ansi_started) {
...@@ -156,12 +157,16 @@ var ai={ ...@@ -156,12 +157,16 @@ var ai={
this.ansi_started = 0; this.ansi_started = 0;
break; break;
} }
m = this.charbuf.match(/^\x1b[([0-9]+);([0-9]+)R$/);
if (m !== null) {
q.write(format("POSITION_"+m[1]+"_"+m[2]+"\x00"+this.charbuf);
}
if (!this.ansi_started) if (!this.ansi_started)
return; return;
} }
// Timeout out waiting for escape sequence. // Timeout out waiting for escape sequence.
if (this.charbuf.length > 5 || this.ansi_started + 100 < Date.now()) { if (this.charbuf.length > 10 || this.ansi_started + 100 < Date.now()) {
for(i=0; i<this.charbuf.length; i++) { for(i=0; i<this.charbuf.length; i++) {
byte = this.charbuf.substr(i,1) byte = this.charbuf.substr(i,1)
q.write(byte); q.write(byte);
......
...@@ -7,6 +7,7 @@ load("graphic.js"); ...@@ -7,6 +7,7 @@ load("graphic.js");
var dk = { var dk = {
console:{ console:{
last_pos:{x:1, y:1},
key:{ key:{
CTRL_A:'\x01', CTRL_A:'\x01',
CTRL_B:'\x02', CTRL_B:'\x02',
...@@ -67,7 +68,8 @@ var dk = { ...@@ -67,7 +68,8 @@ var dk = {
KEY_PGUP:'KEY_PGUP', KEY_PGUP:'KEY_PGUP',
KEY_PGDOWN:'KEY_PGDOWN', KEY_PGDOWN:'KEY_PGDOWN',
KEY_INS:'KEY_INS', KEY_INS:'KEY_INS',
KEY_DEL:'KEY_DEL' KEY_DEL:'KEY_DEL',
POSITION_REPORT:'POSITION_REPORT'
}, },
x:1, // Current column (1-based) x:1, // Current column (1-based)
...@@ -409,6 +411,7 @@ var dk = { ...@@ -409,6 +411,7 @@ var dk = {
*/ */
getkey:function() { getkey:function() {
var ret; var ret;
var m;
if (this.keybuf.length > 0) { if (this.keybuf.length > 0) {
var ret = this.keybuf.substr(0,1); var ret = this.keybuf.substr(0,1);
...@@ -419,8 +422,17 @@ var dk = { ...@@ -419,8 +422,17 @@ var dk = {
return undefined; return undefined;
var q = new Queue("dorkit_input"); var q = new Queue("dorkit_input");
ret = q.read(); ret = q.read();
if (ret.length > 1) if (ret.length > 1) {
if (ret.substr(0, 9) === 'POSITION_') {
m = ret.match(/^POSITION_([0-9]+)_([0-9]+)/);
if (m == NULL)
return undefined;
this.last_pos.x = parseInt(m[2], 10);
this.last_pos.y = parseInt(m[1], 10);
ret = 'POSITION_REPORT';
}
ret=ret.replace(/\x00.*$/,''); ret=ret.replace(/\x00.*$/,'');
}
return ret; return ret;
}, },
...@@ -513,6 +525,7 @@ var dk = { ...@@ -513,6 +525,7 @@ var dk = {
}, },
detect_ansi:function() { detect_ansi:function() {
var start = Date.now();
this.console.remote_io.print("\x1b[s" + // Save cursor position. this.console.remote_io.print("\x1b[s" + // Save cursor position.
"\x1b[255B" + // Locate as far down as possible "\x1b[255B" + // Locate as far down as possible
"\x1b[255C" + // Locate as far right as possible "\x1b[255C" + // Locate as far right as possible
...@@ -520,6 +533,12 @@ var dk = { ...@@ -520,6 +533,12 @@ var dk = {
"\x1b[6n" + // Get cursor position "\x1b[6n" + // Get cursor position
"\x1b[u" // Restore cursor position "\x1b[u" // Restore cursor position
); );
while(Date.now() - start < 500) {
if(waitkey(500))
if (getkey() == key.console.POSITION_REPORT)
return true;
}
return false;
}, },
parse_dropfile:function(path) { parse_dropfile:function(path) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment