From 892e4f0763fac52587e8bbda1e0c87efb678514b Mon Sep 17 00:00:00 2001 From: Inesh Bose <56732164+ineshbose@users.noreply.github.com> Date: Thu, 29 Jun 2023 13:03:12 +0100 Subject: [PATCH] feat(fancy): formatting syntax --- README.md | 3 +++ examples/special.ts | 4 ++++ src/reporters/fancy.ts | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 2045b4f2..e2dd7f94 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,9 @@ consola.box("I am a simple box"); await consola.prompt("Deploy to the production?", { type: "confirm", }); + +// formatting with colorette +consola.log("Text as `monospace` and _underline_ or `(underline,cyan)both`!") ``` Will display in the terminal: diff --git a/examples/special.ts b/examples/special.ts index 3325c77b..d4f69270 100755 --- a/examples/special.ts +++ b/examples/special.ts @@ -22,6 +22,10 @@ consola.log( "We can also _underline_ words but not_this or this should_not_be_underlined!" ); +consola.log("We can also do `(bgGreen)special` highlight"); + +consola.log("How about `(yellow,underline)chaining` them?"); + // Nonstandard error const { message, stack } = new Error("Custom Error!"); consola.error({ message, stack }); diff --git a/src/reporters/fancy.ts b/src/reporters/fancy.ts index 9a60642c..34cf1179 100644 --- a/src/reporters/fancy.ts +++ b/src/reporters/fancy.ts @@ -135,6 +135,10 @@ export class FancyReporter extends BasicReporter { function characterFormat(str: string) { return ( str + .replace(/`\(([^)]*)\)([^`]+)`/gm, (_, f, m) => + // eslint-disable-next-line unicorn/no-array-reduce + f.split(',').reduce((p: string, c: string) => getColor(c)(p), m) + ) // highlight backticks .replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)) // underline underscores