Browse Source

Fix style in readline

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

127
lib/readline.js

@ -364,82 +364,103 @@ 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
previous_word = this.line.slice(0, this.cursor) if (b[1] === 98 && this.cursor > 0) {
.split('').reverse().join('') // meta-b - backward word
.search(/\w/); previous_word = this.line.slice(0, this.cursor)
if (previous_word !== -1) { .split('').reverse().join('')
previous_non_word = this.line.slice(0, this.cursor - previous_word) .search(/\w/);
.split('').reverse().join('') if (previous_word !== -1) {
.search(/\W/); previous_non_word = this.line.slice(0, this.cursor - previous_word)
if (previous_non_word !== -1) { .split('').reverse().join('')
this.cursor -= previous_word + previous_non_word; .search(/\W/);
this._refreshLine(); if (previous_non_word !== -1) {
break; this.cursor -= previous_word + previous_non_word;
} this._refreshLine();
} break;
this.cursor = 0; }
this._refreshLine(); }
} else if (b[1] === 102 && this.cursor < this.line.length) { // meta-f - forward word this.cursor = 0;
next_word = this.line.slice(this.cursor, this.line.length) this._refreshLine();
.search(/\w/);
if (next_word !== -1) { } else if (b[1] === 102 && this.cursor < this.line.length) {
next_non_word = this.line.slice(this.cursor + next_word, this.line.length) // meta-f - forward word
.search(/\W/); next_word = this.line.slice(this.cursor, this.line.length).search(/\w/);
if (next_non_word !== -1) { if (next_word !== -1) {
this.cursor += next_word + next_non_word; next_non_word =
this._refreshLine(); this.line.slice(this.cursor + next_word, this.line.length)
break; .search(/\W/);
} if (next_non_word !== -1) {
} this.cursor += next_word + next_non_word;
this.cursor = this.line.length; this._refreshLine();
this._refreshLine(); break;
} 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/); this.cursor = this.line.length;
if (next_word !== -1) { this._refreshLine();
next_non_word = this.line.slice(this.cursor + next_word, this.line.length)
.search(/\W/); } else if (b[1] === 100 && this.cursor < this.line.length) {
if (next_non_word !== -1) { // meta-d delete forward word
this.line = this.line.slice(this.cursor + next_word + next_non_word); next_word = this.line.slice(this.cursor, this.line.length).search(/\w/);
this.cursor = 0; if (next_word !== -1) {
this._refreshLine(); next_non_word =
break; this.line.slice(this.cursor + next_word, this.line.length)
} .search(/\W/);
} if (next_non_word !== -1) {
this.line = ''; this.line =
this.cursor = 0; this.line.slice(this.cursor + next_word + next_non_word);
this._refreshLine(); this.cursor = 0;
} else if (b[1] === 91 && b[2] === 68) { // left arrow this._refreshLine();
break;
}
}
this.line = '';
this.cursor = 0;
this._refreshLine();
} 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