github charmbracelet/bubbletea v1.1.0

latest releases: v1.1.2, v2.0.0-alpha.1, v1.1.1...
2 months ago

Let’s Focus

Lose focus much? This release contains support for focus-blur window events.

Usage

All you need to do is to add the program option to your application:

p := tea.NewProgram(model{}, tea.WithReportFocus())
if _, err := p.Run(); err != nil {
	fmt.Fprintln(os.Stderr, "Oof:", err)
	os.Exit(1)
}

Then later in your Update function, you can listen for focus-blur messages:

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	switch msg := msg.(type) {
	case tea.FocusMsg:
		// Focused!
	case tea.BlurMsg:
		// Not focused :(
        }
        return m, nil
}

For details, see WithReportFocus.

Tmux

If you're using tmux, make sure you enable the focus-events option in your config.

set-option -g focus-events on

Happy focusing (whatever that means)!


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.