mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 12:54:07 -07:00
Restore terminal state on startup and resume failures
This commit is contained in:
@@ -32,7 +32,9 @@ process.on('uncaughtException', (error) => {
|
|||||||
} else {
|
} else {
|
||||||
writeToStderr(String(error) + '\n');
|
writeToStderr(String(error) + '\n');
|
||||||
}
|
}
|
||||||
process.exit(1);
|
void runExitCleanup().finally(() => {
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
main().catch(async (error) => {
|
main().catch(async (error) => {
|
||||||
|
|||||||
@@ -641,16 +641,27 @@ export async function main() {
|
|||||||
|
|
||||||
const wasRaw = process.stdin.isRaw;
|
const wasRaw = process.stdin.isRaw;
|
||||||
if (config.isInteractive() && !wasRaw && process.stdin.isTTY) {
|
if (config.isInteractive() && !wasRaw && process.stdin.isTTY) {
|
||||||
|
const restoreRawMode = () => {
|
||||||
|
if (
|
||||||
|
process.stdin.isTTY &&
|
||||||
|
process.stdin.isRaw !== wasRaw &&
|
||||||
|
typeof process.stdin.setRawMode === 'function'
|
||||||
|
) {
|
||||||
|
process.stdin.setRawMode(wasRaw);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Set this as early as possible to avoid spurious characters from
|
// Set this as early as possible to avoid spurious characters from
|
||||||
// input showing up in the output.
|
// input showing up in the output.
|
||||||
process.stdin.setRawMode(true);
|
process.stdin.setRawMode(true);
|
||||||
|
registerCleanup(restoreRawMode);
|
||||||
|
|
||||||
// This cleanup isn't strictly needed but may help in certain situations.
|
// Best-effort terminal restoration if terminated by signals.
|
||||||
process.on('SIGTERM', () => {
|
process.on('SIGTERM', restoreRawMode);
|
||||||
process.stdin.setRawMode(wasRaw);
|
process.on('SIGINT', restoreRawMode);
|
||||||
});
|
registerCleanup(() => {
|
||||||
process.on('SIGINT', () => {
|
process.off('SIGTERM', restoreRawMode);
|
||||||
process.stdin.setRawMode(wasRaw);
|
process.off('SIGINT', restoreRawMode);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user