mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
fix cursor highlighting for newly filtered containers
This commit is contained in:
parent
2d2d58d47f
commit
d7f9f715bb
30
cursor.go
30
cursor.go
@ -6,6 +6,7 @@ import (
|
||||
|
||||
type GridCursor struct {
|
||||
selectedID string // id of currently selected container
|
||||
filtered Containers
|
||||
containers Containers
|
||||
cSource ContainerSource
|
||||
}
|
||||
@ -16,24 +17,13 @@ func NewGridCursor() *GridCursor {
|
||||
}
|
||||
}
|
||||
|
||||
func (gc *GridCursor) Len() int { return len(gc.Filtered()) }
|
||||
func (gc *GridCursor) Len() int { return len(gc.filtered) }
|
||||
func (gc *GridCursor) Selected() *Container { return gc.containers[gc.Idx()] }
|
||||
|
||||
// Return Containers filtered by display bool
|
||||
func (gc *GridCursor) Filtered() Containers {
|
||||
var filtered Containers
|
||||
for _, c := range gc.containers {
|
||||
if c.display {
|
||||
filtered = append(filtered, c)
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
// Refresh containers from source
|
||||
func (gc *GridCursor) RefreshContainers() (lenChanged bool) {
|
||||
oldLen := gc.Len()
|
||||
gc.containers = gc.cSource.All()
|
||||
gc.setContainers(gc.cSource.All())
|
||||
if oldLen != gc.Len() {
|
||||
lenChanged = true
|
||||
}
|
||||
@ -43,8 +33,22 @@ func (gc *GridCursor) RefreshContainers() (lenChanged bool) {
|
||||
return lenChanged
|
||||
}
|
||||
|
||||
func (gc *GridCursor) setContainers(c Containers) {
|
||||
gc.containers = c
|
||||
// Containers filtered by display bool
|
||||
gc.filtered = Containers{}
|
||||
for _, c := range gc.containers {
|
||||
if c.display {
|
||||
gc.filtered = append(gc.filtered, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set an initial cursor position, if possible
|
||||
func (gc *GridCursor) Reset() {
|
||||
for _, c := range gc.containers {
|
||||
c.Widgets.Name.UnHighlight()
|
||||
}
|
||||
if gc.Len() > 0 {
|
||||
gc.selectedID = gc.containers[0].Id
|
||||
gc.containers[0].Widgets.Name.Highlight()
|
||||
|
Loading…
Reference in New Issue
Block a user