From e49be4768be8c84daca6c98a1aa344bc5065590e Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Wed, 25 Aug 2010 10:18:24 +0200 Subject: [PATCH] add readline support for meta-d --- lib/readline.js | 16 ++++++++++++++++ test/simple/test-readline.js | 21 +++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index e387194d6f..10e614f765 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -377,6 +377,22 @@ Interface.prototype._ttyWrite = function (b) { } this.cursor = this.line.length; this._refreshLine(); + } else if (b[1] === 100 && this.cursor < this.line.length) { // meta-d delete forward word + next_word = this.line.slice(this.cursor, this.line.length) + .search(/\w/); + if (next_word !== -1) { + next_non_word = this.line.slice(this.cursor + next_word, this.line.length) + .search(/\W/); + if (next_non_word !== -1) { + this.line = this.line.slice(this.cursor + next_word + next_non_word); + this.cursor = 0; + this._refreshLine(); + break; + } + } + this.line = ''; + this.cursor = 0; + this._refreshLine(); } else if (b[1] === 91 && b[2] === 68) { // left arrow if (this.cursor > 0) { this.cursor--; diff --git a/test/simple/test-readline.js b/test/simple/test-readline.js index 9ed68e3d59..edc830fe12 100644 --- a/test/simple/test-readline.js +++ b/test/simple/test-readline.js @@ -7,7 +7,8 @@ var key = { home: [27, 91, 72], end: [27, 91, 70], metab: [27, 98], - metaf: [27, 102] + metaf: [27, 102], + metad: [27, 100] }, gnome: { home: [27, 79, 72], @@ -88,4 +89,20 @@ written_bytes_length = rl.written_bytes.length; rl.write(key.xterm.metab); assert.equal(0, rl.cursor); refreshed = written_bytes_length !== rl.written_bytes.length; -assert.equal(true, refreshed); \ No newline at end of file +assert.equal(true, refreshed); + +rl = readlineFakeStream(); +rl.write('foo bar.hop/zoo'); +rl.write(key.xterm.home); +rl.write(key.xterm.metad); +assert.equal(0, rl.cursor); +assert.equal(' bar.hop/zoo', rl.line); +rl.write(key.xterm.metad); +assert.equal(0, rl.cursor); +assert.equal('.hop/zoo', rl.line); +rl.write(key.xterm.metad); +assert.equal(0, rl.cursor); +assert.equal('/zoo', rl.line); +rl.write(key.xterm.metad); +assert.equal(0, rl.cursor); +assert.equal('', rl.line);