From: Johan Euphrosine Date: Sun, 22 Aug 2010 03:55:34 +0000 (+0200) Subject: add home/end support in rxvt and readline tests X-Git-Tag: v0.3.0~250 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd3e84499e9848aa4bd644049b322ef40ef5ffb6;p=platform%2Fupstream%2Fnodejs.git add home/end support in rxvt and readline tests --- diff --git a/lib/readline.js b/lib/readline.js index 2b2c18c..e8f4d54 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 0000000..af1b73c --- /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);