dahlia / iterfzf

Pythonic interface to fzf, a CLI fuzzy finder
https://pypi.python.org/pypi/iterfzf
GNU General Public License v3.0
164 stars 19 forks source link

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

Closed awood closed 7 months ago

awood commented 7 months ago

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 commented 7 months ago

Thnaks for your contribution!