v0.27.0
Suspending, environment hacking, and more
Hi! This release has three nice little features and some bug fixes. Let's take a look:
Suspending and resuming
At last, now you can programmatically suspend and resume programs with the tea.Suspend
command and handle resumes with the tea.ResumeMsg
message:
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
// Suspend with ctrl+z!
case tea.KeyMsg:
switch msg.String() {
case "ctrl+z":
m.suspended = true
return m, tea.Suspend
}
// Handle resumes
case tea.ResumeMsg:
m.suspended = false
return m, nil
}
// ...
}
There's also a tea.SuspendMsg
that flows through Update
on suspension.
Special thanks to @knz for prototyping the original implementation of this.
Setting the environment
When Bubble Tea is behind Wish you may have needed to pass environment variables from the remote session to the Program
. Now you can with the all new tea.WithEnvironment:
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)
Requesting the window dimensions
All the Bubble Tea pros know that you get a tea.WindowSizeMsg
when the Program
starts and when the window resizes. Now you can just query it on demand too with the tea.WindowSize
command.
Changelog
New!
- 7d70838: feat: add a cmd to request window size (#988) (@aymanbagabas)
- ea13ffb: feat: allow to suspend bubbletea programs (#1054) (@caarlos0)
- cae9acd: feat: set the program environment variables (#1063) (@aymanbagabas)
Fixed
- 7c1bfc0: query window-size in a goroutine (#1059) (@aymanbagabas)
- 4497aa9: reset cursor position on renderer exit (#1058) (@aymanbagabas)
- d6a19f0: wrap
ErrProgramKilled
error (@aymanbagabas) - 4a9620e: fix bugs in package-manager example (@AkshayKalose)
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.