Skip to content

Commit

Permalink
refactor(fancy): more minimal badges when width cannot be determined
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 11, 2023
1 parent ab59db6 commit ad24029
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions examples/no-width.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createConsola } from "../src";

function main() {
const consola = createConsola({
formatOptions: { columns: 0 },
});
consola.info("Foobar");
const scoped = consola.withTag("test");
scoped.success("Foobar");
}

main();
4 changes: 2 additions & 2 deletions src/reporters/fancy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ export default class FancyReporter extends BasicReporter {

let line;
const left = this.filterAndJoin([type, highlightBackticks(message)]);
const right = this.filterAndJoin([tag, coloredDate]);
const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
const space =
(opts.columns || 0) - stringWidth(left) - stringWidth(right) - 2;

line =
space > 0 && (opts.columns || 0) >= 80
? left + " ".repeat(space) + right
: `[ ${right} ] ${left}`;
: (right ? `${colors.gray(`[${right}]`)} ` : "") + left;

line += highlightBackticks(
additional.length > 0 ? "\n" + additional.join("\n") : ""
Expand Down

0 comments on commit ad24029

Please sign in to comment.