Browse Source

add home/end support in rxvt and readline tests

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

8
lib/readline.js

@ -361,10 +361,14 @@ Interface.prototype._ttyWrite = function (b) {
this.cursor++; this.cursor++;
this.output.write('\x1b[0C'); 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.cursor = 0;
this._refreshLine(); 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.cursor = this.line.length;
this._refreshLine(); this._refreshLine();
} else if (b[1] === 91 && b[2] === 65) { // up arrow } else if (b[1] === 91 && b[2] === 65) { // up arrow

43
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);
Loading…
Cancel
Save