From 59eafdbb4f6939c81571d292f45f807e5833b5d5 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Mon, 23 Jan 2017 15:00:33 +0000 Subject: [PATCH] add regex name filter to containermap --- config.go | 1 + containermap.go | 10 +++++++++- grid.go | 1 + menus.go | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index cee4b32..26b2b09 100644 --- a/config.go +++ b/config.go @@ -34,6 +34,7 @@ func NewDefaultConfig() Config { } config := Config{ "dockerHost": docker, + "filterStr": "", "sortField": "id", "sortReverse": "0", "enableHeader": "0", diff --git a/containermap.go b/containermap.go index 68a76ce..1e2378b 100644 --- a/containermap.go +++ b/containermap.go @@ -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 } diff --git a/grid.go b/grid.go index f611507..463d784 100644 --- a/grid.go +++ b/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" { diff --git a/menus.go b/menus.go index 527670a..d97bb83 100644 --- a/menus.go +++ b/menus.go @@ -32,6 +32,7 @@ func FilterMenu() { ui.Render(i) i.InputHandlers() ui.Handle("/sys/kbd/", func(ui.Event) { + updateConfig("filterStr", i.Data) ui.StopLoop() }) ui.Loop()