mirror of
https://github.com/unjs/consola.git
synced 2025-12-05 18:47:19 -06:00
fix: calculate box width with the title width (#362)
This commit is contained in:
@@ -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`,
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user