mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
add regex name filter to containermap
This commit is contained in:
parent
6db32bad56
commit
59eafdbb4f
@ -34,6 +34,7 @@ func NewDefaultConfig() Config {
|
|||||||
}
|
}
|
||||||
config := Config{
|
config := Config{
|
||||||
"dockerHost": docker,
|
"dockerHost": docker,
|
||||||
|
"filterStr": "",
|
||||||
"sortField": "id",
|
"sortField": "id",
|
||||||
"sortReverse": "0",
|
"sortReverse": "0",
|
||||||
"enableHeader": "0",
|
"enableHeader": "0",
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -79,9 +81,15 @@ func (cm *ContainerMap) Get(id string) *Container {
|
|||||||
// Return array of all containers, sorted by field
|
// Return array of all containers, sorted by field
|
||||||
func (cm *ContainerMap) All() []*Container {
|
func (cm *ContainerMap) All() []*Container {
|
||||||
var containers Containers
|
var containers Containers
|
||||||
|
filter := GlobalConfig["filterStr"]
|
||||||
|
re := regexp.MustCompile(fmt.Sprintf(".*%s", filter))
|
||||||
|
|
||||||
for _, c := range cm.containers {
|
for _, c := range cm.containers {
|
||||||
|
if re.FindAllString(c.name, 1) != nil {
|
||||||
containers = append(containers, c)
|
containers = append(containers, c)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sort.Sort(containers)
|
sort.Sort(containers)
|
||||||
return containers
|
return containers
|
||||||
}
|
}
|
||||||
|
1
grid.go
1
grid.go
@ -68,6 +68,7 @@ func (g *Grid) redrawCursor() {
|
|||||||
func (g *Grid) redrawRows() {
|
func (g *Grid) redrawRows() {
|
||||||
// reinit body rows
|
// reinit body rows
|
||||||
ui.Body.Rows = []*ui.Row{}
|
ui.Body.Rows = []*ui.Row{}
|
||||||
|
ui.Clear()
|
||||||
|
|
||||||
// build layout
|
// build layout
|
||||||
if GlobalConfig["enableHeader"] == "1" {
|
if GlobalConfig["enableHeader"] == "1" {
|
||||||
|
1
menus.go
1
menus.go
@ -32,6 +32,7 @@ func FilterMenu() {
|
|||||||
ui.Render(i)
|
ui.Render(i)
|
||||||
i.InputHandlers()
|
i.InputHandlers()
|
||||||
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
||||||
|
updateConfig("filterStr", i.Data)
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
ui.Loop()
|
ui.Loop()
|
||||||
|
Loading…
Reference in New Issue
Block a user