fix: allow tui to open /dev/tty as fallback#9037
Merged
Merged
Conversation
If it's available, we should try to fallback to `/dev/tty` as a fallback. This logic is *borrowed* from bubbletea, however, we can't just use `WithInputTTY`, since this requires that `/dev/tty` exists - we want to continue on, even if it doesn't. This allows us to neatly handle the `echo "" | dagger shell` case - stdin is not a TUI, but we can still usually find one at `/dev/tty`, so we should try and do that. Note: we also do a little refactor of `findTTYs` to directly return `io.Reader`/`io.Writer`s - this avoids the horror of typed nils, which can result in passing a `nil` `os.File` into bubbletea (which is *does not like*). Signed-off-by: Justin Chadwell <me@jedevc.com>
This *really* doesn't happen except in truly bizarrely concocted test cases - it's just nice to not panic if it does happen. Signed-off-by: Justin Chadwell <me@jedevc.com>
vito
approved these changes
Nov 22, 2024
helderco
approved these changes
Nov 22, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some various little things found while investigating TTY magic in the progress output. Original discussion in discord.
It seems like we'll also need a bubbletea fix, as noticed by @vito:
However, we should be able to cleverly fallback to
/dev/ttyif it exists, which is what this PR does.You can simulate
/dev/ttynot existing by using thesetsidwrapper (however, this still breaks until the above-mentioned bubbletea fix can be made). E.g.:fix: avoid panic if no stdin is available when launching terminal
If it's available, we should try to fallback to
/dev/ttyas a fallback.This logic is borrowed from bubbletea, however, we can't just use
WithInputTTY, since this requires that/dev/ttyexists - we want tocontinue on, even if it doesn't.
This allows us to neatly handle the
echo "" | dagger shellcase -stdin is not a TUI, but we can still usually find one at
/dev/tty, sowe should try and do that.
Note: we also do a little refactor of
findTTYsto directly returnio.Reader/io.Writers - this avoids the horror of typed nils, whichcan result in passing a
nilos.Fileinto bubbletea (which is doesnot like).
fix: avoid panic if no stdin is available when launching terminal
This really doesn't happen except in truly bizarrely concocted test
cases - it's just nice to not panic if it does happen.