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{
|
||||
"dockerHost": docker,
|
||||
"filterStr": "",
|
||||
"sortField": "id",
|
||||
"sortReverse": "0",
|
||||
"enableHeader": "0",
|
||||
|
@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@ -79,9 +81,15 @@ func (cm *ContainerMap) Get(id string) *Container {
|
||||
// Return array of all containers, sorted by field
|
||||
func (cm *ContainerMap) All() []*Container {
|
||||
var containers Containers
|
||||
filter := GlobalConfig["filterStr"]
|
||||
re := regexp.MustCompile(fmt.Sprintf(".*%s", filter))
|
||||
|
||||
for _, c := range cm.containers {
|
||||
containers = append(containers, c)
|
||||
if re.FindAllString(c.name, 1) != nil {
|
||||
containers = append(containers, c)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(containers)
|
||||
return containers
|
||||
}
|
||||
|
1
grid.go
1
grid.go
@ -68,6 +68,7 @@ func (g *Grid) redrawCursor() {
|
||||
func (g *Grid) redrawRows() {
|
||||
// reinit body rows
|
||||
ui.Body.Rows = []*ui.Row{}
|
||||
ui.Clear()
|
||||
|
||||
// build layout
|
||||
if GlobalConfig["enableHeader"] == "1" {
|
||||
|
Loading…
Reference in New Issue
Block a user