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 {
|
type GridCursor struct {
|
||||||
selectedID string // id of currently selected container
|
selectedID string // id of currently selected container
|
||||||
|
filtered Containers
|
||||||
containers Containers
|
containers Containers
|
||||||
cSource ContainerSource
|
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()] }
|
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
|
// Refresh containers from source
|
||||||
func (gc *GridCursor) RefreshContainers() (lenChanged bool) {
|
func (gc *GridCursor) RefreshContainers() (lenChanged bool) {
|
||||||
oldLen := gc.Len()
|
oldLen := gc.Len()
|
||||||
gc.containers = gc.cSource.All()
|
gc.setContainers(gc.cSource.All())
|
||||||
if oldLen != gc.Len() {
|
if oldLen != gc.Len() {
|
||||||
lenChanged = true
|
lenChanged = true
|
||||||
}
|
}
|
||||||
@ -43,8 +33,22 @@ func (gc *GridCursor) RefreshContainers() (lenChanged bool) {
|
|||||||
return lenChanged
|
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
|
// Set an initial cursor position, if possible
|
||||||
func (gc *GridCursor) Reset() {
|
func (gc *GridCursor) Reset() {
|
||||||
|
for _, c := range gc.containers {
|
||||||
|
c.Widgets.Name.UnHighlight()
|
||||||
|
}
|
||||||
if gc.Len() > 0 {
|
if gc.Len() > 0 {
|
||||||
gc.selectedID = gc.containers[0].Id
|
gc.selectedID = gc.containers[0].Id
|
||||||
gc.containers[0].Widgets.Name.Highlight()
|
gc.containers[0].Widgets.Name.Highlight()
|
||||||
|
Loading…
Reference in New Issue
Block a user