From f7a1e3e87d6d96d5e74d4a1eb35aefe78b924310 Mon Sep 17 00:00:00 2001 From: deuce <> Date: Thu, 12 Nov 2015 08:45:40 +0000 Subject: [PATCH] Move common ANSI generation into ansi_console which is now load()ed from jsexec_console and socket_console to avoid copy pasta. Use 0/0 origin for all things. Just because ANSI uses 1/1 origin doesn't mean we have to. --- exec/dorkit/graphic.js | 2 +- exec/dorkit/jsexec_console.js | 39 +++----------------------------- exec/dorkit/sbbs_console.js | 2 +- exec/dorkit/socket_console.js | 42 +++++------------------------------ 4 files changed, 10 insertions(+), 75 deletions(-) diff --git a/exec/dorkit/graphic.js b/exec/dorkit/graphic.js index 01e1a57fc9..ac40459dab 100644 --- a/exec/dorkit/graphic.js +++ b/exec/dorkit/graphic.js @@ -486,7 +486,7 @@ Graphic.prototype.draw = function(xpos,ypos,width,height,xoff,yoff) alert("Attempt to draw from outside of graphic: "+xoff+":"+yoff+" "+width+"x"+height+" "+this.width+"x"+this.height); return(false); } - if(xpos+width-1 > dk.console.cols || ypos+height-1 > dk.console.rows) { + if(xpos+width > dk.console.cols || ypos+height > dk.console.rows) { alert("Attempt to draw outside of screen: " + (xpos+width-1) + "x" + (ypos+height-1)); return(false); } diff --git a/exec/dorkit/jsexec_console.js b/exec/dorkit/jsexec_console.js index b1df0f3aed..ed2e877815 100644 --- a/exec/dorkit/jsexec_console.js +++ b/exec/dorkit/jsexec_console.js @@ -1,38 +1,5 @@ -/* - * Clears the current screen and moves to location 1,1 - */ +load("ansi_console.js"); -dk.console.remote_io = { - clear:function() { - this.print("\x1b[2J\x1b[1;1H"); - }, - - /* - * Clears to end of line. - * Not available witout ANSI (???) - */ - cleareol:function() { - if(dk.console.ansi) - this.print('\x1b[K'); - }, - - /* - * Moves the cursor to the specified position. - * returns false on error. - * Not available without ANSI - */ - gotoxy:function(x,y) { - if(dk.console.ansi) - this.print(format("\x1b[%u;%uH", y, x)); - }, - - /* - * Writes a string unmodified. - */ - print:function(string) { - write(string); - }, +dk.console.remote_io.print = function(string) { + write(string); }; - -var input_queue = load(true, "jsexec_input.js"); -js.on_exit("input_queue.write(''); input_queue.poll(0x7fffffff);"); diff --git a/exec/dorkit/sbbs_console.js b/exec/dorkit/sbbs_console.js index 836e4d168f..7119ef17c1 100644 --- a/exec/dorkit/sbbs_console.js +++ b/exec/dorkit/sbbs_console.js @@ -27,7 +27,7 @@ dk.console.remote_io = { * Not available without ANSI */ gotoxy:function(x,y) { - console.gotoxy(x,y); + console.gotoxy(x+1,y+1); }, /* diff --git a/exec/dorkit/socket_console.js b/exec/dorkit/socket_console.js index 4ce9541016..a3ca227a1e 100644 --- a/exec/dorkit/socket_console.js +++ b/exec/dorkit/socket_console.js @@ -1,41 +1,9 @@ -/* - * Clears the current screen to black and moves to location 1,1 - */ +load("ansi_console.js"); -dk.console.remote_io = { - sock:new Socket(true, dk.connection.socket), - clear:function() { - this.print("\x0c"); - }, - - /* - * Clears to end of line. - * Not available witout ANSI (???) - */ - cleareol:function() { - if(dk.console.ansi) - this.print('\x1b[K'); - }, - - /* - * Moves the cursor to the specified position. - * returns false on error. - * Not available without ANSI - */ - gotoxy:function(x,y) { - if(dk.console.ansi) - this.print(format("\x1b[%u;%uH", y, x)); - }, - - /* - * Writes a string unmodified. - */ - print:function(string) { - this.sock.write(string.replace(/\xff/g, "\xff\xff")); - }, -}; +dk.console.remote_io.sock = new Socket(true, dk.connection.socket); if (!dk.console.remote_io.sock.is_connected) throw("Unable to create socket object"); -var input_queue = load(true, "socket_input.js", argv[0], argv[1]); -js.on_exit("input_queue.write(''); input_queue.poll(0x7fffffff);"); +dk.console.remote_io.print = function(string) { + this.sock.write(string.replace(/\xff/g, "\xff\xff")); +}; -- GitLab