Skip to content

Commit

Permalink
readline: remove deprecated methods
Browse files Browse the repository at this point in the history
This commit removes the deprecated exports getStringWidth(),
stripVTControlCharacters(), and isFullWidthCodePoint(). It also
removes codePointAt() in its entirety, as it was deprecated and
not being used by core.

Refs: #3862
PR-URL: #6423
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Π‘ΠΊΠΎΠ²ΠΎΡ€ΠΎΠ΄Π° Никита АндрССвич <chalkerx@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
cjihrig committed May 2, 2016
1 parent 628ae25 commit 8a87b29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 65 deletions.
36 changes: 0 additions & 36 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const kHistorySize = 30;

const util = require('util');
const debug = util.debuglog('readline');
const internalUtil = require('internal/util');
const inherits = util.inherits;
const Buffer = require('buffer').Buffer;
const EventEmitter = require('events');
Expand Down Expand Up @@ -1042,38 +1041,3 @@ function clearScreenDown(stream) {
stream.write('\x1b[0J');
}
exports.clearScreenDown = clearScreenDown;


/**
* Returns the Unicode code point for the character at the
* given index in the given string. Similar to String.charCodeAt(),
* but this function handles surrogates (code point >= 0x10000).
*/

function codePointAt(str, index) {
var code = str.charCodeAt(index);
var low;
if (0xd800 <= code && code <= 0xdbff) { // High surrogate
low = str.charCodeAt(index + 1);
if (!isNaN(low)) {
code = 0x10000 + (code - 0xd800) * 0x400 + (low - 0xdc00);
}
}
return code;
}
exports.codePointAt = internalUtil.deprecate(codePointAt,
'readline.codePointAt is deprecated. ' +
'Use String.prototype.codePointAt instead.');


exports.getStringWidth = internalUtil.deprecate(getStringWidth,
'getStringWidth is deprecated and will be removed.');


exports.isFullWidthCodePoint = internalUtil.deprecate(isFullWidthCodePoint,
'isFullWidthCodePoint is deprecated and will be removed.');


exports.stripVTControlCharacters = internalUtil.deprecate(
stripVTControlCharacters,
'stripVTControlCharacters is deprecated and will be removed.');
54 changes: 25 additions & 29 deletions test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Flags: --expose_internals
'use strict';
require('../common');
var assert = require('assert');
var readline = require('readline');
var EventEmitter = require('events').EventEmitter;
var inherits = require('util').inherits;
const assert = require('assert');
const readline = require('readline');
const internalReadline = require('internal/readline');
const EventEmitter = require('events').EventEmitter;
const inherits = require('util').inherits;

function FakeInput() {
EventEmitter.call(this);
Expand Down Expand Up @@ -322,37 +324,31 @@ function isWarned(emitter) {
}

// wide characters should be treated as two columns.
assert.equal(readline.isFullWidthCodePoint('a'.charCodeAt(0)), false);
assert.equal(readline.isFullWidthCodePoint('あ'.charCodeAt(0)), true);
assert.equal(readline.isFullWidthCodePoint('θ°’'.charCodeAt(0)), true);
assert.equal(readline.isFullWidthCodePoint('κ³ '.charCodeAt(0)), true);
assert.equal(readline.isFullWidthCodePoint(0x1f251), true); // surrogate
assert.equal(readline.codePointAt('ABC', 0), 0x41);
assert.equal(readline.codePointAt('あいう', 1), 0x3044);
assert.equal(readline.codePointAt('\ud800\udc00', 0), // surrogate
0x10000);
assert.equal(readline.codePointAt('\ud800\udc00A', 2), // surrogate
0x41);
assert.equal(readline.getStringWidth('abcde'), 5);
assert.equal(readline.getStringWidth('叀池や'), 6);
assert.equal(readline.getStringWidth('γƒŽγƒΌγƒ‰.js'), 9);
assert.equal(readline.getStringWidth('δ½ ε₯½'), 4);
assert.equal(readline.getStringWidth('μ•ˆλ…•ν•˜μ„Έμš”'), 10);
assert.equal(readline.getStringWidth('A\ud83c\ude00BC'), 5); // surrogate
assert.equal(internalReadline.isFullWidthCodePoint('a'.charCodeAt(0)), false);
assert.equal(internalReadline.isFullWidthCodePoint('あ'.charCodeAt(0)), true);
assert.equal(internalReadline.isFullWidthCodePoint('θ°’'.charCodeAt(0)), true);
assert.equal(internalReadline.isFullWidthCodePoint('κ³ '.charCodeAt(0)), true);
assert.equal(internalReadline.isFullWidthCodePoint(0x1f251), true);
assert.equal(internalReadline.getStringWidth('abcde'), 5);
assert.equal(internalReadline.getStringWidth('叀池や'), 6);
assert.equal(internalReadline.getStringWidth('γƒŽγƒΌγƒ‰.js'), 9);
assert.equal(internalReadline.getStringWidth('δ½ ε₯½'), 4);
assert.equal(internalReadline.getStringWidth('μ•ˆλ…•ν•˜μ„Έμš”'), 10);
assert.equal(internalReadline.getStringWidth('A\ud83c\ude00BC'), 5);

// check if vt control chars are stripped
assert.equal(readline
assert.equal(internalReadline
.stripVTControlCharacters('\u001b[31m> \u001b[39m'), '> ');
assert.equal(readline
assert.equal(internalReadline
.stripVTControlCharacters('\u001b[31m> \u001b[39m> '), '> > ');
assert.equal(readline
assert.equal(internalReadline
.stripVTControlCharacters('\u001b[31m\u001b[39m'), '');
assert.equal(readline
assert.equal(internalReadline
.stripVTControlCharacters('> '), '> ');
assert.equal(readline.getStringWidth('\u001b[31m> \u001b[39m'), 2);
assert.equal(readline.getStringWidth('\u001b[31m> \u001b[39m> '), 4);
assert.equal(readline.getStringWidth('\u001b[31m\u001b[39m'), 0);
assert.equal(readline.getStringWidth('> '), 2);
assert.equal(internalReadline.getStringWidth('\u001b[31m> \u001b[39m'), 2);
assert.equal(internalReadline.getStringWidth('\u001b[31m> \u001b[39m> '), 4);
assert.equal(internalReadline.getStringWidth('\u001b[31m\u001b[39m'), 0);
assert.equal(internalReadline.getStringWidth('> '), 2);

assert.deepStrictEqual(fi.listeners(terminal ? 'keypress' : 'data'), []);

Expand Down

0 comments on commit 8a87b29

Please sign in to comment.