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