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{ config := Config{
"dockerHost": docker, "dockerHost": docker,
"filterStr": "",
"sortField": "id", "sortField": "id",
"sortReverse": "0", "sortReverse": "0",
"enableHeader": "0", "enableHeader": "0",

View File

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

View File

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

View File

@ -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()