Skip to content

Commit

Permalink
Fix crashes when wrapping text containing colorized content (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist authored Apr 6, 2021
1 parent de1f3c8 commit ab25c46
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module.exports = (text, options) => {
const createdLines = wrapAnsi(line, max, {hard: true});
const alignedLines = ansiAlign(createdLines, {align: options.align});
const alignedLinesArray = alignedLines.split('\n');
const longestLength = Math.max(...alignedLinesArray.map(s => s.length));
const longestLength = Math.max(...alignedLinesArray.map(s => stringWidth(s)));

for (const alignedLine of alignedLinesArray) {
let paddedLine;
Expand Down
28 changes: 28 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,34 @@ test('align option `left`', t => {
`);
});

test('align option (left) does not throw when colorized content > columns', t => {
console.log('process.stdout.columns', process.stdout.columns);
const longContent = chalk.green('ab').repeat(process.stdout.columns);
t.notThrows(() => {
boxen(longContent, {
align: 'left'
});
});
});

test('align option (center) does not throw when colorized content > columns', t => {
const longContent = chalk.green('ab').repeat(process.stdout.columns);
t.notThrows(() => {
boxen(longContent, {
align: 'center'
});
});
});

test('align option (right) does not throw when colorized content > columns', t => {
const longContent = chalk.green('ab').repeat(process.stdout.columns);
t.notThrows(() => {
boxen(longContent, {
align: 'right'
});
});
});

test('dimBorder option', t => {
const dimTopBorder = chalk.dim('┌───┐');
const dimSide = chalk.dim('│');
Expand Down

0 comments on commit ab25c46

Please sign in to comment.