prompts
prompts copied to clipboard
Support Unicode characters
When input unicode characters,the number of input line is not correct. see screenshot below for more details.

Please use [email protected]
to strip characters instead of the simple strip function in the source code below to compute the width of characters
The path of source code below is lib/util/strip.js
'use strict';
module.exports = str => {
const pattern = [
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))'
].join('|');
const RGX = new RegExp(pattern, 'g');
return typeof str === 'string' ? str.replace(RGX, '') : str;
};
The changes maybe like this
The path of source code below is lib/util/clear.js
'use strict';
//const strip = require('./strip');
const { erase, cursor } = require('sisteransi');
const stringWidth = require('string-width');
//const width = str => [...strip(str)].length;
/**
* @param {string} prompt
* @param {number} perLine
*/
module.exports = function(prompt, perLine) {
if (!perLine) return erase.line + cursor.to(0);
let rows = 0;
const lines = prompt.split(/\r?\n/);
for (let line of lines) {
rows += 1 + Math.floor(Math.max(stringWidth(line) - 1, 0) / perLine);
}
return erase.lines(rows);
};