mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
- spinner.mjs: withSpinner/shouldUseSpinner com suporte a quiet/output/CI/NO_COLOR - open.mjs: comando `open` com 16 recursos, respeita ambientes restritos - environment.mjs: detectRestrictedEnvironment/getEnvBanner (codespaces/wsl/gitpod/replit/ci) - clipboard.mjs: copyToClipboard/isClipboardSupported (pbcopy/clip/xclip/xsel/wl-copy) - check-env-doc-sync: vars de plataforma/OS adicionadas ao IGNORE_FROM_CODE
31 lines
881 B
JavaScript
31 lines
881 B
JavaScript
import ora from "ora";
|
|
|
|
export async function withSpinner(label, fn, opts = {}) {
|
|
const enabled = shouldUseSpinner(opts);
|
|
const spinner = enabled
|
|
? ora({ text: label, stream: process.stderr }).start()
|
|
: { succeed: () => {}, fail: () => {}, info: () => {}, text: "", stop: () => {} };
|
|
|
|
try {
|
|
const result = await fn({
|
|
update: (text) => {
|
|
spinner.text = text;
|
|
},
|
|
});
|
|
if (enabled) spinner.succeed(label);
|
|
return result;
|
|
} catch (err) {
|
|
if (enabled) spinner.fail(`${label} — ${err.message}`);
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
export function shouldUseSpinner(opts = {}) {
|
|
if (opts.quiet) return false;
|
|
if (opts.output === "json" || opts.output === "jsonl" || opts.output === "csv") return false;
|
|
if (!process.stderr.isTTY) return false;
|
|
if (process.env.NO_COLOR) return false;
|
|
if (process.env.CI) return false;
|
|
return true;
|
|
}
|