v1.1.0
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)!
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.