Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close stdin before waiting to allow --select-1 to work #34

Merged
merged 2 commits into from Mar 6, 2024

Conversation

awood
Copy link
Contributor

@awood awood commented Feb 29, 2024

Prior to this patch, using the --select-1 option with iterfzf would result in FZF block indefinitely. When stdin is left open, --select-1 would never terminate since FZF anticipates more input and the POpen.wait() call just hangs. By closing stdin before making the call to POpen.wait(), FZF is only waiting on user input (if any is required) and not blocking for any other reason.

This patch also includes a very rudimentary unit test suite that can be run with python -m unittest. The suite requires the user to press the enter key. Presumably there is a way to use unittest.mock to patch stdin and replace it with a defined string so that the test suite can run without manual intervention, but the complexities of that operation eluded me. My working theory is that it will be necessary to use the pty module to control terminal operations programmatically, but that is beyond my level of expertise.

Prior to this patch, using the --select-1 option with iterfzf would
result in FZF block indefinitely.  When stdin is left open, --select-1
would never terminate since FZF anticipates more input and the
POpen.wait() call just hangs.  By closing stdin before making the call
to POpen.wait(), FZF is only waiting on user input (if any is required)
and not blocking for any other reason.

This patch also includes a very rudimentary unit test suite that can be
run with `python -m unittest`.  The suite requires the user to press the
enter key.  Presumably there is a way to use unittest.mock to patch
stdin and replace it with a defined string so that the test suite can
run without manual intervention, but the complexities of that operation
eluded me.  My working theory is that it will be necessary to use the
pty module to control terminal operations programmatically, but that is
beyond my level of expertise.
@dahlia
Copy link
Owner

dahlia commented Mar 6, 2024

Thnaks for your contribution!

@dahlia dahlia merged commit cd7e119 into dahlia:main Mar 6, 2024
4 checks passed
dahlia added a commit that referenced this pull request Mar 6, 2024
dahlia added a commit that referenced this pull request Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants