@@ -73,11 +73,13 @@ export const box = (message = '', title = '', opts?: BoxOptions) => {
7373 const symbols = ( opts ?. rounded ? roundedSymbols : squareSymbols ) . map ( formatBorder ) ;
7474 const hSymbol = formatBorder ( S_BAR_H ) ;
7575 const vSymbol = formatBorder ( S_BAR ) ;
76- const maxBoxWidth = columns - stringWidth ( linePrefix ) ;
77- let boxWidth = Math . floor ( columns * width ) - stringWidth ( linePrefix ) ;
76+ const linePrefixWidth = stringWidth ( linePrefix ) ;
77+ const titleWidth = stringWidth ( title ) ;
78+ const maxBoxWidth = columns - linePrefixWidth ;
79+ let boxWidth = Math . floor ( columns * width ) - linePrefixWidth ;
7880 if ( opts ?. width === 'auto' ) {
7981 const lines = message . split ( '\n' ) ;
80- let longestLine = stringWidth ( title ) + titlePadding * 2 ;
82+ let longestLine = titleWidth + titlePadding * 2 ;
8183 for ( const line of lines ) {
8284 const lineWithPadding = stringWidth ( line ) + contentPadding * 2 ;
8385 if ( lineWithPadding > longestLine ) {
@@ -99,7 +101,7 @@ export const box = (message = '', title = '', opts?: BoxOptions) => {
99101 const innerWidth = boxWidth - borderTotalWidth ;
100102 const maxTitleLength = innerWidth - titlePadding * 2 ;
101103 const truncatedTitle =
102- stringWidth ( title ) > maxTitleLength ? `${ title . slice ( 0 , maxTitleLength - 3 ) } ...` : title ;
104+ titleWidth > maxTitleLength ? `${ title . slice ( 0 , maxTitleLength - 3 ) } ...` : title ;
103105 const [ titlePaddingLeft , titlePaddingRight ] = getPaddingForLine (
104106 stringWidth ( truncatedTitle ) ,
105107 innerWidth ,
0 commit comments