Comparing version 0.1.1 to 1.0.0
93
index.js
@@ -9,9 +9,5 @@ /** | ||
var MuteStream = require("mute-stream"); | ||
var stripAnsi = require("strip-ansi"); | ||
var codePointAt = require("code-point-at"); | ||
var isFullwidthCodePoint = require("is-fullwidth-code-point"); | ||
/** | ||
* Module export | ||
*/ | ||
var Interface = module.exports = {}; | ||
@@ -64,3 +60,3 @@ | ||
this.cursor < this.line.length && | ||
isFullWidthCodePoint(codePointAt(this.line, this.cursor))) { | ||
isFullwidthCodePoint(codePointAt(this.line, this.cursor))) { | ||
rows++; | ||
@@ -76,4 +72,5 @@ cols = 0; | ||
var col = this.columns; | ||
var row = 0; | ||
var code; | ||
str = stripAnsi(str); | ||
str = stripVTControlCharacters(str); | ||
for (var i = 0, len = str.length; i < len; i++) { | ||
@@ -84,3 +81,8 @@ code = codePointAt(str, i); | ||
} | ||
if (isFullWidthCodePoint(code)) { | ||
if (code === 0x0a) { // new line \n | ||
offset = 0; | ||
row += 1; | ||
continue; | ||
} | ||
if (isFullwidthCodePoint(code)) { | ||
if ((offset + 1) % col === 0) { | ||
@@ -95,3 +97,3 @@ offset++; | ||
var cols = offset % col; | ||
var rows = (offset - cols) / col; | ||
var rows = row + (offset - cols) / col; | ||
return {cols: cols, rows: rows}; | ||
@@ -114,64 +116,17 @@ }; | ||
/** | ||
* 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). | ||
*/ | ||
// Regexes used for ansi escape code splitting | ||
var metaKeyCodeReAnywhere = /(?:\x1b)([a-zA-Z0-9])/; | ||
var functionKeyCodeReAnywhere = new RegExp('(?:\x1b+)(O|N|\\[|\\[\\[)(?:' + [ | ||
'(\\d+)(?:;(\\d+))?([~^$])', | ||
'(?:M([@ #!a`])(.)(.))', // mouse | ||
'(?:1;)?(\\d+)?([a-zA-Z])' | ||
].join('|') + ')'); | ||
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; | ||
} | ||
/** | ||
* Returns true if the character represented by a given | ||
* Unicode code point is full-width. Otherwise returns false. | ||
* Tries to remove all VT control characters. Use to estimate displayed | ||
* string width. May be buggy due to not running a real state machine | ||
*/ | ||
function isFullWidthCodePoint(code) { | ||
if (isNaN(code)) { | ||
return false; | ||
} | ||
// Code points are derived from: | ||
// http://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt | ||
if (code >= 0x1100 && ( | ||
code <= 0x115f || // Hangul Jamo | ||
0x2329 === code || // LEFT-POINTING ANGLE BRACKET | ||
0x232a === code || // RIGHT-POINTING ANGLE BRACKET | ||
// CJK Radicals Supplement .. Enclosed CJK Letters and Months | ||
(0x2e80 <= code && code <= 0x3247 && code !== 0x303f) || | ||
// Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A | ||
0x3250 <= code && code <= 0x4dbf || | ||
// CJK Unified Ideographs .. Yi Radicals | ||
0x4e00 <= code && code <= 0xa4c6 || | ||
// Hangul Jamo Extended-A | ||
0xa960 <= code && code <= 0xa97c || | ||
// Hangul Syllables | ||
0xac00 <= code && code <= 0xd7a3 || | ||
// CJK Compatibility Ideographs | ||
0xf900 <= code && code <= 0xfaff || | ||
// Vertical Forms | ||
0xfe10 <= code && code <= 0xfe19 || | ||
// CJK Compatibility Forms .. Small Form Variants | ||
0xfe30 <= code && code <= 0xfe6b || | ||
// Halfwidth and Fullwidth Forms | ||
0xff01 <= code && code <= 0xff60 || | ||
0xffe0 <= code && code <= 0xffe6 || | ||
// Kana Supplement | ||
0x1b000 <= code && code <= 0x1b001 || | ||
// Enclosed Ideographic Supplement | ||
0x1f200 <= code && code <= 0x1f251 || | ||
// CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane | ||
0x20000 <= code && code <= 0x3fffd)) { | ||
return true; | ||
} | ||
return false; | ||
function stripVTControlCharacters (str) { | ||
str = str.replace(new RegExp(functionKeyCodeReAnywhere.source, 'g'), ''); | ||
return str.replace(new RegExp(metaKeyCodeReAnywhere.source, 'g'), ''); | ||
} |
{ | ||
"name": "readline2", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "Readline Façade fixing bugs and issues found in releases 0.8 and 0.10", | ||
@@ -22,4 +22,5 @@ "scripts": { | ||
"dependencies": { | ||
"mute-stream": "0.0.4", | ||
"strip-ansi": "^2.0.1" | ||
"code-point-at": "^1.0.0", | ||
"is-fullwidth-code-point": "^1.0.0", | ||
"mute-stream": "^0.0.4" | ||
}, | ||
@@ -26,0 +27,0 @@ "devDependencies": { |
@@ -6,3 +6,3 @@ readline2 [![Build Status](https://travis-ci.org/SBoudrias/readline2.png?branch=master)](https://travis-ci.org/SBoudrias/readline2) | ||
This module include fixes seen in later version (0.11) and ease some undesirable behavior one could see using the readline to create interatives prompts. This means `readline2` change some behaviors and as so is **not** meant to be a drop-in replacement. | ||
This module include fixes seen in later version (0.11-0.12 and iojs) and ease some undesirable behavior one could see using the readline to create interatives prompts. This means `readline2` change some behaviors and as so is **not** meant to be an exact drop-in replacement. | ||
@@ -17,3 +17,3 @@ This project is extracted from the core of [Inquirer.js interactive prompt interface](https://github.com/SBoudrias/Inquirer.js) to be available as a standalone module. | ||
### readline2.createInterface( options ); -> {Interface} | ||
### readline2.createInterface(options); -> {Interface} | ||
@@ -28,2 +28,3 @@ Present the same API as [Node.js `readline.createInterface()`](http://nodejs.org/api/readline.html) | ||
- Fix cursor position after a line refresh when the `Interface` prompt contains ANSI colors | ||
- Correctly return the cursor position when faced with implicit line returns | ||
@@ -30,0 +31,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
34
5788
3
107
+ Addedcode-point-at@^1.0.0
+ Addedcode-point-at@1.1.0(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
- Removedstrip-ansi@^2.0.1
- Removedansi-regex@1.1.1(transitive)
- Removedstrip-ansi@2.0.1(transitive)
Updatedmute-stream@^0.0.4