File: main.go

package info (click to toggle)
golang-code.rocketnine-tslocum-cview 1.5.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,396 kB
  • sloc: makefile: 40
file content (38 lines) | stat: -rw-r--r-- 838 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Demo code for the Panels primitive.
package main

import (
	"fmt"

	"code.rocketnine.space/tslocum/cview"
)

const panelCount = 5

func main() {
	app := cview.NewApplication()
	app.EnableMouse(true)

	panels := cview.NewPanels()
	for panel := 0; panel < panelCount; panel++ {
		func(panel int) {
			modal := cview.NewModal()
			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 {
					panels.SetCurrentPanel(fmt.Sprintf("panel-%d", (panel+1)%panelCount))
				} else {
					app.Stop()
				}
			})

			panels.AddPanel(fmt.Sprintf("panel-%d", panel), modal, false, panel == 0)
		}(panel)
	}

	app.SetRoot(panels, true)
	if err := app.Run(); err != nil {
		panic(err)
	}
}