add regex name filter to containermap

This commit is contained in:
Bradley Cicenas 2017-01-23 15:00:33 +00:00
parent 6db32bad56
commit 59eafdbb4f
4 changed files with 12 additions and 1 deletions

View File

@ -34,6 +34,7 @@ func NewDefaultConfig() Config {
}
config := Config{
"dockerHost": docker,
"filterStr": "",
"sortField": "id",
"sortReverse": "0",
"enableHeader": "0",

View File

@ -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
}

View File

@ -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" {

View File

@ -32,6 +32,7 @@ func FilterMenu() {
ui.Render(i)
i.InputHandlers()
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
updateConfig("filterStr", i.Data)
ui.StopLoop()
})
ui.Loop()