2018-01-04 04:13:32 +08:00
|
|
|
// Demo code for the Pages primitive.
|
2017-12-27 23:05:00 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/rivo/tview"
|
|
|
|
)
|
|
|
|
|
|
|
|
const pageCount = 5
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := tview.NewApplication()
|
|
|
|
pages := tview.NewPages()
|
|
|
|
for page := 0; page < pageCount; page++ {
|
|
|
|
func(page int) {
|
|
|
|
pages.AddPage(fmt.Sprintf("page-%d", page),
|
|
|
|
tview.NewModal().
|
|
|
|
SetText(fmt.Sprintf("This is page %d. Choose where to go next.", page+1)).
|
|
|
|
AddButtons([]string{"Next", "Quit"}).
|
|
|
|
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
|
|
|
if buttonIndex == 0 {
|
|
|
|
pages.SwitchToPage(fmt.Sprintf("page-%d", (page+1)%pageCount))
|
|
|
|
} else {
|
|
|
|
app.Stop()
|
|
|
|
}
|
|
|
|
}),
|
2017-12-28 05:28:16 +08:00
|
|
|
false,
|
2017-12-27 23:05:00 +08:00
|
|
|
page == 0)
|
|
|
|
}(page)
|
|
|
|
}
|
2020-03-28 01:41:44 +08:00
|
|
|
if err := app.SetRoot(pages, true).EnableMouse(true).Run(); err != nil {
|
2017-12-27 23:05:00 +08:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|