UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

130 lines (129 loc) • 4.27 kB
import { t as ExitError } from "./runtime-B-SLYP-m.mjs"; import { t as sleep } from "./sleep-CkI3nkiJ.mjs"; import { n as isRich, r as theme } from "./theme-BOI0xyRZ.mjs"; import { i as supportsDecorativeEmoji, t as decorativeEmoji } from "./decorative-emoji-CIP77smZ.mjs"; //#region src/cli/claw-banner.ts const MASCOT_ART = [ " •●●:. .:●●•", ":●●●●: :●●●●:", ".●●●●:.:•●●•:.:●●●●.", " .●●●: •●●●●• :●●●.", " ..:••●●●●●●●●••:..", ".::••••●●●●●●••••::.", " . .: •●●●●• :. .", " . :●●●●: .", " .●●●●●●.", " :••••:" ]; const MASCOT_OPEN_ROWS = ["•●•.:. .:.•●•", ":●●●•: :•●●●:"]; const MASCOT_WIDTH = 20; const WORDMARK_ROW_OFFSET = 3; const WORDMARK_ART = [ "█▀▀▀█ █▀▀▀█ █▀▀▀▀ █▄ █ █▀▀▀▀ █ █▀▀▀█ █ █", "█ █ █▀▀▀▀ █▀▀▀ █ ▀▄█ █ █ █▀▀▀█ █▄▀▄█", "▀▀▀▀▀ ▀ ▀▀▀▀▀ ▀ ▀ ▀▀▀▀▀ ▀▀▀▀▀ ▀ ▀ ▀ ▀" ]; const GAP = 3; const BANNER_WIDTH = 71; const ROWS = MASCOT_ART.length; const identityTint = (e) => e; function composeFrame(e) { const t = e.mascotRows ?? MASCOT_ART; const n = []; for (let r = 0; r < ROWS; r++) { const i = (t[r] ?? "").padEnd(MASCOT_WIDTH).slice(0, MASCOT_WIDTH); let a = ""; for (let t = 0; t < i.length; t++) { const n = i[t] ?? " "; a += n === " " ? " " : (e.mascotTint?.(t) ?? theme.accent)(n); } const o = WORDMARK_ART[r - WORDMARK_ROW_OFFSET]; if (o) { a += " ".repeat(GAP); for (let t = 0; t < o.length; t++) { const n = o[t] ?? " "; a += n === " " ? " " : (e.wordmarkTint?.(23 + t) ?? identityTint)(n); } } n.push(a.replace(/\s+$/, "")); } return n; } async function animateBanner(e) { const write = (e) => process.stdout.write(e); let t = false; let n; const r = e ? Promise.resolve(e).then(() => { t = true; }, () => { t = true; }) : null; const pause = async (e) => { if (r) await Promise.race([sleep(e), r]); else await sleep(e); if (n !== void 0) throw new ExitError(n); return !t; }; let i = false; const draw = (e) => { const t = i ? `\x1b[${ROWS}F` : ""; i = true; write(`${t}${e.map((e) => `\x1b[K${e}`).join("\n")}\n`); }; const onSignal = (e) => { n ??= e === "SIGINT" ? 130 : 143; }; const onSigint = () => onSignal("SIGINT"); const onSigterm = () => onSignal("SIGTERM"); process.once("SIGINT", onSigint); process.once("SIGTERM", onSigterm); write("\x1B[?25l"); try { const e = 5; for (let t = 0; t <= e; t++) { const n = Math.round(BANNER_WIDTH * t / e); const tintAt = (e) => (t) => t < n ? e : t < n + 2 ? theme.accentBright : theme.muted; draw(composeFrame({ mascotTint: tintAt(theme.accent), wordmarkTint: tintAt(identityTint) })); if (!await pause(20)) return "settled"; } for (let e = MASCOT_WIDTH; e < 77; e += 9) { const band = (t) => t >= e && t < e + 9 ? theme.accentBright : identityTint; draw(composeFrame({ wordmarkTint: band })); if (!await pause(20)) return "settled"; } draw(composeFrame({ mascotRows: [...MASCOT_OPEN_ROWS, ...MASCOT_ART.slice(2)] })); if (!await pause(35)) return "settled"; draw(composeFrame({})); if (!await pause(35)) return "settled"; draw(composeFrame({})); return "completed"; } finally { try { if (t && i && n === void 0) draw(composeFrame({})); } finally { process.off("SIGINT", onSigint); process.off("SIGTERM", onSigterm); write("\x1B[?25h"); } } } async function printClawBanner(e, t = {}) { if ((process.stdout.columns ?? 80) < BANNER_WIDTH) { const t = decorativeEmoji("🦞"); const n = supportsDecorativeEmoji() && t ? `${t} OPENCLAW ${t}` : "OPENCLAW"; e.log(`${n}\n`); return "static"; } if (!(process.stdout.isTTY && isRich() && !process.env.CI && !process.env.VITEST)) { e.log(`${composeFrame({}).join("\n")}\n`); return "static"; } const n = await animateBanner(t.settleWhen); process.stdout.write("\n"); return n; } //#endregion export { printClawBanner as t };