diff options
author | James M Snell <jasnell@gmail.com> | 2017-04-29 17:05:04 -0700 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-05-07 22:54:26 +0200 |
commit | 4c070d489718b196d7950998ccfb54bcc50d9711 (patch) | |
tree | 4ae3ae06ef77340f821f180472d55e3bcad929be /lib/readline.js | |
parent | 4ac7a68ccd6fb0104f171ef49e964fb6d4a170c6 (diff) | |
download | android-node-v8-4c070d489718b196d7950998ccfb54bcc50d9711.tar.gz android-node-v8-4c070d489718b196d7950998ccfb54bcc50d9711.tar.bz2 android-node-v8-4c070d489718b196d7950998ccfb54bcc50d9711.zip |
readline: move escape codes into internal/readline
Moves escape codes into internal/readline for easier management.
PR-URL: https://github.com/nodejs/node/pull/12755
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib/readline.js')
-rw-r--r-- | lib/readline.js | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/readline.js b/lib/readline.js index f46fc0d59c..60864f40af 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -31,12 +31,21 @@ const { debug, inherits } = require('util'); const Buffer = require('buffer').Buffer; const EventEmitter = require('events'); const { + CSI, emitKeys, getStringWidth, isFullWidthCodePoint, stripVTControlCharacters } = require('internal/readline'); +const { + kEscape, + kClearToBeginning, + kClearToEnd, + kClearLine, + kClearScreenDown +} = CSI; + const kHistorySize = 30; const kMincrlfDelay = 100; const kMaxcrlfDelay = 2000; @@ -995,7 +1004,7 @@ function emitKeypressEvents(stream, iface) { try { stream[ESCAPE_DECODER].next(r[i]); // Escape letter at the tail position - if (r[i] === '\x1b' && i + 1 === r.length) { + if (r[i] === kEscape && i + 1 === r.length) { timeoutId = setTimeout(escapeCodeTimeout, ESCAPE_CODE_TIMEOUT); } } catch (err) { @@ -1047,9 +1056,9 @@ function cursorTo(stream, x, y) { throw new Error('Can\'t set cursor row without also setting it\'s column'); if (typeof y !== 'number') { - stream.write('\x1b[' + (x + 1) + 'G'); + stream.write(CSI`${x + 1}G`); } else { - stream.write('\x1b[' + (y + 1) + ';' + (x + 1) + 'H'); + stream.write(CSI`${y + 1};${x + 1}H`); } } @@ -1062,15 +1071,15 @@ function moveCursor(stream, dx, dy) { return; if (dx < 0) { - stream.write('\x1b[' + (-dx) + 'D'); + stream.write(CSI`${-dx}D`); } else if (dx > 0) { - stream.write('\x1b[' + dx + 'C'); + stream.write(CSI`${dx}C`); } if (dy < 0) { - stream.write('\x1b[' + (-dy) + 'A'); + stream.write(CSI`${-dy}A`); } else if (dy > 0) { - stream.write('\x1b[' + dy + 'B'); + stream.write(CSI`${dy}B`); } } @@ -1087,13 +1096,13 @@ function clearLine(stream, dir) { if (dir < 0) { // to the beginning - stream.write('\x1b[1K'); + stream.write(kClearToBeginning); } else if (dir > 0) { // to the end - stream.write('\x1b[0K'); + stream.write(kClearToEnd); } else { // entire line - stream.write('\x1b[2K'); + stream.write(kClearLine); } } @@ -1105,7 +1114,7 @@ function clearScreenDown(stream) { if (stream === null || stream === undefined) return; - stream.write('\x1b[0J'); + stream.write(kClearScreenDown); } module.exports = { |