Skip to content

Commit 71df563

Browse files
authored
fix: calculate box width with the title width (#362)
1 parent 7b82f84 commit 71df563

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

examples/box.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ function main() {
88
`${colors.red("I")} ${colors.yellowBright("am")} ${colors.yellow("the")} ${colors.green("rainbow")} ${colors.blue("banner")}`,
99
);
1010

11+
consola.box({
12+
title: "longer title",
13+
message: "short msg",
14+
});
15+
1116
consola.box({
1217
title: "Box with options",
1318
message: `I am a banner with different options`,

src/utils/box.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,10 @@ export function box(text: string, _opts: BoxOpts = {}) {
256256
opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1;
257257
const height = textLines.length + paddingOffset;
258258
const width =
259-
Math.max(...textLines.map((line) => stripAnsi(line).length)) +
260-
paddingOffset;
259+
Math.max(
260+
...textLines.map((line) => stripAnsi(line).length),
261+
opts.title ? stripAnsi(opts.title).length : 0,
262+
) + paddingOffset;
261263
const widthOffset = width + paddingOffset;
262264

263265
const leftSpace =

0 commit comments

Comments
 (0)