| 1 |
|
| 2 |
package main |
| 3 |
|
| 4 |
import ( |
| 5 |
"fmt" |
| 6 |
|
| 7 |
"github.com/rivo/tview" |
| 8 |
) |
| 9 |
|
| 10 |
const pageCount = 5 |
| 11 |
|
| 12 |
func main() { |
| 13 |
app := tview.NewApplication() |
| 14 |
pages := tview.NewPages() |
| 15 |
for page := 0; page < pageCount; page++ { |
| 16 |
func(page int) { |
| 17 |
pages.AddPage(fmt.Sprintf("page-%d", page), |
| 18 |
tview.NewModal(). |
| 19 |
SetText(fmt.Sprintf("This is page %d. Choose where to go next.", page+1)). |
| 20 |
AddButtons([]string{"Next", "Quit"}). |
| 21 |
SetDoneFunc(func(buttonIndex int, buttonLabel string) { |
| 22 |
if buttonIndex == 0 { |
| 23 |
pages.SwitchToPage(fmt.Sprintf("page-%d", (page+1)%pageCount)) |
| 24 |
} else { |
| 25 |
app.Stop() |
| 26 |
} |
| 27 |
}), |
| 28 |
false, |
| 29 |
page == 0) |
| 30 |
}(page) |
| 31 |
} |
| 32 |
if err := app.SetRoot(pages, true).EnableMouse(true).Run(); err != nil { |
| 33 |
panic(err) |
| 34 |
} |
| 35 |
} |