summaryrefslogtreecommitdiff
path: root/examples/go-dashboard/ui/ui.go
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2020-09-01 23:44:09 +0200
committerToni Uhlig <matzeton@googlemail.com>2020-09-01 23:46:07 +0200
commit0a03293d16ca0fc9f493a58748da1c43d35782e4 (patch)
treea1ceefdb8b21615de9e34d8da36d805ecb1e7990 /examples/go-dashboard/ui/ui.go
parent70febd225b0255cee6408a97b360f4edb7c7e8e3 (diff)
go-dashboard: go mod/vendor support + termdash text user interface
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'examples/go-dashboard/ui/ui.go')
-rw-r--r--examples/go-dashboard/ui/ui.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/examples/go-dashboard/ui/ui.go b/examples/go-dashboard/ui/ui.go
new file mode 100644
index 000000000..e8c89f81d
--- /dev/null
+++ b/examples/go-dashboard/ui/ui.go
@@ -0,0 +1,77 @@
+package ui
+
+import (
+ "context"
+ "time"
+
+ "github.com/mum4k/termdash"
+ "github.com/mum4k/termdash/container"
+ "github.com/mum4k/termdash/keyboard"
+ "github.com/mum4k/termdash/linestyle"
+ "github.com/mum4k/termdash/terminal/termbox"
+ "github.com/mum4k/termdash/terminal/terminalapi"
+ "github.com/mum4k/termdash/widgets/text"
+)
+
+const rootID = "root"
+const redrawInterval = 250 * time.Millisecond
+
+type widgets struct {
+ menu *text.Text
+}
+
+func newWidgets(ctx context.Context) (*widgets, error) {
+ menu, err := text.New(text.RollContent(), text.WrapAtWords())
+ if err != nil {
+ panic(err)
+ }
+
+ return &widgets{
+ menu: menu,
+ }, nil
+}
+
+func Init() {
+ term, err := termbox.New(termbox.ColorMode(terminalapi.ColorMode256))
+
+ if err != nil {
+ panic(err)
+ }
+ defer term.Close()
+
+ ctx, cancel := context.WithCancel(context.Background())
+ wdgts, err := newWidgets(ctx)
+ if err != nil {
+ panic(err)
+ }
+
+ cnt, err := container.New(term,
+ container.Border(linestyle.None),
+ container.BorderTitle("[ESC to Quit]"),
+ container.SplitHorizontal(
+ container.Top(
+ container.Border(linestyle.Light),
+ container.BorderTitle("Go nDPId Dashboard"),
+ container.PlaceWidget(wdgts.menu),
+ ),
+ container.Bottom(
+ container.Border(linestyle.Light),
+ container.BorderTitle("Raw JSON"),
+ container.PlaceWidget(wdgts.menu),
+ ),
+ container.SplitFixed(3),
+ ),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ quitter := func(k *terminalapi.Keyboard) {
+ if k.Key == keyboard.KeyEsc || k.Key == keyboard.KeyCtrlC {
+ cancel()
+ }
+ }
+ if err := termdash.Run(ctx, term, cnt, termdash.KeyboardSubscriber(quitter), termdash.RedrawInterval(redrawInterval)); err != nil {
+ panic(err)
+ }
+}