Closed christophberger closed 5 years ago
Hi, I (roughly) converted your code based on the latest api:
package main
import (
ui "github.com/gizak/termui"
"github.com/gizak/termui/widgets"
)
func main() {
ui.Init()
defer ui.Close()
p := widgets.NewParagraph()
p.Text = "Hey"
grid := ui.NewGrid()
termWidth, termHeight := ui.TerminalDimensions()
grid.SetRect(0, 0, termWidth, termHeight)
grid.Set(
ui.NewRow(1.0/2,
ui.NewCol(1.0/2, p),
),
)
ui.Render(grid)
uiEvents := ui.PollEvents()
for {
select {
case e := <-uiEvents:
switch e.ID {
case "q", "<C-c>":
return
case "<Resize>":
payload := e.Payload.(ui.Resize)
grid.SetRect(0, 0, payload.Width, 0)
ui.Clear()
ui.Render(grid)
}
}
}
}
And it seems to work for me with or without the ui.Clear()
line. I just rewrote most of termui in 958a285 on master, so that may have fixed it, but let me know if you still get issues. Do note that termui has been heavily reworked in that commit, so there's a lot of breaking changes.
When the resize handler func calls termui.Clear(), resizing the terminal window can cause a crash.
This is the test code:
BTW, the resize handler appears to work fine without Clear().