-
-
Notifications
You must be signed in to change notification settings - Fork 234
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
Is there a way to unblock io.Copy(ptmx, os.Stdin)
after exiting the spawned shell
#188
Comments
I had cross posted this question in the bubbletea discord too and their reply lead me to Since this issue is non deterministic, I will test it a bit more and follow up here if cancelReader does indeed fix everything. |
Can you specify your OS? I suspect it is OSX, right? We could set the read in non-block mode, but Golang has a bug on OSX resulting in this using 100% CPU. But it would also behave as you expect. An alternative would be to use select (2) syscall (not go's select keyword) or to watch for SIGIO before read, that way you can be sure the Read call will not block, and it should work everywhere. That is a bit outside the scope of the library though, as it deals more about I/Os than TTYs. |
For reference: golang/go#22099 |
The only way to io.Copy(dst, os.Stdin) returns in raw mode is when io.Copy tries to read a character from stdin and find that dst is no longer valid. For our use here, that presents a problem. Users expect the input to close when they exit the shell. We can't get an extra input here to unblock io.Copy when it is reading from stdin. Enter, cancelreader. We wrap os.Stdin with a cancel reader that can be preempted from another go-routine by calling Cancel() on the cancel reader. The implementation of the cancel reader is platform dependent, but the pkg should work across linux, osx and windows. @creack also points out an alternative way to ensure we don't block on io.Copy reads here: creack/pty#188 (comment)
The only way to io.Copy(dst, os.Stdin) returns in raw mode is when io.Copy tries to read a character from stdin and find that dst is no longer valid. For our use here, that presents a problem. Users expect the input to close when they exit the shell. We can't get an extra input here to unblock io.Copy when it is reading from stdin. Enter, cancelreader. We wrap os.Stdin with a cancel reader that can be preempted from another go-routine by calling Cancel() on the cancel reader. The implementation of the cancel reader is platform dependent, but the pkg should work across linux, osx and windows. @creack also points out an alternative way to ensure we don't block on io.Copy reads here: creack/pty#188 (comment)
verified that using the cancelreader works for now. Thanks for the suggestion of using sigio too. If I run into corner cases with the cancel reader, I will give that a shot. |
Thanks for creating this package!
I'm running into an issue where
pty
doesn't seem to play nice with https://github.com/charmbracelet/bubbletea.I observe that bubbletea programs hang until I press a key ( after exiting the spawned shell by typing exit or ctrl-d)
I'm following the example in the README closely and I think this particular line below is causing the problem.
The need for an extra keystroke to unblock that go-routine seems to be the main issue.
Is there any way to exit the go routine that copies from stdin to ptmx when ptmx closes?
The text was updated successfully, but these errors were encountered: