Fix issues where escape codes could end up on startup in the input prompt (#7267)

This commit is contained in:
Jacob Richman
2025-09-05 17:18:51 -07:00
committed by GitHub
parent dfd622e096
commit 81904005fc
5 changed files with 167 additions and 50 deletions
+20 -2
View File
@@ -172,8 +172,6 @@ export async function startInteractiveUI(
workspaceRoot: string = process.cwd(),
) {
const version = await getCliVersion();
// Detect and enable Kitty keyboard protocol once at startup
await detectAndEnableKittyProtocol();
setWindowTitle(basename(workspaceRoot), settings);
const instance = render(
<React.StrictMode>
@@ -218,6 +216,24 @@ export async function main() {
argv,
);
const wasRaw = process.stdin.isRaw;
let kittyProtocolDetectionComplete: Promise<boolean> | undefined;
if (config.isInteractive() && !wasRaw) {
// Set this as early as possible to avoid spurious characters from
// input showing up in the output.
process.stdin.setRawMode(true);
// This cleanup isn't strictly needed but may help in certain situations.
process.on('SIGTERM', () => {
process.stdin.setRawMode(wasRaw);
});
process.on('SIGINT', () => {
process.stdin.setRawMode(wasRaw);
});
// Detect and enable Kitty keyboard protocol once at startup.
kittyProtocolDetectionComplete = detectAndEnableKittyProtocol();
}
if (argv.sessionSummary) {
registerCleanup(() => {
const metrics = uiTelemetryService.getMetrics();
@@ -385,6 +401,8 @@ export async function main() {
// Render UI, passing necessary config values. Check that there is no command line question.
if (config.isInteractive()) {
// Need kitty detection to be complete before we can start the interactive UI.
await kittyProtocolDetectionComplete;
await startInteractiveUI(config, settings, startupWarnings);
return;
}