Browse Source

Fix style in readline

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
2d09ef8541
  1. 55
      lib/readline.js

55
lib/readline.js

@ -364,7 +364,9 @@ Interface.prototype._ttyWrite = function (b) {
case 27: /* escape sequence */ case 27: /* escape sequence */
var next_word, next_non_word, previous_word, previous_non_word; var next_word, next_non_word, previous_word, previous_non_word;
if (b[1] === 98 && this.cursor > 0) { // meta-b - backward word
if (b[1] === 98 && this.cursor > 0) {
// meta-b - backward word
previous_word = this.line.slice(0, this.cursor) previous_word = this.line.slice(0, this.cursor)
.split('').reverse().join('') .split('').reverse().join('')
.search(/\w/); .search(/\w/);
@ -380,11 +382,13 @@ Interface.prototype._ttyWrite = function (b) {
} }
this.cursor = 0; this.cursor = 0;
this._refreshLine(); this._refreshLine();
} else if (b[1] === 102 && this.cursor < this.line.length) { // meta-f - forward word
next_word = this.line.slice(this.cursor, this.line.length) } else if (b[1] === 102 && this.cursor < this.line.length) {
.search(/\w/); // meta-f - forward word
next_word = this.line.slice(this.cursor, this.line.length).search(/\w/);
if (next_word !== -1) { if (next_word !== -1) {
next_non_word = this.line.slice(this.cursor + next_word, this.line.length) next_non_word =
this.line.slice(this.cursor + next_word, this.line.length)
.search(/\W/); .search(/\W/);
if (next_non_word !== -1) { if (next_non_word !== -1) {
this.cursor += next_word + next_non_word; this.cursor += next_word + next_non_word;
@ -394,14 +398,17 @@ 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) } else if (b[1] === 100 && this.cursor < this.line.length) {
.search(/\w/); // meta-d delete forward word
next_word = this.line.slice(this.cursor, this.line.length).search(/\w/);
if (next_word !== -1) { if (next_word !== -1) {
next_non_word = this.line.slice(this.cursor + next_word, this.line.length) next_non_word =
this.line.slice(this.cursor + next_word, this.line.length)
.search(/\W/); .search(/\W/);
if (next_non_word !== -1) { if (next_non_word !== -1) {
this.line = this.line.slice(this.cursor + next_word + next_non_word); this.line =
this.line.slice(this.cursor + next_word + next_non_word);
this.cursor = 0; this.cursor = 0;
this._refreshLine(); this._refreshLine();
break; break;
@ -410,36 +417,50 @@ Interface.prototype._ttyWrite = function (b) {
this.line = ''; this.line = '';
this.cursor = 0; this.cursor = 0;
this._refreshLine(); 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--;
this.output.write('\x1b[0D'); this.output.write('\x1b[0D');
} }
} else if (b[1] === 91 && b[2] === 67) { // right arrow
} else if (b[1] === 91 && b[2] === 67) {
// right arrow
if (this.cursor != this.line.length) { if (this.cursor != this.line.length) {
this.cursor++; this.cursor++;
this.output.write('\x1b[0C'); this.output.write('\x1b[0C');
} }
} else if ((b[1] === 91 && b[2] === 72) || } else if ((b[1] === 91 && b[2] === 72) ||
(b[1] === 79 && b[2] === 72) || (b[1] === 79 && b[2] === 72) ||
(b[1] === 91 && b[2] === 55) || (b[1] === 91 && b[2] === 55) ||
(b[1] === 91 && b[2] === 49 && (b[3] && b[3] === 126))) { // home (b[1] === 91 && b[2] === 49 && (b[3] && b[3] === 126))) {
// home
this.cursor = 0; this.cursor = 0;
this._refreshLine(); this._refreshLine();
} else if ((b[1] === 91 && b[2] === 70) || } else if ((b[1] === 91 && b[2] === 70) ||
(b[1] === 79 && b[2] === 70) || (b[1] === 79 && b[2] === 70) ||
(b[1] === 91 && b[2] === 56) || (b[1] === 91 && b[2] === 56) ||
(b[1] === 91 && b[2] === 52 && (b[3] && b[3] === 126))) { // end (b[1] === 91 && b[2] === 52 && (b[3] && b[3] === 126))) {
// 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
this._historyPrev(); this._historyPrev();
} else if (b[1] === 91 && b[2] === 66) { // down arrow
} else if (b[1] === 91 && b[2] === 66) {
// down arrow
this._historyNext(); this._historyNext();
} else if (b[1] === 91 && b[2] === 51 && this.cursor < this.line.length) { // delete right
} else if (b[1] === 91 && b[2] === 51 && this.cursor < this.line.length) {
// delete right
this.line = this.line.slice(0, this.cursor) + this.line = this.line.slice(0, this.cursor) +
this.line.slice(this.cursor+1, this.line.length); this.line.slice(this.cursor+1, this.line.length);
this._refreshLine(); this._refreshLine();
} }
break; break;

Loading…
Cancel
Save