2026-01-18 03:55:09 +00:00
|
|
|
import { clearActiveProgressLine } from "./terminal/progress-line.js";
|
2026-02-03 06:10:19 +00:00
|
|
|
import { restoreTerminalState } from "./terminal/restore.js";
|
2026-01-18 03:55:09 +00:00
|
|
|
|
2025-11-25 02:16:54 +01:00
|
|
|
export type RuntimeEnv = {
|
2025-11-26 00:53:53 +01:00
|
|
|
log: typeof console.log;
|
|
|
|
|
error: typeof console.error;
|
|
|
|
|
exit: (code: number) => never;
|
2025-11-25 02:16:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const defaultRuntime: RuntimeEnv = {
|
2026-01-18 03:55:09 +00:00
|
|
|
log: (...args: Parameters<typeof console.log>) => {
|
|
|
|
|
clearActiveProgressLine();
|
|
|
|
|
console.log(...args);
|
|
|
|
|
},
|
|
|
|
|
error: (...args: Parameters<typeof console.error>) => {
|
|
|
|
|
clearActiveProgressLine();
|
|
|
|
|
console.error(...args);
|
|
|
|
|
},
|
2025-11-26 00:53:53 +01:00
|
|
|
exit: (code) => {
|
2026-02-03 06:10:19 +00:00
|
|
|
restoreTerminalState("runtime exit");
|
2025-11-26 00:53:53 +01:00
|
|
|
process.exit(code);
|
|
|
|
|
throw new Error("unreachable"); // satisfies tests when mocked
|
|
|
|
|
},
|
2025-11-25 02:16:54 +01:00
|
|
|
};
|