mirror of
https://github.com/status-im/status-go-monitor.git
synced 2025-01-12 04:14:11 +00:00
add Enabled attribute for ViewController
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
aa49194e75
commit
71c4d860e3
21
main.go
21
main.go
@ -1,9 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/jroimartin/gocui"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
||||
type rcpResp map[string]interface{}
|
||||
@ -33,6 +34,7 @@ func main() {
|
||||
Name: "main",
|
||||
Title: "Peers",
|
||||
Placeholder: "Loading peers...",
|
||||
Enabled: true,
|
||||
Cursor: true,
|
||||
Highlight: true,
|
||||
Current: true,
|
||||
@ -40,12 +42,8 @@ func main() {
|
||||
SelBgColor: gocui.ColorGreen,
|
||||
State: peers,
|
||||
// corner positions
|
||||
TopLeft: func(mx, my int) (int, int) {
|
||||
return 0, 0
|
||||
},
|
||||
BotRight: func(mx, my int) (int, int) {
|
||||
return mx - 1, my / 2
|
||||
},
|
||||
TopLeft: func(mx, my int) (int, int) { return 0, 0 },
|
||||
BotRight: func(mx, my int) (int, int) { return mx - 1, my / 2 },
|
||||
}
|
||||
// bindings defined separately so handlers can reference mainView
|
||||
mainView.Keybindings = []Binding{
|
||||
@ -59,14 +57,11 @@ func main() {
|
||||
Name: "info",
|
||||
Title: "Details",
|
||||
Placeholder: "Loading details...",
|
||||
Enabled: true,
|
||||
Wrap: true,
|
||||
// corner positions
|
||||
TopLeft: func(mx, my int) (int, int) {
|
||||
return 0, my/2 + 1
|
||||
},
|
||||
BotRight: func(mx, my int) (int, int) {
|
||||
return mx - 1, my - 1
|
||||
},
|
||||
TopLeft: func(mx, my int) (int, int) { return 0, my/2 + 1 },
|
||||
BotRight: func(mx, my int) (int, int) { return mx - 1, my - 1 },
|
||||
}
|
||||
|
||||
views := []*ViewController{mainView, infoView}
|
||||
|
10
view.go
10
view.go
@ -10,10 +10,12 @@ type ViewController struct {
|
||||
Name string
|
||||
Title string
|
||||
Placeholder string
|
||||
Enabled bool
|
||||
Wrap bool
|
||||
Cursor bool
|
||||
Current bool
|
||||
Highlight bool
|
||||
OnTop bool
|
||||
TopLeft func(int, int) (int, int)
|
||||
BotRight func(int, int) (int, int)
|
||||
SelBgColor gocui.Attribute
|
||||
@ -32,6 +34,9 @@ func (m *ViewManager) Layout(g *gocui.Gui) error {
|
||||
mx, my := g.Size()
|
||||
|
||||
for _, cfg := range m.views {
|
||||
if !cfg.Enabled {
|
||||
continue
|
||||
}
|
||||
x0, y0 := cfg.TopLeft(mx, my)
|
||||
x1, y1 := cfg.BotRight(mx, my)
|
||||
|
||||
@ -49,7 +54,10 @@ func (m *ViewManager) Layout(g *gocui.Gui) error {
|
||||
v.SetCursor(0, 0)
|
||||
}
|
||||
if cfg.Current {
|
||||
g.SetCurrentView("main")
|
||||
g.SetCurrentView(cfg.Name)
|
||||
}
|
||||
if cfg.OnTop {
|
||||
g.SetViewOnTop(cfg.Name)
|
||||
}
|
||||
fmt.Fprintln(v, cfg.Placeholder)
|
||||
cfg.SetKeybindings(g)
|
||||
|
Loading…
x
Reference in New Issue
Block a user