Loading cli/inbox.tsx +1 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import { ActivityEntryPage, ActivityListPage } from "./inbox/view.tsx"; import { recordingSink } from "./log.ts"; import { tableStyle } from "./table.ts"; import { spawnTemporaryServer, type TemporaryServer } from "./tempserver.ts"; import { colorEnabled } from "./utils.ts"; /** * Context data for the ephemeral ActivityPub inbox server. Loading cli/lookup.ts +2 −2 Original line number Diff line number Diff line Loading @@ -18,8 +18,8 @@ import * as colors from "@std/fmt/colors"; import { dirname, isAbsolute, resolve } from "@std/path"; import ora from "ora"; import { getContextLoader, getDocumentLoader } from "./docloader.ts"; import { colorEnabled, formatObjectForOutput } from "./mod.ts"; import { spawnTemporaryServer, type TemporaryServer } from "./tempserver.ts"; import { colorEnabled, formatCliObjectOutputWithColor } from "./utils.ts"; const logger = getLogger(["fedify", "cli", "lookup"]); Loading Loading @@ -109,7 +109,7 @@ export async function writeObjectToStream( } const enableColors = colorEnabled && options.output === undefined; content = formatObjectForOutput(content, enableColors); content = formatCliObjectOutputWithColor(content, enableColors); const encoder = new TextEncoder(); const bytes = encoder.encode(content + "\n"); Loading cli/mod.ts +1 −12 Original line number Diff line number Diff line Loading @@ -11,22 +11,11 @@ import { logFile, recordingSink } from "./log.ts"; import { command as lookup } from "./lookup.ts"; import { command as nodeinfo } from "./nodeinfo.ts"; import { command as tunnel } from "./tunnel.ts"; import { colorEnabled } from "./utils.ts"; import { command as webfinger } from "./webfinger.ts"; export const colorEnabled: boolean = Deno.stdout.isTerminal() && !Deno.env.has("NO_COLOR"); setColorEnabled(colorEnabled); export function formatObjectForOutput(obj: unknown, colors?: boolean): string { const enableColors = colors ?? colorEnabled; if (enableColors) { return Deno.inspect(obj, { colors: true }); } else { return Deno.inspect(obj, { colors: false }); } } const command = new Command() .name("fedify") .version(metadata.version) Loading cli/nodeinfo.ts +4 −3 Original line number Diff line number Diff line Loading @@ -7,8 +7,7 @@ import * as colors from "@std/fmt/colors"; import { isICO, parseICO } from "icojs"; import { defaultFormats, defaultPlugins, intToRGBA } from "jimp"; import ora from "ora"; import { formatObjectForOutput } from "./mod.ts"; import { printJson } from "./utils.ts"; import { formatCliObjectOutputWithColor, printJson } from "./utils.ts"; const logger = getLogger(["fedify", "cli", "nodeinfo"]); Loading Loading @@ -213,7 +212,9 @@ export const command = new Command() for (const [key, value] of Object.entries(nodeInfo.metadata)) { layout[next()] += ` ${colors.dim(key + ":")} ${ indent( typeof value === "string" ? value : formatObjectForOutput(value), typeof value === "string" ? value : formatCliObjectOutputWithColor(value), defaultWidth + 4 + key.length, ) }`; Loading cli/utils.ts +11 −0 Original line number Diff line number Diff line Loading @@ -4,3 +4,14 @@ export function printJson(json: unknown): void { const formatted = JSON.stringify(json, null, 2); console.log(highlight(formatted, { language: "json" })); } export const colorEnabled: boolean = Deno.stdout.isTerminal() && !Deno.env.has("NO_COLOR"); export function formatCliObjectOutputWithColor( obj: unknown, colors?: boolean, ): string { const enableColors = colors ?? colorEnabled; return Deno.inspect(obj, { colors: enableColors }); } Loading
cli/inbox.tsx +1 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import { ActivityEntryPage, ActivityListPage } from "./inbox/view.tsx"; import { recordingSink } from "./log.ts"; import { tableStyle } from "./table.ts"; import { spawnTemporaryServer, type TemporaryServer } from "./tempserver.ts"; import { colorEnabled } from "./utils.ts"; /** * Context data for the ephemeral ActivityPub inbox server. Loading
cli/lookup.ts +2 −2 Original line number Diff line number Diff line Loading @@ -18,8 +18,8 @@ import * as colors from "@std/fmt/colors"; import { dirname, isAbsolute, resolve } from "@std/path"; import ora from "ora"; import { getContextLoader, getDocumentLoader } from "./docloader.ts"; import { colorEnabled, formatObjectForOutput } from "./mod.ts"; import { spawnTemporaryServer, type TemporaryServer } from "./tempserver.ts"; import { colorEnabled, formatCliObjectOutputWithColor } from "./utils.ts"; const logger = getLogger(["fedify", "cli", "lookup"]); Loading Loading @@ -109,7 +109,7 @@ export async function writeObjectToStream( } const enableColors = colorEnabled && options.output === undefined; content = formatObjectForOutput(content, enableColors); content = formatCliObjectOutputWithColor(content, enableColors); const encoder = new TextEncoder(); const bytes = encoder.encode(content + "\n"); Loading
cli/mod.ts +1 −12 Original line number Diff line number Diff line Loading @@ -11,22 +11,11 @@ import { logFile, recordingSink } from "./log.ts"; import { command as lookup } from "./lookup.ts"; import { command as nodeinfo } from "./nodeinfo.ts"; import { command as tunnel } from "./tunnel.ts"; import { colorEnabled } from "./utils.ts"; import { command as webfinger } from "./webfinger.ts"; export const colorEnabled: boolean = Deno.stdout.isTerminal() && !Deno.env.has("NO_COLOR"); setColorEnabled(colorEnabled); export function formatObjectForOutput(obj: unknown, colors?: boolean): string { const enableColors = colors ?? colorEnabled; if (enableColors) { return Deno.inspect(obj, { colors: true }); } else { return Deno.inspect(obj, { colors: false }); } } const command = new Command() .name("fedify") .version(metadata.version) Loading
cli/nodeinfo.ts +4 −3 Original line number Diff line number Diff line Loading @@ -7,8 +7,7 @@ import * as colors from "@std/fmt/colors"; import { isICO, parseICO } from "icojs"; import { defaultFormats, defaultPlugins, intToRGBA } from "jimp"; import ora from "ora"; import { formatObjectForOutput } from "./mod.ts"; import { printJson } from "./utils.ts"; import { formatCliObjectOutputWithColor, printJson } from "./utils.ts"; const logger = getLogger(["fedify", "cli", "nodeinfo"]); Loading Loading @@ -213,7 +212,9 @@ export const command = new Command() for (const [key, value] of Object.entries(nodeInfo.metadata)) { layout[next()] += ` ${colors.dim(key + ":")} ${ indent( typeof value === "string" ? value : formatObjectForOutput(value), typeof value === "string" ? value : formatCliObjectOutputWithColor(value), defaultWidth + 4 + key.length, ) }`; Loading
cli/utils.ts +11 −0 Original line number Diff line number Diff line Loading @@ -4,3 +4,14 @@ export function printJson(json: unknown): void { const formatted = JSON.stringify(json, null, 2); console.log(highlight(formatted, { language: "json" })); } export const colorEnabled: boolean = Deno.stdout.isTerminal() && !Deno.env.has("NO_COLOR"); export function formatCliObjectOutputWithColor( obj: unknown, colors?: boolean, ): string { const enableColors = colors ?? colorEnabled; return Deno.inspect(obj, { colors: enableColors }); }