clear screen conditionally

This commit is contained in:
Bradley Cicenas 2017-03-08 11:10:38 +11:00
parent b8eb386360
commit bf4d59c251
3 changed files with 23 additions and 12 deletions

View File

@ -19,11 +19,17 @@ func NewGridCursor() *GridCursor {
func (gc *GridCursor) Len() int { return len(gc.containers) } func (gc *GridCursor) Len() int { return len(gc.containers) }
func (gc *GridCursor) Selected() *Container { return gc.containers[gc.Idx()] } func (gc *GridCursor) Selected() *Container { return gc.containers[gc.Idx()] }
func (gc *GridCursor) RefreshContainers() { // Refresh containers from source
func (gc *GridCursor) RefreshContainers() (lenChanged bool) {
oldLen := gc.Len()
gc.containers = gc.cSource.All().Filter() gc.containers = gc.cSource.All().Filter()
if oldLen != gc.Len() {
lenChanged = true
}
if gc.selectedID == "" { if gc.selectedID == "" {
gc.Reset() gc.Reset()
} }
return lenChanged
} }
// Set an initial cursor position, if possible // Set an initial cursor position, if possible

24
grid.go
View File

@ -10,7 +10,7 @@ func maxRows() int {
return ui.TermHeight() - 2 - cGrid.Y return ui.TermHeight() - 2 - cGrid.Y
} }
func RedrawRows() { func RedrawRows(clr bool) {
// reinit body rows // reinit body rows
cGrid.Clear() cGrid.Clear()
@ -39,7 +39,10 @@ func RedrawRows() {
cursor.Reset() cursor.Reset()
} }
ui.Clear() if clr {
ui.Clear()
log.Debugf("screen cleared")
}
if config.GetSwitchVal("enableHeader") { if config.GetSwitchVal("enableHeader") {
header.Render() header.Render()
} }
@ -73,6 +76,11 @@ func ExpandView(c *Container) {
c.SetUpdater(c.Widgets) c.SetUpdater(c.Widgets)
} }
func RefreshDisplay() {
needsClear := cursor.RefreshContainers()
RedrawRows(needsClear)
}
func Display() bool { func Display() bool {
var menu func() var menu func()
var expand bool var expand bool
@ -83,7 +91,7 @@ func Display() bool {
// initial draw // initial draw
header.Align() header.Align()
cursor.RefreshContainers() cursor.RefreshContainers()
RedrawRows() RedrawRows(true)
ui.Handle("/sys/kbd/<up>", func(ui.Event) { ui.Handle("/sys/kbd/<up>", func(ui.Event) {
cursor.Up() cursor.Up()
@ -98,8 +106,7 @@ func Display() bool {
ui.Handle("/sys/kbd/a", func(ui.Event) { ui.Handle("/sys/kbd/a", func(ui.Event) {
config.Toggle("allContainers") config.Toggle("allContainers")
cursor.RefreshContainers() RefreshDisplay()
RedrawRows()
}) })
ui.Handle("/sys/kbd/D", func(ui.Event) { ui.Handle("/sys/kbd/D", func(ui.Event) {
dumpContainer(cursor.Selected()) dumpContainer(cursor.Selected())
@ -114,7 +121,7 @@ func Display() bool {
}) })
ui.Handle("/sys/kbd/H", func(ui.Event) { ui.Handle("/sys/kbd/H", func(ui.Event) {
config.Toggle("enableHeader") config.Toggle("enableHeader")
RedrawRows() RedrawRows(true)
}) })
ui.Handle("/sys/kbd/q", func(ui.Event) { ui.Handle("/sys/kbd/q", func(ui.Event) {
ui.StopLoop() ui.StopLoop()
@ -128,15 +135,14 @@ func Display() bool {
}) })
ui.Handle("/timer/1s", func(e ui.Event) { ui.Handle("/timer/1s", func(e ui.Event) {
cursor.RefreshContainers() RefreshDisplay()
RedrawRows()
}) })
ui.Handle("/sys/wnd/resize", func(e ui.Event) { ui.Handle("/sys/wnd/resize", func(e ui.Event) {
header.Align() header.Align()
cGrid.SetWidth(ui.TermWidth()) cGrid.SetWidth(ui.TermWidth())
log.Infof("resize: width=%v max-rows=%v", cGrid.Width, maxRows()) log.Infof("resize: width=%v max-rows=%v", cGrid.Width, maxRows())
RedrawRows() RedrawRows(true)
}) })
ui.Loop() ui.Loop()

View File

@ -46,8 +46,7 @@ func FilterMenu() {
go func() { go func() {
for s := range stream { for s := range stream {
config.Update("filterStr", s) config.Update("filterStr", s)
cursor.RefreshContainers() RefreshDisplay()
RedrawRows()
ui.Render(i) ui.Render(i)
} }
}() }()