Skip to content

Commit 4ac7a68

Browse files
jasnelladdaleax
authored andcommitted
readline: multiple code cleanups
Variety of code maintenance updates, cleanups PR-URL: #12755 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 392a898 commit 4ac7a68

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

lib/readline.js

+18-19
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,32 @@
2727

2828
'use strict';
2929

30+
const { debug, inherits } = require('util');
31+
const Buffer = require('buffer').Buffer;
32+
const EventEmitter = require('events');
33+
const {
34+
emitKeys,
35+
getStringWidth,
36+
isFullWidthCodePoint,
37+
stripVTControlCharacters
38+
} = require('internal/readline');
39+
3040
const kHistorySize = 30;
3141
const kMincrlfDelay = 100;
3242
const kMaxcrlfDelay = 2000;
43+
// \r\n, \n, or \r followed by something other than \n
44+
const lineEnding = /\r?\n|\r(?!\n)/;
3345

34-
const util = require('util');
35-
const debug = util.debuglog('readline');
36-
const inherits = util.inherits;
37-
const Buffer = require('buffer').Buffer;
38-
const EventEmitter = require('events');
39-
const internalReadline = require('internal/readline');
40-
const emitKeys = internalReadline.emitKeys;
41-
const getStringWidth = internalReadline.getStringWidth;
42-
const isFullWidthCodePoint = internalReadline.isFullWidthCodePoint;
43-
const stripVTControlCharacters = internalReadline.stripVTControlCharacters;
46+
const KEYPRESS_DECODER = Symbol('keypress-decoder');
47+
const ESCAPE_DECODER = Symbol('escape-decoder');
48+
49+
// GNU readline library - keyseq-timeout is 500ms (default)
50+
const ESCAPE_CODE_TIMEOUT = 500;
4451

4552

4653
function createInterface(input, output, completer, terminal) {
4754
return new Interface(input, output, completer, terminal);
48-
};
55+
}
4956

5057

5158
function Interface(input, output, completer, terminal) {
@@ -373,8 +380,6 @@ Interface.prototype.write = function(d, key) {
373380
this.terminal ? this._ttyWrite(d, key) : this._normalWrite(d);
374381
};
375382

376-
// \r\n, \n, or \r followed by something other than \n
377-
const lineEnding = /\r?\n|\r(?!\n)/;
378383
Interface.prototype._normalWrite = function(b) {
379384
if (b === undefined) {
380385
return;
@@ -961,12 +966,6 @@ Interface.prototype._ttyWrite = function(s, key) {
961966
* accepts a readable Stream instance and makes it emit "keypress" events
962967
*/
963968

964-
const KEYPRESS_DECODER = Symbol('keypress-decoder');
965-
const ESCAPE_DECODER = Symbol('escape-decoder');
966-
967-
// GNU readline library - keyseq-timeout is 500ms (default)
968-
const ESCAPE_CODE_TIMEOUT = 500;
969-
970969
function emitKeypressEvents(stream, iface) {
971970
if (stream[KEYPRESS_DECODER]) return;
972971
var StringDecoder = require('string_decoder').StringDecoder; // lazy load

0 commit comments

Comments
 (0)