diff --git a/index.js b/index.js index 4add910..f4737f6 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/test.js b/test.js index 02b98c2..1967983 100644 --- a/test.js +++ b/test.js @@ -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('│');