github charmbracelet/bubbletea v0.27.0

latest releases: v2.0.0-alpha.1, v1.1.1, v1.1.0...
one month ago

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
	}

	// ...
}

Example

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!

Fixed


The Charm logo

Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.

Don't miss a new bubbletea release

NewReleases is sending notifications on new releases.