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

feat: set the program environment variables #1063

Merged
merged 1 commit into from
Aug 12, 2024
Merged

feat: set the program environment variables #1063

merged 1 commit into from
Aug 12, 2024

Conversation

aymanbagabas
Copy link
Member

@aymanbagabas aymanbagabas commented Jul 18, 2024

This adds the option to provide a custom set of environment variables to use in the Bubble Tea program. When running Bubble Tea in a remote session such as SSH, we need to be able to pass the SSH session's environment variables rather than the server ones.

	// Add the TERM from the SSH session to the environment
	var sess ssh.Session // from the github.com/charmbracelet/ssh package
	pty, _, _ := sess.Pty()
	environ := append(sess.Environ(), "TERM="+pty.Term)
	p := tea.NewProgram(model{}, tea.WithEnvironmen(environ))

Now, the Bubble Tea program running for a remote session can determine the appropriate color profile from the session's environment variables instead of the server's environment variables.

In most cases you'll only need this feature when using Bubble Tea in remote sessions.

Copy link
Member

@meowgorithm meowgorithm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome

@aymanbagabas aymanbagabas mentioned this pull request Jul 18, 2024
Copy link
Member

@caarlos0 caarlos0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing!

@meowgorithm
Copy link
Member

Two questions with this one:

  • Will it have any effect on local programs?
  • How would the user implement it in Wish?

I'd also add a very short example to this PR (and probably the doc comments) so we can reference it later.

This gives the option to provide a custom set of environment variables
to use in the Bubble Tea program. When running Bubble Tea in a remote
session such as SSH, we need to be able to pass the SSH session's
environment variables rather than the server ones.
@aymanbagabas
Copy link
Member Author

Added an example in the code comment

  • Will it have any effect on local programs?

No, bubbletea programs default to os.Environ() if no environment is set.

  • How would the user implement it in Wish?

The bubbletea middleware should pass the SSH session's environment to the program. The middleware should include something like:

	var sess ssh.Session // ssh.Session is a type from the github.com/charmbracelet/ssh package
	pty, _, _ := sess.Pty()
	environ := append(sess.Environ(), "TERM="+pty.Term)
	p := tea.NewProgram(model, tea.WithEnvironment(environ)

aymanbagabas added a commit to charmbracelet/ssh that referenced this pull request Jul 25, 2024
By default, the TERM environment variable is sent separately in the
`pry-req` request when the session is a PTY session. Other environment
variables have their own request type `env` and get handled separately.

This combines these two and returns a slice that contains TERM and all
other sent environment variables.

Refs: charmbracelet/bubbletea#1063
aymanbagabas added a commit to charmbracelet/ssh that referenced this pull request Jul 25, 2024
By default, the TERM environment variable is sent separately in the
`pry-req` request when the session is a PTY session. Other environment
variables have their own request type `env` and get handled separately.

This combines these two and returns a slice that contains TERM and all
other sent environment variables.

Refs: charmbracelet/bubbletea#1063
@aymanbagabas aymanbagabas merged commit cae9acd into master Aug 12, 2024
18 checks passed
@aymanbagabas aymanbagabas deleted the environ branch August 12, 2024 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants