From 58ca18584cf9330559734b789a23ede1d24db632 Mon Sep 17 00:00:00 2001 From: Matteo Depalo Date: Tue, 8 Aug 2023 12:06:44 +0100 Subject: [PATCH] Go back to 'data' event in use-input --- src/components/App.tsx | 2 +- src/hooks/use-input.ts | 12 ++---------- test/fixtures/exit-double-raw-mode.tsx | 4 ++-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 823fea4f0..c8779efe5 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -158,8 +158,8 @@ export default class App extends PureComponent { 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++; diff --git a/src/hooks/use-input.ts b/src/hooks/use-input.ts index 4ca723fed..55d37066c 100644 --- a/src/hooks/use-input.ts +++ b/src/hooks/use-input.ts @@ -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]); }; diff --git a/test/fixtures/exit-double-raw-mode.tsx b/test/fixtures/exit-double-raw-mode.tsx index d26719de8..808796244 100644 --- a/test/fixtures/exit-double-raw-mode.tsx +++ b/test/fixtures/exit-double-raw-mode.tsx @@ -32,8 +32,8 @@ function Test() { const {unmount, waitUntilExit} = render(); -process.stdin.on('readable', () => { - if (String(process.stdin.read()) === 'q') { +process.stdin.on('data', data => { + if (String(data) === 'q') { unmount(); } });