Skip to content

Instantly share code, notes, and snippets.

@pkramme
Last active August 22, 2019 22:04
Show Gist options
  • Save pkramme/704cc6946fb7728faad136814f104d09 to your computer and use it in GitHub Desktop.
Save pkramme/704cc6946fb7728faad136814f104d09 to your computer and use it in GitHub Desktop.
package main
import "github.com/rivo/tview"
func main() {
app := tview.NewApplication()
MainPages := tview.NewPages()
QuitDialog := tview.NewModal().
SetText("Do you want to quit the application?").
AddButtons([]string{"Cancel", "Quit"}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == "Quit" {
app.Stop()
} else {
MainPages.SwitchToPage("main")
}
})
MainMenu := tview.NewList().AddItem("Quit", "Press to exit", 'q', func() {
MainPages.AddAndSwitchToPage("QuitDialog", QuitDialog, true)
})
MainPages.AddPage("main", MainMenu, false, true)
if err := app.SetRoot(MainPages, true).Run(); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment