-
Notifications
You must be signed in to change notification settings - Fork 717
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
fix: set stdout in exec when not tty is available #758
Open
ivanvc
wants to merge
1
commit into
charmbracelet:master
Choose a base branch
from
ivanvc:fix-exec-when-no-tty
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does setting the output to
p.output
differ from the (nil)file returned byp.output.TTY()
?If the goal is to output to
stdout
then would usingos.Stdout
work similarly to settingStderr
below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @hopefulTex!
As background, I'm doing this from a Wish (SSH) application. I debugged Wish, Bubble Tea, and termenv to see where would be the best place for this fix. With this in mind, let me answer your questions.
If the output is
nil
, the client won't display anything on the screen.I'm afraid the goal is not to output to
os.Stdout
. Doing so would show the output of the execution on the server's screen rather than the client's.The underlying problem is that Bubble Tea's option
WithOutput(...)
will convert the output (ssh.Session
which implements theio.Writer
interface) into atermenv.Output
. Then, termenv'soutput.TTY()
will returnnil
astty
doesn't implement thetermenv.File
interface (ssh.Session
doesn't defineFd() uintptr
, which makes sense as it doesn't have a file descriptor).So, the possible places to fix this issue are:
FD()
function. But, I would discard this option, as it just instructs to usebubbletea.WithOutput(...)
.ssh.Session
. If so, could you do the wrapping defined in 1? But, it doesn't seem to be the right place as it would add a dependency oncharmbracelet/ssh
. Or, checking if the output is anssh.Session
, and then not creating atermenv.Output
(but it would lose termenv's features).output.TTY()
, checking iftty
is anssh.Session
. However, it has the same issue as in the previous option.Fd() uintptr
method in (ssh.session
)[https://github.com/charmbracelet/ssh/blob/master/session.go]. To be honest, this would be another option, but I'm torn because defining a dummy file descriptor doesn't sound like a good thing to do.Yet another option would be to create a Bubble that receives the
ssh.Session
(as I wouldn't have access to the programinput
/output
as they are not exported). But, the bug would still happen if someone else wants to execute a remote command using a Bubble Tea application with Wish.I created two sample applications that reproduce the issue. One doesn't allocate a pty, so the command (
journalctl -f
) just shows the output to the client. While the other one starts an interactive bash session: https://gist.github.com/ivanvc/cb4580c02e8bb04d17ef286c9183098b