diff --git a/packages/cli/src/formatters/accounting.ts b/packages/cli/src/formatters/accounting.ts new file mode 100644 index 0000000..5bda507 --- /dev/null +++ b/packages/cli/src/formatters/accounting.ts @@ -0,0 +1,31 @@ +import type { AccountExplanation } from "../types/index.js"; +import { colorize } from "../lib/config.js"; +import { truncateAddress } from "../lib/truncate.js"; + +export function formatAccount(acc: AccountExplanation, useColor = false, fullAddress = false): string { + const lines: string[] = [ + `${colorize("Account:", 1, useColor)} ${truncateAddress(acc.account_id, fullAddress)}`, + `${colorize("Summary:", 1, useColor)} ${acc.summary}`, + `${colorize("Subentries:", 1, useColor)} ${acc.subentry_count}`, + `${colorize("Last ledger:", 1, useColor)} ${acc.last_modified_ledger}`, + ]; + + if (acc.home_domain) lines.push(`${colorize("Home domain:", 1, useColor)} ${acc.home_domain}`); + + if (acc.balances.length > 0) { + lines.push("", "Balances:"); + for (const b of acc.balances) { + const asset = b.asset_type === "native" ? "XLM" : `${b.asset_code ?? ""}:${b.asset_issuer ?? ""}`; + lines.push(` ${colorize(b.balance, 32, useColor)} ${asset}`); + } + } + + if (acc.signers.length > 0) { + lines.push("", "Signers:"); + for (const s of acc.signers) { + lines.push(` ${truncateAddress(s.key, fullAddress)} ${colorize(`weight=${s.weight}`, 36, useColor)}`); + } + } + + return lines.join("\n"); +} diff --git a/packages/cli/src/formatters/healthy.ts b/packages/cli/src/formatters/healthy.ts new file mode 100644 index 0000000..f4f77a6 --- /dev/null +++ b/packages/cli/src/formatters/healthy.ts @@ -0,0 +1,16 @@ +import type { HealthResponse } from "../types/index.js"; +import { colorize } from "../lib/config.js"; + +const STATUS_COLOR: Record = { + ok: 32, + degraded: 33, + down: 31, +}; + +export function formatHealth(h: HealthResponse, useColor = false): string { + return [ + `Status: ${colorize(h.status, STATUS_COLOR[h.status], useColor)}`, + `Horizon: ${colorize(h.horizon_reachable ? "reachable" : "unreachable", h.horizon_reachable ? 32 : 31, useColor)}`, + `Version: ${h.version}`, + ].join("\n"); +}