add readline support for meta-d

This commit is contained in:
Johan Euphrosine 2010-08-25 10:18:24 +02:00 коммит произвёл Ryan Dahl
Родитель 37b6e10684
Коммит e49be4768b
2 изменённых файлов: 35 добавлений и 2 удалений

Просмотреть файл

@ -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--;

Просмотреть файл

@ -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);
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);