mostly working
This commit is contained in:
parent
ef2c76930f
commit
789643261f
@ -1,14 +1,14 @@
|
||||
package filetree
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"fmt"
|
||||
"github.com/phayes/permbits"
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/wagoodman/docker-image-explorer/_vendor-20180604210951/github.com/Microsoft/go-winio/archive/tar"
|
||||
"github.com/fatih/color"
|
||||
"github.com/phayes/permbits"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -32,7 +32,7 @@ func NewCommandView(name string, gui *gocui.Gui) (commandview *CommandView) {
|
||||
return commandview
|
||||
}
|
||||
|
||||
func (view *CommandView) Setup(v *gocui.View) error {
|
||||
func (view *CommandView) Setup(v *gocui.View, header *gocui.View) error {
|
||||
|
||||
// set view options
|
||||
view.view = v
|
||||
@ -80,8 +80,7 @@ func (view *CommandView) KeyHelp() string {
|
||||
|
||||
func (view *CommandView) Render() error {
|
||||
view.gui.Update(func(g *gocui.Gui) error {
|
||||
view.view.Clear()
|
||||
fmt.Fprintln(view.view, "Filter: ")
|
||||
fmt.Fprintln(view.view, "")
|
||||
|
||||
return nil
|
||||
})
|
||||
|
@ -4,9 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"strings"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
@ -108,12 +105,6 @@ func (view *FileTreeView) setLayer(layerIndex int) error {
|
||||
}
|
||||
view.ModelTree.VisitDepthChildFirst(visitor, nil)
|
||||
|
||||
if debug {
|
||||
v, _ := view.gui.View("debug")
|
||||
v.Clear()
|
||||
_, _ = fmt.Fprintln(v, view.RefTrees[layerIndex])
|
||||
}
|
||||
|
||||
view.view.SetCursor(0, 0)
|
||||
view.TreeIndex = 0
|
||||
view.ModelTree = newTree
|
||||
@ -197,31 +188,61 @@ func (view *FileTreeView) toggleShowDiffType(diffType filetree.DiffType) error {
|
||||
}
|
||||
|
||||
func filterRegex() *regexp.Regexp {
|
||||
debugPrint("Entered filterRegex()")
|
||||
if Views.Command == nil || Views.Command.view == nil {
|
||||
return nil
|
||||
}
|
||||
var filterBytes []byte
|
||||
read, err := Views.Command.view.Read(filterBytes)
|
||||
if read > 0 && err == nil {
|
||||
regex, err := regexp.Compile(string(filterBytes))
|
||||
if err == nil {
|
||||
filterString := strings.TrimSpace(Views.Command.view.Buffer())
|
||||
if len(filterString) < 1 {
|
||||
debugPrint(fmt.Sprintf("returing nil from fitlerRegex() because string is too short (%s)", filterString))
|
||||
return nil
|
||||
}
|
||||
|
||||
debugPrint("Compiling regex from " + filterString)
|
||||
regex, err := regexp.Compile(filterString)
|
||||
if err != nil {
|
||||
debugPrint("Returning nil from filterRegex")
|
||||
return nil
|
||||
}
|
||||
|
||||
return regex
|
||||
}
|
||||
|
||||
func debugPrint(s string) {
|
||||
if debug && Views.Tree != nil && Views.Tree.gui != nil {
|
||||
v, _ := Views.Tree.gui.View("debug")
|
||||
if v != nil {
|
||||
if len(v.ViewBuffer()) > 100 {
|
||||
v.Clear()
|
||||
}
|
||||
_, _ = fmt.Fprintln(v, s)
|
||||
}
|
||||
if read > 0 && err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (view *FileTreeView) updateViewTree() {
|
||||
regex := filterRegex()
|
||||
if regex == nil {
|
||||
debugPrint("Nil regex in updateViewTree()")
|
||||
}
|
||||
// keep the view selection in parity with the current DiffType selection
|
||||
view.ModelTree.VisitDepthChildFirst(func(node *filetree.FileNode) error {
|
||||
node.Data.ViewInfo.Hidden = view.HiddenDiffTypes[node.Data.DiffType]
|
||||
if regex != nil {
|
||||
match := regex.Find([]byte(node.Path()))
|
||||
node.Data.ViewInfo.Hidden = match != nil
|
||||
visibleChild := false
|
||||
for _, child := range node.Children {
|
||||
if !child.Data.ViewInfo.Hidden {
|
||||
visibleChild = true
|
||||
}
|
||||
}
|
||||
if regex != nil && !visibleChild {
|
||||
match := regex.FindString(node.Path())
|
||||
node.Data.ViewInfo.Hidden = len(match) == 0
|
||||
debugPrint(fmt.Sprintf("Not nil regex, match was %s", string(match)))
|
||||
if len(match) == 0 {
|
||||
debugPrint(fmt.Sprintf("Hiding '%s' because of failure to match /%v/", node.Path(), regex))
|
||||
} else {
|
||||
debugPrint(fmt.Sprintf("Showing '%s' because of matching /%v/", node.Path(), regex))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}, nil)
|
||||
|
6
ui/ui.go
6
ui/ui.go
@ -10,7 +10,7 @@ import (
|
||||
"github.com/wagoodman/docker-image-explorer/image"
|
||||
)
|
||||
|
||||
const debug = false
|
||||
const debug = true
|
||||
|
||||
var Formatting struct {
|
||||
Header func(...interface{}) string
|
||||
@ -45,12 +45,14 @@ func toggleView(g *gocui.Gui, v *gocui.View) error {
|
||||
}
|
||||
|
||||
func focusFilterView(g *gocui.Gui, v *gocui.View) error {
|
||||
debugPrint("focusFilterView()")
|
||||
_, err := g.SetCurrentView(Views.Command.Name)
|
||||
Render()
|
||||
return err
|
||||
}
|
||||
|
||||
func returnToTreeView(g *gocui.Gui, v *gocui.View) error {
|
||||
debugPrint("returnToTreeView()")
|
||||
_, err := g.SetCurrentView(Views.Tree.Name)
|
||||
Render()
|
||||
return err
|
||||
@ -177,7 +179,7 @@ func layout(g *gocui.Gui) error {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
Views.Command.Setup(view)
|
||||
Views.Command.Setup(view, nil)
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user