Browse Source

add readline support for meta-d

v0.7.4-release
Johan Euphrosine 15 years ago
committed by Ryan Dahl
parent
commit
e49be4768b
  1. 16
      lib/readline.js
  2. 21
      test/simple/test-readline.js

16
lib/readline.js

@ -377,6 +377,22 @@ Interface.prototype._ttyWrite = function (b) {
} }
this.cursor = this.line.length; this.cursor = this.line.length;
this._refreshLine(); 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 } else if (b[1] === 91 && b[2] === 68) { // left arrow
if (this.cursor > 0) { if (this.cursor > 0) {
this.cursor--; this.cursor--;

21
test/simple/test-readline.js

@ -7,7 +7,8 @@ var key = {
home: [27, 91, 72], home: [27, 91, 72],
end: [27, 91, 70], end: [27, 91, 70],
metab: [27, 98], metab: [27, 98],
metaf: [27, 102] metaf: [27, 102],
metad: [27, 100]
}, },
gnome: { gnome: {
home: [27, 79, 72], home: [27, 79, 72],
@ -88,4 +89,20 @@ written_bytes_length = rl.written_bytes.length;
rl.write(key.xterm.metab); rl.write(key.xterm.metab);
assert.equal(0, rl.cursor); assert.equal(0, rl.cursor);
refreshed = written_bytes_length !== rl.written_bytes.length; refreshed = written_bytes_length !== rl.written_bytes.length;
assert.equal(true, refreshed); 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);

Loading…
Cancel
Save