Terminal: colors, status emoji and a live spinner line for waits at a TTY; plain lines unchanged when piped, in CI, with NO_COLOR, TERM=dumb, --json or MCP; desktop download progress through the log

This commit is contained in:
CRTkafa 2026-10-22 02:15:03 +08:00
parent e1634f6abe
commit f7dd646e57
4 changed files with 98 additions and 5 deletions

View file

@ -26,7 +26,7 @@ import { verify } from './lib/minisign';
import { parsePlist } from './lib/plist';
import { addFolder } from './lib/registry';
import * as rt from './lib/rt';
import { printJson, promptOut } from './lib/log';
import { log, printJson, promptOut } from './lib/log';
import { stdinIsTTY } from './lib/tty';
type Fetch = (url: string) => Promise<Response>;
@ -58,7 +58,7 @@ export function pick(m: Manifest, keys: DownloadKey[], format?: string): [Downlo
}
/** Downloads one installer and keeps it only when its size, SHA-256 and minisign signature are right. */
export async function download(d: Download, dir: string, get: Fetch = fetch, publicKey = PUBLIC_KEY, stallMs = 60_000, say: (s: string) => void = s => console.log(s)): Promise<string> {
export async function download(d: Download, dir: string, get: Fetch = fetch, publicKey = PUBLIC_KEY, stallMs = 60_000, say: (s: string) => void = s => log('desktop', `downloading ${s.trim()}`)): Promise<string> {
const r = await withStall(get(d.url), stallMs, d.url);
if (!r.ok) throw new Error(`${d.url}: HTTP ${r.status}`);
const data = await readBody(r, d, stallMs, say);