Skip to content

Commit 52e2d4e

Browse files
authored
fix(cli): avoid progress spinners in active TUI input (#75003)
Merged via squash. Prepared head SHA: 129e23e Co-authored-by: velvet-shark <126378+velvet-shark@users.noreply.github.com> Co-authored-by: velvet-shark <126378+velvet-shark@users.noreply.github.com> Reviewed-by: @velvet-shark
1 parent 9cb71f7 commit 52e2d4e

3 files changed

Lines changed: 83 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Docs: https://docs.openclaw.ai
44

5+
## Unreleased
6+
7+
### Fixes
8+
9+
- CLI/progress: suppress nested progress spinners and line clears while TUI input owns raw stdin, so Crestodian `/status` no longer disturbs the active input row. (#75003) Thanks @velvet-shark.
10+
511
## 2026.4.29
612

713
### Highlights

src/cli/progress.test.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
import { describe, expect, it, vi } from "vitest";
2-
import { createCliProgress } from "./progress.js";
2+
import { createCliProgress, shouldUseInteractiveProgressSpinner } from "./progress.js";
3+
4+
function withStdinIsRaw<T>(isRaw: boolean, run: () => T): T {
5+
const original = Object.getOwnPropertyDescriptor(process.stdin, "isRaw");
6+
Object.defineProperty(process.stdin, "isRaw", {
7+
configurable: true,
8+
value: isRaw,
9+
});
10+
try {
11+
return run();
12+
} finally {
13+
if (original) {
14+
Object.defineProperty(process.stdin, "isRaw", original);
15+
} else {
16+
Reflect.deleteProperty(process.stdin, "isRaw");
17+
}
18+
}
19+
}
320

421
describe("cli progress", () => {
522
it("logs progress when non-tty and fallback=log", () => {
@@ -43,4 +60,45 @@ describe("cli progress", () => {
4360

4461
expect(write).not.toHaveBeenCalled();
4562
});
63+
64+
it("does not use readline-backed spinners while raw TUI input is active", () => {
65+
expect(
66+
shouldUseInteractiveProgressSpinner({
67+
streamIsTty: true,
68+
stdinIsRaw: true,
69+
}),
70+
).toBe(false);
71+
});
72+
73+
it("keeps the normal interactive spinner for regular tty commands", () => {
74+
expect(
75+
shouldUseInteractiveProgressSpinner({
76+
streamIsTty: true,
77+
stdinIsRaw: false,
78+
}),
79+
).toBe(true);
80+
});
81+
82+
it("does not write terminal controls when raw TUI input suppresses the default spinner", () => {
83+
const writes: string[] = [];
84+
const stream = {
85+
isTTY: true,
86+
write: vi.fn((chunk: string) => {
87+
writes.push(chunk);
88+
}),
89+
} as unknown as NodeJS.WriteStream;
90+
91+
withStdinIsRaw(true, () => {
92+
const progress = createCliProgress({
93+
label: "Scanning",
94+
total: 2,
95+
stream,
96+
});
97+
progress.setLabel("Still scanning");
98+
progress.tick();
99+
progress.done();
100+
});
101+
102+
expect(writes).toEqual([]);
103+
});
46104
});

src/cli/progress.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ export type ProgressTotalsUpdate = {
3333
label?: string;
3434
};
3535

36+
export function shouldUseInteractiveProgressSpinner(params: {
37+
fallback?: ProgressOptions["fallback"];
38+
streamIsTty?: boolean;
39+
stdinIsRaw?: boolean;
40+
}): boolean {
41+
const spinnerRequested = params.fallback === undefined || params.fallback === "spinner";
42+
return spinnerRequested && params.streamIsTty === true && params.stdinIsRaw !== true;
43+
}
44+
3645
const noopReporter: ProgressReporter = {
3746
setLabel: () => {},
3847
setPercent: () => {},
@@ -57,8 +66,16 @@ export function createCliProgress(options: ProgressOptions): ProgressReporter {
5766

5867
const delayMs = typeof options.delayMs === "number" ? options.delayMs : DEFAULT_DELAY_MS;
5968
const canOsc = isTty && supportsOscProgress(process.env, isTty);
60-
const allowSpinner = isTty && (options.fallback === undefined || options.fallback === "spinner");
69+
const stdinIsRaw = process.stdin.isRaw;
70+
const allowSpinner = shouldUseInteractiveProgressSpinner({
71+
fallback: options.fallback,
72+
streamIsTty: isTty,
73+
stdinIsRaw,
74+
});
6175
const allowLine = isTty && options.fallback === "line";
76+
if (isTty && stdinIsRaw && (options.fallback === undefined || options.fallback === "spinner")) {
77+
return noopReporter;
78+
}
6279

6380
let started = false;
6481
let label = options.label;

0 commit comments

Comments
 (0)