Fix bug where users are unable to re-enter disconnected terminals. (#8765)

This commit is contained in:
Jacob Richman
2025-09-20 10:59:37 -07:00
committed by GitHub
parent 2216856e3c
commit 375b8522fc
15 changed files with 267 additions and 55 deletions

View File

@@ -6,6 +6,7 @@
import { useStdin, useStdout } from 'ink';
import { useEffect, useState } from 'react';
import { useKeypress } from './useKeypress.js';
// ANSI escape codes to enable/disable terminal focus reporting
export const ENABLE_FOCUS_REPORTING = '\x1b[?1004h';
@@ -44,5 +45,18 @@ export const useFocus = () => {
};
}, [stdin, stdout]);
useKeypress(
(_) => {
if (!isFocused) {
// If the user has typed a key, and we cannot possibly be focused out.
// This is a workaround for some tmux use cases. It is still useful to
// listen for the true FOCUS_IN event as well as that will update the
// focus state earlier than waiting for a keypress.
setIsFocused(true);
}
},
{ isActive: true },
);
return isFocused;
};