We need to run checkResize in a goroutine, otherwise, it will block.
Related: https://github.com/charmbracelet/bubbletea/pull/988#issuecomment-2231811332
Fixes: 7d708384a1 (feat: add a cmd to request window size (#988))
44 lines
774 B
Go
44 lines
774 B
Go
package main
|
|
|
|
// A simple program that queries and displays the window-size.
|
|
|
|
import (
|
|
"log"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
func main() {
|
|
p := tea.NewProgram(model{})
|
|
if _, err := p.Run(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
type model struct{}
|
|
|
|
func (m model) Init() tea.Cmd {
|
|
return nil
|
|
}
|
|
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
switch msg := msg.(type) {
|
|
case tea.KeyMsg:
|
|
if s := msg.String(); s == "ctrl+c" || s == "q" || s == "esc" {
|
|
return m, tea.Quit
|
|
}
|
|
|
|
return m, tea.WindowSize()
|
|
|
|
case tea.WindowSizeMsg:
|
|
return m, tea.Printf("%dx%d", msg.Width, msg.Height)
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
func (m model) View() string {
|
|
s := "When you're done press q to quit. Press any other key to query the window-size.\n"
|
|
|
|
return s
|
|
}
|