diff --git a/src/components/App.tsx b/src/components/App.tsx index ed9f6e83..419868d8 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -163,6 +163,7 @@ export default class App extends PureComponent { if (isEnabled) { // Ensure raw mode is enabled only once if (this.rawModeEnabledCount === 0) { + stdin.ref(); stdin.setRawMode(true); stdin.addListener('readable', this.handleReadable); } diff --git a/test/components.tsx b/test/components.tsx index 16801f1b..c3e1beec 100644 --- a/test/components.tsx +++ b/test/components.tsx @@ -449,6 +449,8 @@ test('disable raw mode when all input components are unmounted', t => { stdin.setEncoding = () => {}; stdin.setRawMode = spy(); stdin.isTTY = true; // Without this, setRawMode will throw + stdin.ref = spy(); + stdin.unref = spy(); const options = { stdout, @@ -494,15 +496,20 @@ test('disable raw mode when all input components are unmounted', t => { ); t.true(stdin.setRawMode.calledOnce); + t.true(stdin.ref.calledOnce); t.deepEqual(stdin.setRawMode.firstCall.args, [true]); rerender(); t.true(stdin.setRawMode.calledOnce); + t.true(stdin.ref.calledOnce); + t.true(stdin.unref.notCalled); rerender(); t.true(stdin.setRawMode.calledTwice); + t.true(stdin.ref.calledOnce); + t.true(stdin.unref.calledOnce); t.deepEqual(stdin.setRawMode.lastCall.args, [false]); }); diff --git a/test/focus.tsx b/test/focus.tsx index 31efb21e..adc18511 100644 --- a/test/focus.tsx +++ b/test/focus.tsx @@ -13,6 +13,7 @@ const createStdin = () => { stdin.setEncoding = () => {}; stdin.read = stub(); stdin.unref = () => {}; + stdin.ref = () => {}; return stdin; };