mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:10:51 +00:00
fix(cli): silence raw TUI progress
This commit is contained in:
@@ -1,6 +1,23 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createCliProgress, shouldUseInteractiveProgressSpinner } from "./progress.js";
|
||||
|
||||
function withStdinIsRaw<T>(isRaw: boolean, run: () => T): T {
|
||||
const original = Object.getOwnPropertyDescriptor(process.stdin, "isRaw");
|
||||
Object.defineProperty(process.stdin, "isRaw", {
|
||||
configurable: true,
|
||||
value: isRaw,
|
||||
});
|
||||
try {
|
||||
return run();
|
||||
} finally {
|
||||
if (original) {
|
||||
Object.defineProperty(process.stdin, "isRaw", original);
|
||||
} else {
|
||||
Reflect.deleteProperty(process.stdin, "isRaw");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe("cli progress", () => {
|
||||
it("logs progress when non-tty and fallback=log", () => {
|
||||
const writes: string[] = [];
|
||||
@@ -61,4 +78,27 @@ describe("cli progress", () => {
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("does not write terminal controls when raw TUI input suppresses the default spinner", () => {
|
||||
const writes: string[] = [];
|
||||
const stream = {
|
||||
isTTY: true,
|
||||
write: vi.fn((chunk: string) => {
|
||||
writes.push(chunk);
|
||||
}),
|
||||
} as unknown as NodeJS.WriteStream;
|
||||
|
||||
withStdinIsRaw(true, () => {
|
||||
const progress = createCliProgress({
|
||||
label: "Scanning",
|
||||
total: 2,
|
||||
stream,
|
||||
});
|
||||
progress.setLabel("Still scanning");
|
||||
progress.tick();
|
||||
progress.done();
|
||||
});
|
||||
|
||||
expect(writes).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -66,12 +66,16 @@ export function createCliProgress(options: ProgressOptions): ProgressReporter {
|
||||
|
||||
const delayMs = typeof options.delayMs === "number" ? options.delayMs : DEFAULT_DELAY_MS;
|
||||
const canOsc = isTty && supportsOscProgress(process.env, isTty);
|
||||
const stdinIsRaw = process.stdin.isRaw === true;
|
||||
const allowSpinner = shouldUseInteractiveProgressSpinner({
|
||||
fallback: options.fallback,
|
||||
streamIsTty: isTty,
|
||||
stdinIsRaw: process.stdin.isRaw,
|
||||
stdinIsRaw,
|
||||
});
|
||||
const allowLine = isTty && options.fallback === "line";
|
||||
if (isTty && stdinIsRaw && (options.fallback === undefined || options.fallback === "spinner")) {
|
||||
return noopReporter;
|
||||
}
|
||||
|
||||
let started = false;
|
||||
let label = options.label;
|
||||
|
||||
Reference in New Issue
Block a user