From b43ab1f6ec01c2cb60db1c33873222ac4073d1bf Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 1 Jan 2026 16:57:03 +0100 Subject: [PATCH] style(cli): add more color --- src/cli/program.ts | 14 ++++++++++++ src/cli/shared.ts | 53 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/cli/program.ts b/src/cli/program.ts index 45ae729..e0101d1 100644 --- a/src/cli/program.ts +++ b/src/cli/program.ts @@ -33,6 +33,20 @@ export function createProgram(ctx: CliContext): Command { program.configureHelp({ showGlobalOptions: true, + styleTitle: (t) => ctx.colors.section(t), + styleUsage: (t) => ctx.colors.description(t), + styleCommandText: (t) => ctx.colors.command(t), + styleCommandDescription: (t) => ctx.colors.muted(t), + styleOptionTerm: (t) => ctx.colors.option(t), + styleOptionText: (t) => ctx.colors.option(t), + styleOptionDescription: (t) => ctx.colors.muted(t), + styleArgumentTerm: (t) => ctx.colors.argument(t), + styleArgumentText: (t) => ctx.colors.argument(t), + styleArgumentDescription: (t) => ctx.colors.muted(t), + styleSubcommandTerm: (t) => ctx.colors.command(t), + styleSubcommandText: (t) => ctx.colors.command(t), + styleSubcommandDescription: (t) => ctx.colors.muted(t), + styleDescriptionText: (t) => ctx.colors.muted(t), }); const collect = (value: string, previous: string[] = []): string[] => { diff --git a/src/cli/shared.ts b/src/cli/shared.ts index aa94d4c..8619f8d 100644 --- a/src/cli/shared.ts +++ b/src/cli/shared.ts @@ -190,8 +190,57 @@ export function createCliContext(normalizedArgs: string[], env: NodeJS.ProcessEn accent: wrap((t) => kleur.green(t)), }; - const p = (kind: Parameters[0]): string => statusPrefix(kind, output); - const l = (kind: Parameters[0]): string => labelPrefix(kind, output); + const p = (kind: Parameters[0]): string => { + const prefix = statusPrefix(kind, output); + if (output.plain || !output.color) { + return prefix; + } + if (kind === 'ok') { + return kleur.green(prefix); + } + if (kind === 'warn') { + return kleur.yellow(prefix); + } + if (kind === 'err') { + return kleur.red(prefix); + } + if (kind === 'info') { + return kleur.cyan(prefix); + } + return kleur.gray(prefix); + }; + + const l = (kind: Parameters[0]): string => { + const prefix = labelPrefix(kind, output); + if (output.plain || !output.color) { + return prefix; + } + if (kind === 'url') { + return kleur.cyan(prefix); + } + if (kind === 'date') { + return kleur.magenta(prefix); + } + if (kind === 'source') { + return kleur.gray(prefix); + } + if (kind === 'engine') { + return kleur.blue(prefix); + } + if (kind === 'credentials') { + return kleur.yellow(prefix); + } + if (kind === 'user') { + return kleur.cyan(prefix); + } + if (kind === 'userId') { + return kleur.magenta(prefix); + } + if (kind === 'email') { + return kleur.green(prefix); + } + return kleur.gray(prefix); + }; const config = loadConfig((message) => { console.error(colors.muted(`${p('warn')}${message}`));