Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: port breakLines to wrap-ansi #1106

Merged
merged 4 commits into from Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -45,5 +45,7 @@
"coverageDirectory": "./coverage/",
"collectCoverage": true
},
"dependencies": {}
SBoudrias marked this conversation as resolved.
Show resolved Hide resolved
"dependencies": {
"wrap-ansi": "^7.0.0"
}
}
12 changes: 4 additions & 8 deletions packages/inquirer/lib/utils/screen-manager.js
@@ -1,6 +1,7 @@
'use strict';
const util = require('./readline');
const cliWidth = require('cli-width');
const wrapAnsi = require('wrap-ansi');
const stripAnsi = require('strip-ansi');
const stringWidth = require('string-width');
const ora = require('ora');
Expand Down Expand Up @@ -155,14 +156,9 @@ class ScreenManager {
*/
breakLines(lines, width = this.normalizedCliWidth()) {
// Break lines who're longer than the cli width so we can normalize the natural line
// returns behavior across terminals.
const regex = new RegExp(`(?:(?:\\033[[0-9;]*m)*.?){1,${width}}`, 'g');
return lines.map((line) => {
const chunk = line.match(regex);
// Last match is always empty
chunk.pop();
return chunk || '';
});
// returns behavior across terminals. By default, `wrapAnsi` trims whitespace, which
// is not what we want.
return lines.map((line) => wrapAnsi(line, width, { trim: false }));
}

/**
Expand Down