Closed Zebbeni closed 1 year ago
Okay, it looks like batching a WindowSizeMsg Cmd with my tick Cmd solves my problem. It'd be great if bubbletea comes up with a way to avoid polling for window resizes on Windows machines in the future but I'm happy with this for now.
previous:
func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.(type) {
case tickMsg:
w, h, _ := term.GetSize(int(os.Stdout.Fd()))
if w != m.w || h != m.h {
m.updateSize(w, h)
}
return m, tick
}
return m, nil
}
solution:
func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.(type) {
case tickMsg:
w, h, _ := term.GetSize(int(os.Stdout.Fd()))
if w != m.w || h != m.h {
m.updateSize(w, h)
}
return m, tea.Batch(tick, func() tea.Msg { return tea.WindowSizeMsg{Width: w, Height: h} })
}
return m, nil
}
What issues are you having with the tea.WindowSizeMsg
on Windows? It should work cross platform. The resizes also trigger the tea.WindowSizeMsg
, you shouldn't be having to trigger it manually
I'm doing a simple experiment to poll the terminal for size changes and update a bordered viewport to span the full window. (It's not an ideal solution but I can't rely on
WindowSizeMsg
events on Windows.) In some cases think I'm experiencing https://github.com/charmbracelet/bubbletea/issues/573 but it tends to correct itself with subsequent resizes. The more consistent problem I'm finding is that the viewport gets truncated on the width the terminal window had at the time the program launched, and its y offset seems to get messed up if I enlarge the terminal window beyond its original height. I don't see the style MaxWidth or MaxHeight being set to anything unexpected so I wonder if this is a bug? Or is there something else I'm missing?