Skip to content
Myr

fix: query window-size in a goroutine (#1059)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

We need to run checkResize in a goroutine, otherwise, it will block.

authored by Ayman Bagabas · committed by GitHub · parent 7d70838 · Browse files · 2 files+45 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Related: https://github.com/charmbracelet/bubbletea/pull/988#issuecomment-2231811332
  • Fixes: 7d708384a105 (feat: add a cmd to request window size (#988))

Diff stats

2 files+45 added−1 removed

  • other:+45 added−1 removed

2 files+45 added−1 removed

added:examples/window-size/main.go+44 added
1package main23// A simple program that queries and displays the window-size.45import (6 "log"78 tea "github.com/charmbracelet/bubbletea"9)1011func main() {12 p := tea.NewProgram(model{})13 if _, err := p.Run(); err != nil {14 log.Fatal(err)15 }16}1718type model struct{}1920func (m model) Init() tea.Cmd {21 return nil22}2324func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {25 switch msg := msg.(type) {26 case tea.KeyMsg:27 if s := msg.String(); s == "ctrl+c" || s == "q" || s == "esc" {28 return m, tea.Quit29 }3031 return m, tea.WindowSize()3233 case tea.WindowSizeMsg:34 return m, tea.Printf("%dx%d", msg.Width, msg.Height)35 }3637 return m, nil38}3940func (m model) View() string {41 s := "When you're done press q to quit. Press any other key to query the window-size.\n"4243 return s44}
modified:tea.go+1 added-1 removed
422 unmodified lines
423 case setWindowTitleMsg:424 p.SetWindowTitle(string(msg))425426 case windowSizeMsg:427 p.checkResize()427 go p.checkResize()428 }429430 // Process internal messages for the renderer.431 if r, ok := p.renderer.(*standardRenderer); ok {
319 unmodified lines