From fd3e84499e9848aa4bd644049b322ef40ef5ffb6 Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Sun, 22 Aug 2010 05:55:34 +0200 Subject: [PATCH] add home/end support in rxvt and readline tests --- lib/readline.js | 8 +++++-- test/simple/test-readline.js | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 test/simple/test-readline.js diff --git a/lib/readline.js b/lib/readline.js index 2b2c18c4f7..e8f4d542d5 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -361,10 +361,14 @@ Interface.prototype._ttyWrite = function (b) { this.cursor++; this.output.write('\x1b[0C'); } - } else if ((b[1] === 91 || b[1] === 79) && b[2] === 72) { // home + } else if ((b[1] === 91 && b[2] === 72) || + (b[1] === 79 && b[2] === 72) || + (b[1] === 91 && b[2] === 55)) { // home this.cursor = 0; this._refreshLine(); - } else if ((b[1] === 91 || b[1] === 79) && b[2] === 70) { // end + } else if ((b[1] === 91 && b[2] === 70) || + (b[1] === 79 && b[2] === 70) || + (b[1] === 91 && b[2] === 56)) { // end this.cursor = this.line.length; this._refreshLine(); } else if (b[1] === 91 && b[2] === 65) { // up arrow diff --git a/test/simple/test-readline.js b/test/simple/test-readline.js new file mode 100644 index 0000000000..af1b73cc0d --- /dev/null +++ b/test/simple/test-readline.js @@ -0,0 +1,43 @@ +common = require("../common"); +assert = common.assert; +var readline = require("readline"); + +var key = { + xterm: { + home: [27, 91, 72], + end: [27, 91, 70] + }, + gnome: { + home: [27, 79, 72], + end: [27, 79, 70] + }, + rxvt: { + home: [27, 91, 55], + end: [27, 91, 56] + } +}; + +var fakestream = { + fd: 1, + write: function(bytes) { + } +}; + +var rl = readline.createInterface(fakestream, function (text) { + return [[], ""]; +}); + +rl.write('foo'); +assert.equal(3, rl.cursor); +rl.write(key.xterm.home); +assert.equal(0, rl.cursor); +rl.write(key.xterm.end); +assert.equal(3, rl.cursor); +rl.write(key.rxvt.home); +assert.equal(0, rl.cursor); +rl.write(key.rxvt.end); +assert.equal(3, rl.cursor); +rl.write(key.gnome.home); +assert.equal(0, rl.cursor); +rl.write(key.gnome.end); +assert.equal(3, rl.cursor);