Skip to content

Commit

Permalink
fix: port breakLines to wrap-ansi
Browse files Browse the repository at this point in the history
This PR addresses incorrect line wrapping with `terminal-link`. It does so by employing the `wrap-ansi` npm.

Fixes #1014
Fixes #304
  • Loading branch information
starpit committed Apr 24, 2022
1 parent aad7190 commit 8640d55
Show file tree
Hide file tree
Showing 3 changed files with 6,884 additions and 6,710 deletions.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -45,5 +45,7 @@
"coverageDirectory": "./coverage/",
"collectCoverage": true
},
"dependencies": {}
"dependencies": {
"wrap-ansi": "^7.0.0"
}
}
9 changes: 2 additions & 7 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 @@ -156,13 +157,7 @@ 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 || '';
});
return lines.map((line) => wrapAnsi(line, width));
}

/**
Expand Down

0 comments on commit 8640d55

Please sign in to comment.