From 31cafb29170288ac123c254da579894e55391207 Mon Sep 17 00:00:00 2001 From: Inesh Bose <2504266b@student.gla.ac.uk> Date: Sun, 21 May 2023 13:49:15 +0100 Subject: [PATCH 1/5] feat: underlining --- examples/special.ts | 2 ++ src/reporters/fancy.ts | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/special.ts b/examples/special.ts index 5a37176..4c36cf7 100755 --- a/examples/special.ts +++ b/examples/special.ts @@ -18,6 +18,8 @@ consola.error(undefined, null, false, true, Number.NaN); consola.log("We can `monospace` keyword using grave accent charachter!"); +consola.log("We can also _underline_ words!") + // 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 c8eb64e..5d9cfe0 100644 --- a/src/reporters/fancy.ts +++ b/src/reporters/fancy.ts @@ -86,7 +86,7 @@ export class FancyReporter extends BasicReporter { const tag = logObj.tag ? colors.gray(logObj.tag) : ""; let line; - const left = this.filterAndJoin([type, highlightBackticks(message)]); + const left = this.filterAndJoin([type, characterFormat(message)]); const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]); const space = (opts.columns || 0) - stringWidth(left) - stringWidth(right) - 2; @@ -96,7 +96,7 @@ export class FancyReporter extends BasicReporter { ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left; - line += highlightBackticks( + line += characterFormat( additional.length > 0 ? "\n" + additional.join("\n") : "" ); @@ -109,8 +109,12 @@ export class FancyReporter extends BasicReporter { } } -function highlightBackticks(str: string) { - return str.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)); +function characterFormat(str: string) { + return str + // highlight backticks + .replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)) + // underline underscores + .replace(/_([^_]+)_/gm, (_, m) => colors.underline(m)); } function getColor(color = "white") { From 967025108fd97b1f863b62e51512bd0db1f1dec5 Mon Sep 17 00:00:00 2001 From: Inesh Bose <2504266b@student.gla.ac.uk> Date: Mon, 22 May 2023 14:01:34 +0100 Subject: [PATCH 2/5] feat: format syntax --- examples/special.ts | 6 +++++- src/reporters/fancy.ts | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/special.ts b/examples/special.ts index 4c36cf7..ecc5ed8 100755 --- a/examples/special.ts +++ b/examples/special.ts @@ -18,7 +18,11 @@ consola.error(undefined, null, false, true, Number.NaN); consola.log("We can `monospace` keyword using grave accent charachter!"); -consola.log("We can also _underline_ words!") +consola.log("We can also _underline_ words!"); + +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!"); diff --git a/src/reporters/fancy.ts b/src/reporters/fancy.ts index 5d9cfe0..2d4813a 100644 --- a/src/reporters/fancy.ts +++ b/src/reporters/fancy.ts @@ -111,6 +111,8 @@ export class FancyReporter extends BasicReporter { function characterFormat(str: string) { return str + // eslint-disable-next-line unicorn/no-array-reduce + .replace(/`\(([^)]*)\)([^`]+)`/gm, (_, f, m) => f.split(',').reduce((p: string, c: string) => getColor(c)(p), m)) // highlight backticks .replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)) // underline underscores From 75845480d8a768163cad192d38cd4c2c5126ec0e Mon Sep 17 00:00:00 2001 From: Inesh Bose <2504266b@student.gla.ac.uk> Date: Mon, 22 May 2023 14:04:56 +0100 Subject: [PATCH 3/5] docs: update readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7f05695..9f2ac01 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,9 @@ consola.error(new Error("This is an example error. Everything is fine!")); 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: From 0f6951738cc53d565c7c1db15a367ce671bad59a Mon Sep 17 00:00:00 2001 From: Inesh Bose <2504266b@student.gla.ac.uk> Date: Fri, 26 May 2023 13:29:13 +0100 Subject: [PATCH 4/5] fix: lint --- src/reporters/fancy.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/reporters/fancy.ts b/src/reporters/fancy.ts index 2d4813a..5a4ed09 100644 --- a/src/reporters/fancy.ts +++ b/src/reporters/fancy.ts @@ -110,13 +110,17 @@ export class FancyReporter extends BasicReporter { } function characterFormat(str: string) { - return str - // eslint-disable-next-line unicorn/no-array-reduce - .replace(/`\(([^)]*)\)([^`]+)`/gm, (_, f, m) => f.split(',').reduce((p: string, c: string) => getColor(c)(p), m)) - // highlight backticks - .replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)) - // underline underscores - .replace(/_([^_]+)_/gm, (_, m) => colors.underline(m)); + 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 + .replace(/_([^_]+)_/gm, (_, m) => colors.underline(m)) + ); } function getColor(color = "white") { From 67a525f50cce6d3abbf55a95e8cb3bca856f441d Mon Sep 17 00:00:00 2001 From: Inesh Bose <2504266b@student.gla.ac.uk> Date: Fri, 26 May 2023 14:39:22 +0100 Subject: [PATCH 5/5] chore: remove fancy syntax for now --- README.md | 3 --- examples/special.ts | 4 ---- src/reporters/fancy.ts | 4 ---- 3 files changed, 11 deletions(-) diff --git a/README.md b/README.md index 9f2ac01..7f05695 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,6 @@ consola.error(new Error("This is an example error. Everything is fine!")); 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 ecc5ed8..1c4b6cc 100755 --- a/examples/special.ts +++ b/examples/special.ts @@ -20,10 +20,6 @@ consola.log("We can `monospace` keyword using grave accent charachter!"); consola.log("We can also _underline_ words!"); -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 5a4ed09..9c60b9c 100644 --- a/src/reporters/fancy.ts +++ b/src/reporters/fancy.ts @@ -112,10 +112,6 @@ 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