Skip to content

Commit

Permalink
Go back to 'data' event in use-input
Browse files Browse the repository at this point in the history
  • Loading branch information
matteodepalo committed Aug 8, 2023
1 parent df02408 commit 58ca185
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ export default class App extends PureComponent<Props, State> {
if (isEnabled) {
// Ensure raw mode is enabled only once
if (this.rawModeEnabledCount === 0) {
stdin.addListener('readable', this.handleReadable);
stdin.setRawMode(true);
stdin.addListener('readable', this.handleReadable);
}

this.rawModeEnabledCount++;
Expand Down
12 changes: 2 additions & 10 deletions src/hooks/use-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,10 @@ const useInput = (inputHandler: Handler, options: Options = {}) => {
}
};

const handleReadable = () => {
let data;
// eslint-disable-next-line @typescript-eslint/ban-types
while ((data = stdin.read() as string | null) !== null) {
handleData(data);
}
};

stdin?.on('readable', handleReadable);
stdin?.on('data', handleData);

return () => {
stdin?.off('readable', handleReadable);
stdin?.off('data', handleData);
};
}, [options.isActive, stdin, internal_exitOnCtrlC, inputHandler]);
};
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/exit-double-raw-mode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function Test() {

const {unmount, waitUntilExit} = render(<Test />);

process.stdin.on('readable', () => {
if (String(process.stdin.read()) === 'q') {
process.stdin.on('data', data => {
if (String(data) === 'q') {
unmount();
}
});
Expand Down

0 comments on commit 58ca185

Please sign in to comment.