Skip to content

Commit

Permalink
Fix inability to read user input after app exit (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
matteodepalo authored Sep 9, 2023
1 parent adc2c0c commit 45dcc1e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default class App extends PureComponent<Props, State> {
if (isEnabled) {
// Ensure raw mode is enabled only once
if (this.rawModeEnabledCount === 0) {
stdin.ref();
stdin.setRawMode(true);
stdin.addListener('readable', this.handleReadable);
}
Expand Down
7 changes: 7 additions & 0 deletions test/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(<Test renderFirstInput />);

t.true(stdin.setRawMode.calledOnce);
t.true(stdin.ref.calledOnce);
t.true(stdin.unref.notCalled);

rerender(<Test />);

t.true(stdin.setRawMode.calledTwice);
t.true(stdin.ref.calledOnce);
t.true(stdin.unref.calledOnce);
t.deepEqual(stdin.setRawMode.lastCall.args, [false]);
});

Expand Down
1 change: 1 addition & 0 deletions test/focus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const createStdin = () => {
stdin.setEncoding = () => {};
stdin.read = stub();
stdin.unref = () => {};
stdin.ref = () => {};

return stdin;
};
Expand Down

0 comments on commit 45dcc1e

Please sign in to comment.