Fix style in readline
This commit is contained in:
parent
0ef8a86af2
commit
2d09ef8541
127
lib/readline.js
127
lib/readline.js
@ -364,82 +364,103 @@ Interface.prototype._ttyWrite = function (b) {
|
||||
|
||||
case 27: /* escape sequence */
|
||||
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)
|
||||
.split('').reverse().join('')
|
||||
.search(/\w/);
|
||||
if (previous_word !== -1) {
|
||||
previous_non_word = this.line.slice(0, this.cursor - previous_word)
|
||||
.split('').reverse().join('')
|
||||
.search(/\W/);
|
||||
if (previous_non_word !== -1) {
|
||||
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
|
||||
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.cursor += next_word + next_non_word;
|
||||
this._refreshLine();
|
||||
break;
|
||||
}
|
||||
}
|
||||
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 (b[1] === 98 && this.cursor > 0) {
|
||||
// meta-b - backward word
|
||||
previous_word = this.line.slice(0, this.cursor)
|
||||
.split('').reverse().join('')
|
||||
.search(/\w/);
|
||||
if (previous_word !== -1) {
|
||||
previous_non_word = this.line.slice(0, this.cursor - previous_word)
|
||||
.split('').reverse().join('')
|
||||
.search(/\W/);
|
||||
if (previous_non_word !== -1) {
|
||||
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
|
||||
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.cursor += next_word + next_non_word;
|
||||
this._refreshLine();
|
||||
break;
|
||||
}
|
||||
}
|
||||
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--;
|
||||
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) {
|
||||
this.cursor++;
|
||||
this.output.write('\x1b[0C');
|
||||
}
|
||||
|
||||
} else if ((b[1] === 91 && b[2] === 72) ||
|
||||
(b[1] === 79 && b[2] === 72) ||
|
||||
(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._refreshLine();
|
||||
} else if ((b[1] === 91 && b[2] === 70) ||
|
||||
(b[1] === 79 && b[2] === 70) ||
|
||||
(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._refreshLine();
|
||||
} else if (b[1] === 91 && b[2] === 65) { // up arrow
|
||||
|
||||
} else if (b[1] === 91 && b[2] === 65) {
|
||||
// up arrow
|
||||
this._historyPrev();
|
||||
} else if (b[1] === 91 && b[2] === 66) { // down arrow
|
||||
|
||||
} else if (b[1] === 91 && b[2] === 66) {
|
||||
// down arrow
|
||||
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.slice(this.cursor+1, this.line.length);
|
||||
this._refreshLine();
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user