|
@ -7,15 +7,12 @@ |
|
|
const ansi = |
|
|
const ansi = |
|
|
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; |
|
|
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; |
|
|
|
|
|
|
|
|
|
|
|
var getStringWidth; |
|
|
module.exports = { |
|
|
var isFullWidthCodePoint; |
|
|
emitKeys, |
|
|
|
|
|
stripVTControlCharacters |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if (process.binding('config').hasIntl) { |
|
|
if (process.binding('config').hasIntl) { |
|
|
const icu = process.binding('icu'); |
|
|
const icu = process.binding('icu'); |
|
|
module.exports.getStringWidth = function getStringWidth(str, options) { |
|
|
getStringWidth = function getStringWidth(str, options) { |
|
|
options = options || {}; |
|
|
options = options || {}; |
|
|
if (!Number.isInteger(str)) |
|
|
if (!Number.isInteger(str)) |
|
|
str = stripVTControlCharacters(String(str)); |
|
|
str = stripVTControlCharacters(String(str)); |
|
@ -23,7 +20,7 @@ if (process.binding('config').hasIntl) { |
|
|
Boolean(options.ambiguousAsFullWidth), |
|
|
Boolean(options.ambiguousAsFullWidth), |
|
|
Boolean(options.expandEmojiSequence)); |
|
|
Boolean(options.expandEmojiSequence)); |
|
|
}; |
|
|
}; |
|
|
module.exports.isFullWidthCodePoint = |
|
|
isFullWidthCodePoint = |
|
|
function isFullWidthCodePoint(code, options) { |
|
|
function isFullWidthCodePoint(code, options) { |
|
|
if (typeof code !== 'number') |
|
|
if (typeof code !== 'number') |
|
|
return false; |
|
|
return false; |
|
@ -33,9 +30,9 @@ if (process.binding('config').hasIntl) { |
|
|
/** |
|
|
/** |
|
|
* Returns the number of columns required to display the given string. |
|
|
* Returns the number of columns required to display the given string. |
|
|
*/ |
|
|
*/ |
|
|
module.exports.getStringWidth = function getStringWidth(str) { |
|
|
getStringWidth = function getStringWidth(str) { |
|
|
if (Number.isInteger(str)) |
|
|
if (Number.isInteger(str)) |
|
|
return module.exports.isFullWidthCodePoint(str) ? 2 : 1; |
|
|
return isFullWidthCodePoint(str) ? 2 : 1; |
|
|
|
|
|
|
|
|
let width = 0; |
|
|
let width = 0; |
|
|
|
|
|
|
|
@ -48,7 +45,7 @@ if (process.binding('config').hasIntl) { |
|
|
i++; |
|
|
i++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (module.exports.isFullWidthCodePoint(code)) { |
|
|
if (isFullWidthCodePoint(code)) { |
|
|
width += 2; |
|
|
width += 2; |
|
|
} else { |
|
|
} else { |
|
|
width++; |
|
|
width++; |
|
@ -62,7 +59,7 @@ if (process.binding('config').hasIntl) { |
|
|
* Returns true if the character represented by a given |
|
|
* Returns true if the character represented by a given |
|
|
* Unicode code point is full-width. Otherwise returns false. |
|
|
* Unicode code point is full-width. Otherwise returns false. |
|
|
*/ |
|
|
*/ |
|
|
module.exports.isFullWidthCodePoint = function isFullWidthCodePoint(code) { |
|
|
isFullWidthCodePoint = function isFullWidthCodePoint(code) { |
|
|
if (!Number.isInteger(code)) { |
|
|
if (!Number.isInteger(code)) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
@ -407,3 +404,10 @@ function* emitKeys(stream) { |
|
|
/* Unrecognized or broken escape sequence, don't emit anything */ |
|
|
/* Unrecognized or broken escape sequence, don't emit anything */ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
|
|
|
emitKeys, |
|
|
|
|
|
getStringWidth, |
|
|
|
|
|
isFullWidthCodePoint, |
|
|
|
|
|
stripVTControlCharacters |
|
|
|
|
|
}; |
|
|