mirror of
https://github.com/KeygraphHQ/shannon.git
synced 2026-10-03 06:46:49 +02:00
* feat: surface report at run root and nest run internals under .shannon * feat: use plain-language wording in user-facing terminal messages * feat(cli): guide users to watch scan progress and surface report path on start * docs: sync run-folder layout and CLI wording across docs and comments * feat(cli): add version command reporting package version or git SHA * feat(cli): detect TTY for interactive prompts, color, and progress output * docs: document --yes flag, version command, and tty module * fix(cli): FORCE_COLOR precedence and plain uninstall --yes output * fix(cli): respect empty NO_COLOR * fix(cli): let NO_COLOR take precedence over FORCE_COLOR * docs: mark claude-code-router integration as removed
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
/**
|
|
* Terminal capability detection — output coloring, cursor animation, and
|
|
* whether the user can be prompted interactively.
|
|
*/
|
|
|
|
/** True when stdout is a real terminal — safe for color, cursor moves, and spinners. */
|
|
export function stdoutIsTerminal(): boolean {
|
|
return !!process.stdout.isTTY;
|
|
}
|
|
|
|
/** True when both stdin and stdout are terminals, so interactive prompts can run. */
|
|
function isInteractive(): boolean {
|
|
return !!process.stdin.isTTY && !!process.stdout.isTTY;
|
|
}
|
|
|
|
/** True when color escapes should be emitted. NO_COLOR disables; FORCE_COLOR overrides (0/false/empty = off). */
|
|
export function supportsColor(): boolean {
|
|
if (process.env.NO_COLOR !== undefined) return false;
|
|
|
|
const force = process.env.FORCE_COLOR;
|
|
if (force !== undefined) {
|
|
return force !== '0' && force !== 'false' && force !== '';
|
|
}
|
|
|
|
return stdoutIsTerminal();
|
|
}
|
|
|
|
/** Exit with a clear error when an interactive-only command has no terminal, instead of hanging on a prompt. */
|
|
export function requireInteractive(command: string, alternative: string): void {
|
|
if (isInteractive()) return;
|
|
console.error(`ERROR: '${command}' needs an interactive terminal.`);
|
|
console.error(alternative);
|
|
process.exit(1);
|
|
}
|