mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
dettach menus from grid
This commit is contained in:
parent
e73732ae98
commit
409d44e8a3
16
grid.go
16
grid.go
@ -102,17 +102,15 @@ func headerPar(s string) *ui.Par {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
type View func(*Grid)
|
|
||||||
|
|
||||||
func ResetView() {
|
func ResetView() {
|
||||||
ui.DefaultEvtStream.ResetHandlers()
|
ui.DefaultEvtStream.ResetHandlers()
|
||||||
ui.Clear()
|
ui.Clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Grid) OpenView(v View) {
|
func OpenMenu(m func()) {
|
||||||
ResetView()
|
ResetView()
|
||||||
defer ResetView()
|
defer ResetView()
|
||||||
v(g)
|
m()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Grid) ExpandView() {
|
func (g *Grid) ExpandView() {
|
||||||
@ -125,7 +123,7 @@ func (g *Grid) ExpandView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Display(g *Grid) bool {
|
func Display(g *Grid) bool {
|
||||||
var newView View
|
var menu func()
|
||||||
var expand bool
|
var expand bool
|
||||||
|
|
||||||
// calculate layout
|
// calculate layout
|
||||||
@ -144,11 +142,11 @@ func Display(g *Grid) bool {
|
|||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
ui.Handle("/sys/kbd/h", func(ui.Event) {
|
ui.Handle("/sys/kbd/h", func(ui.Event) {
|
||||||
newView = HelpMenu
|
menu = HelpMenu
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
ui.Handle("/sys/kbd/s", func(ui.Event) {
|
ui.Handle("/sys/kbd/s", func(ui.Event) {
|
||||||
newView = SortMenu
|
menu = SortMenu
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
@ -167,8 +165,8 @@ func Display(g *Grid) bool {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ui.Loop()
|
ui.Loop()
|
||||||
if newView != nil {
|
if menu != nil {
|
||||||
g.OpenView(newView)
|
OpenMenu(menu)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if expand {
|
if expand {
|
||||||
|
4
menus.go
4
menus.go
@ -11,7 +11,7 @@ var helpDialog = []string{
|
|||||||
"[q] - exit ctop",
|
"[q] - exit ctop",
|
||||||
}
|
}
|
||||||
|
|
||||||
func HelpMenu(g *Grid) {
|
func HelpMenu() {
|
||||||
m := widgets.NewMenu(helpDialog)
|
m := widgets.NewMenu(helpDialog)
|
||||||
m.TextFgColor = ui.ColorWhite
|
m.TextFgColor = ui.ColorWhite
|
||||||
m.BorderLabel = "Help"
|
m.BorderLabel = "Help"
|
||||||
@ -23,7 +23,7 @@ func HelpMenu(g *Grid) {
|
|||||||
ui.Loop()
|
ui.Loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func SortMenu(g *Grid) {
|
func SortMenu() {
|
||||||
m := widgets.NewMenu(SortFields)
|
m := widgets.NewMenu(SortFields)
|
||||||
m.Selectable = true
|
m.Selectable = true
|
||||||
m.TextFgColor = ui.ColorWhite
|
m.TextFgColor = ui.ColorWhite
|
||||||
|
Loading…
Reference in New Issue
Block a user