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

Snippet with fzf fails with "Failed to read /dev/tty" #267

Closed
denisidoro opened this issue Mar 15, 2020 · 3 comments · Fixed by #298
Closed

Snippet with fzf fails with "Failed to read /dev/tty" #267

denisidoro opened this issue Mar 15, 2020 · 3 comments · Fixed by #298
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@denisidoro
Copy link
Owner

The following cheatsheet fails:

% fzf

# call fzf
fzf

I have already tried all tricks with exec, stty, < /dev/tty and so on. Help needed.

@denisidoro denisidoro added new feature New feature or request bug Something isn't working help wanted Extra attention is needed and removed new feature New feature or request labels Mar 15, 2020
@DenSA-Inc
Copy link
Contributor

Your problem is the way linux handles tty's. Terminals are created by calls to openpty which creates something of a pipe that goes through the kernel terminal driver. The driver is responsible for turning ctrl-c into a SIGINT etc. Programs detect the presense of a terminal with isatty which does some ioctl-calls and queries information associated with the file descriptor of stdin.

My guess is that running a command with spawn() (don't you need to call wait() on the child process?) does not "carry over" the terminal information of stdin. One solution is calling exec on unix systems, but this replaces the process's image with the command you're calling and you can't do this more than once. Another solution would be creating your own terminal with openpty and proxying information through them, but this would be too much work for something that could hide bugs.

I'll see if I can find something about rusts Command and terminals

@DenSA-Inc
Copy link
Contributor

As a side note: exec is performed in the bash process you create in navi, therefore it can't take over navi. And < /dev/tty only works if the bash process is already connected to a terminal.

DenSA-Inc added a commit to DenSA-Inc/navi that referenced this issue Mar 20, 2020
@DenSA-Inc
Copy link
Contributor

I found the issue: rather than some complicated terminal magic not working as intended you missed a call to Child::wait(). I assume this way the Child struct gets dropped while the child process is still running. I'm not exactly sure what's supposed to happen then but adding the call to wait() fixed it. Maybe navi exited and closed the streams before fzf could read them.

I also performed a little test with a demo program that executed fzf without waiting for the child process. For some reason I got the fzf ui while my keypresses where sent to my shell and fzf seemingly at random. Sometimes I was able to narrow down fzf search results and sometimes I got autocompletion from my shell in the fzf ui.

denisidoro added a commit that referenced this issue Mar 20, 2020
fixed issue of terminal programs like fzf not recognizing stdin as terminal (#267)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants