cview/demos/panels/main.go

39 lines
838 B
Go
Raw Normal View History

2020-10-15 16:12:10 +00:00
// Demo code for the Panels primitive.
2017-12-27 15:05:00 +00:00
package main
import (
"fmt"
"code.rocketnine.space/tslocum/cview"
2017-12-27 15:05:00 +00:00
)
2020-10-15 16:12:10 +00:00
const panelCount = 5
2017-12-27 15:05:00 +00:00
func main() {
app := cview.NewApplication()
app.EnableMouse(true)
2020-10-15 16:12:10 +00:00
panels := cview.NewPanels()
for panel := 0; panel < panelCount; panel++ {
func(panel int) {
modal := cview.NewModal()
2020-10-15 16:12:10 +00:00
modal.SetText(fmt.Sprintf("This is page %d. Choose where to go next.", panel+1))
modal.AddButtons([]string{"Next", "Quit"})
modal.SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonIndex == 0 {
2020-10-16 01:50:10 +00:00
panels.SetCurrentPanel(fmt.Sprintf("panel-%d", (panel+1)%panelCount))
} else {
app.Stop()
}
})
2020-10-16 01:50:10 +00:00
panels.AddPanel(fmt.Sprintf("panel-%d", panel), modal, false, panel == 0)
2020-10-15 16:12:10 +00:00
}(panel)
2017-12-27 15:05:00 +00:00
}
2020-10-15 16:12:10 +00:00
app.SetRoot(panels, true)
if err := app.Run(); err != nil {
2017-12-27 15:05:00 +00:00
panic(err)
}
}