diff --git a/examples/box.ts b/examples/box.ts index 68c602c7..bd75c059 100644 --- a/examples/box.ts +++ b/examples/box.ts @@ -8,6 +8,11 @@ function main() { `${colors.red("I")} ${colors.yellowBright("am")} ${colors.yellow("the")} ${colors.green("rainbow")} ${colors.blue("banner")}`, ); + consola.box({ + title: "longer title", + message: "short msg", + }); + consola.box({ title: "Box with options", message: `I am a banner with different options`, diff --git a/src/utils/box.ts b/src/utils/box.ts index dba957ff..e400a15a 100644 --- a/src/utils/box.ts +++ b/src/utils/box.ts @@ -256,8 +256,10 @@ export function box(text: string, _opts: BoxOpts = {}) { opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1; const height = textLines.length + paddingOffset; const width = - Math.max(...textLines.map((line) => stripAnsi(line).length)) + - paddingOffset; + Math.max( + ...textLines.map((line) => stripAnsi(line).length), + opts.title ? stripAnsi(opts.title).length : 0, + ) + paddingOffset; const widthOffset = width + paddingOffset; const leftSpace =