From 7c27c2d659dc9de547e2145a9d93291a87ff282f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Feb 2026 02:42:46 +0000 Subject: [PATCH] refactor(daemon-cli): share status text styling --- src/cli/daemon-cli/shared.ts | 14 ++++++++++++++ src/cli/daemon-cli/status.print.ts | 12 ++++-------- src/cli/node-cli/daemon.ts | 13 ++++--------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/cli/daemon-cli/shared.ts b/src/cli/daemon-cli/shared.ts index 4c07458fb2d..ef37e855b24 100644 --- a/src/cli/daemon-cli/shared.ts +++ b/src/cli/daemon-cli/shared.ts @@ -7,12 +7,26 @@ import { resolveGatewayLogPaths } from "../../daemon/launchd.js"; import { formatRuntimeStatus } from "../../daemon/runtime-format.js"; import { pickPrimaryLanIPv4 } from "../../gateway/net.js"; import { getResolvedLoggerSettings } from "../../logging.js"; +import { colorize, isRich, theme } from "../../terminal/theme.js"; import { formatCliCommand } from "../command-format.js"; import { parsePort } from "../shared/parse-port.js"; export { formatRuntimeStatus }; export { parsePort }; +export function createCliStatusTextStyles() { + const rich = isRich(); + return { + rich, + label: (value: string) => colorize(rich, theme.muted, value), + accent: (value: string) => colorize(rich, theme.accent, value), + infoText: (value: string) => colorize(rich, theme.info, value), + okText: (value: string) => colorize(rich, theme.success, value), + warnText: (value: string) => colorize(rich, theme.warn, value), + errorText: (value: string) => colorize(rich, theme.error, value), + }; +} + export function parsePortFromArgs(programArguments: string[] | undefined): number | null { if (!programArguments?.length) { return null; diff --git a/src/cli/daemon-cli/status.print.ts b/src/cli/daemon-cli/status.print.ts index 24249ab1dc1..bfa0cfa69c2 100644 --- a/src/cli/daemon-cli/status.print.ts +++ b/src/cli/daemon-cli/status.print.ts @@ -12,10 +12,11 @@ import { import { isWSLEnv } from "../../infra/wsl.js"; import { getResolvedLoggerSettings } from "../../logging.js"; import { defaultRuntime } from "../../runtime.js"; -import { colorize, isRich, theme } from "../../terminal/theme.js"; +import { colorize, theme } from "../../terminal/theme.js"; import { shortenHomePath } from "../../utils.js"; import { formatCliCommand } from "../command-format.js"; import { + createCliStatusTextStyles, filterDaemonEnv, formatRuntimeStatus, renderRuntimeHints, @@ -53,13 +54,8 @@ export function printDaemonStatus(status: DaemonStatus, opts: { json: boolean }) return; } - const rich = isRich(); - const label = (value: string) => colorize(rich, theme.muted, value); - const accent = (value: string) => colorize(rich, theme.accent, value); - const infoText = (value: string) => colorize(rich, theme.info, value); - const okText = (value: string) => colorize(rich, theme.success, value); - const warnText = (value: string) => colorize(rich, theme.warn, value); - const errorText = (value: string) => colorize(rich, theme.error, value); + const { rich, label, accent, infoText, okText, warnText, errorText } = + createCliStatusTextStyles(); const spacer = () => defaultRuntime.log(""); const { service, rpc, extraServices } = status; diff --git a/src/cli/node-cli/daemon.ts b/src/cli/node-cli/daemon.ts index 35d579ca9ed..9c53af76178 100644 --- a/src/cli/node-cli/daemon.ts +++ b/src/cli/node-cli/daemon.ts @@ -14,7 +14,7 @@ import { resolveGatewayLogPaths } from "../../daemon/launchd.js"; import { resolveNodeService } from "../../daemon/node-service.js"; import { loadNodeHostConfig } from "../../node-host/config.js"; import { defaultRuntime } from "../../runtime.js"; -import { colorize, isRich, theme } from "../../terminal/theme.js"; +import { colorize, theme } from "../../terminal/theme.js"; import { formatCliCommand } from "../command-format.js"; import { runServiceRestart, @@ -27,7 +27,7 @@ import { createDaemonActionContext, installDaemonServiceAndEmit, } from "../daemon-cli/response.js"; -import { formatRuntimeStatus, parsePort } from "../daemon-cli/shared.js"; +import { createCliStatusTextStyles, formatRuntimeStatus, parsePort } from "../daemon-cli/shared.js"; type NodeDaemonInstallOptions = { host?: string; @@ -243,13 +243,8 @@ export async function runNodeDaemonStatus(opts: NodeDaemonStatusOptions = {}) { return; } - const rich = isRich(); - const label = (value: string) => colorize(rich, theme.muted, value); - const accent = (value: string) => colorize(rich, theme.accent, value); - const infoText = (value: string) => colorize(rich, theme.info, value); - const okText = (value: string) => colorize(rich, theme.success, value); - const warnText = (value: string) => colorize(rich, theme.warn, value); - const errorText = (value: string) => colorize(rich, theme.error, value); + const { rich, label, accent, infoText, okText, warnText, errorText } = + createCliStatusTextStyles(); const serviceStatus = loaded ? okText(service.loadedText) : warnText(service.notLoadedText); defaultRuntime.log(`${label("Service:")} ${accent(service.label)} (${serviceStatus})`);