diff --git a/examples/special.ts b/examples/special.ts index 5a37176..1c4b6cc 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..9c60b9c 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,14 @@ 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") {