start adding search bar
This commit is contained in:
parent
90c86234c4
commit
348e88e70b
94
ui/commandview.go
Normal file
94
ui/commandview.go
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/jroimartin/gocui"
|
||||||
|
)
|
||||||
|
|
||||||
|
// with special thanks to https://gist.github.com/jroimartin/3b2e943a3811d795e0718b4a95b89bec
|
||||||
|
|
||||||
|
type CommandView struct {
|
||||||
|
Name string
|
||||||
|
gui *gocui.Gui
|
||||||
|
view *gocui.View
|
||||||
|
maxLength int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Input struct {
|
||||||
|
name string
|
||||||
|
x, y int
|
||||||
|
w int
|
||||||
|
maxLength int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCommandView(name string, gui *gocui.Gui) (commandview *CommandView) {
|
||||||
|
commandview = new(CommandView)
|
||||||
|
|
||||||
|
// populate main fields
|
||||||
|
commandview.Name = name
|
||||||
|
commandview.gui = gui
|
||||||
|
|
||||||
|
return commandview
|
||||||
|
}
|
||||||
|
|
||||||
|
func (view *CommandView) Setup(v *gocui.View) error {
|
||||||
|
|
||||||
|
// set view options
|
||||||
|
view.view = v
|
||||||
|
view.view.Frame = false
|
||||||
|
view.view.BgColor = gocui.ColorDefault + gocui.AttrReverse
|
||||||
|
|
||||||
|
// set keybindings
|
||||||
|
// if err := view.gui.SetKeybinding(view.Name, gocui.KeyArrowDown, gocui.ModNone, func(*gocui.Gui, *gocui.View) error { return view.CursorDown() }); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// if err := view.gui.SetKeybinding(view.Name, gocui.KeyArrowUp, gocui.ModNone, func(*gocui.Gui, *gocui.View) error { return view.CursorUp() }); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
|
||||||
|
view.Render()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (view *CommandView) CursorDown() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (view *CommandView) CursorUp() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *CommandView) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
|
||||||
|
cx, _ := v.Cursor()
|
||||||
|
ox, _ := v.Origin()
|
||||||
|
limit := ox+cx+1 > i.maxLength
|
||||||
|
switch {
|
||||||
|
case ch != 0 && mod == 0 && !limit:
|
||||||
|
v.EditWrite(ch)
|
||||||
|
case key == gocui.KeySpace && !limit:
|
||||||
|
v.EditWrite(' ')
|
||||||
|
case key == gocui.KeyBackspace || key == gocui.KeyBackspace2:
|
||||||
|
v.EditDelete(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (view *CommandView) KeyHelp() string {
|
||||||
|
control := color.New(color.Bold).SprintFunc()
|
||||||
|
return control("[^C]") + ": Quit " +
|
||||||
|
control("[^Space]") + ": Switch View "
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (view *CommandView) Render() error {
|
||||||
|
view.gui.Update(func(g *gocui.Gui) error {
|
||||||
|
view.view.Clear()
|
||||||
|
fmt.Fprintln(view.view, "Filter: ")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
// todo: blerg
|
||||||
|
return nil
|
||||||
|
}
|
@ -4,10 +4,11 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
"github.com/jroimartin/gocui"
|
"github.com/jroimartin/gocui"
|
||||||
"github.com/wagoodman/docker-image-explorer/filetree"
|
"github.com/wagoodman/docker-image-explorer/filetree"
|
||||||
"github.com/fatih/color"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileTreeView struct {
|
type FileTreeView struct {
|
||||||
@ -67,6 +68,9 @@ func (view *FileTreeView) Setup(v *gocui.View) error {
|
|||||||
if err := view.gui.SetKeybinding(view.Name, gocui.KeyCtrlU, gocui.ModNone, func(*gocui.Gui, *gocui.View) error { return view.toggleShowDiffType(filetree.Unchanged) }); err != nil {
|
if err := view.gui.SetKeybinding(view.Name, gocui.KeyCtrlU, gocui.ModNone, func(*gocui.Gui, *gocui.View) error { return view.toggleShowDiffType(filetree.Unchanged) }); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := view.gui.SetKeybinding(view.Name, gocui.KeyCtrlSlash, gocui.ModNone, func(*gocui.Gui, *gocui.View) error { return nil }); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
view.updateViewTree()
|
view.updateViewTree()
|
||||||
view.Render()
|
view.Render()
|
||||||
@ -97,7 +101,6 @@ func (view *FileTreeView) setLayer(layerIndex int) error {
|
|||||||
_, _ = fmt.Fprintln(v, view.RefTrees[layerIndex])
|
_, _ = fmt.Fprintln(v, view.RefTrees[layerIndex])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
view.view.SetCursor(0, 0)
|
view.view.SetCursor(0, 0)
|
||||||
view.TreeIndex = 0
|
view.TreeIndex = 0
|
||||||
view.ModelTree = newTree
|
view.ModelTree = newTree
|
||||||
@ -186,11 +189,11 @@ func (view *FileTreeView) updateViewTree() {
|
|||||||
|
|
||||||
func (view *FileTreeView) KeyHelp() string {
|
func (view *FileTreeView) KeyHelp() string {
|
||||||
control := color.New(color.Bold).SprintFunc()
|
control := color.New(color.Bold).SprintFunc()
|
||||||
return control("[Space]") + ": Collapse dir " +
|
return control("[Space]") + ": Collapse dir " +
|
||||||
control("[^A]") + ": Added files " +
|
control("[^A]") + ": Added files " +
|
||||||
control("[^R]") + ": Removed files " +
|
control("[^R]") + ": Removed files " +
|
||||||
control("[^M]") + ": Modified files " +
|
control("[^M]") + ": Modified files " +
|
||||||
control("[^U]") + ": Unmodified files"
|
control("[^U]") + ": Unmodified files"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (view *FileTreeView) Render() error {
|
func (view *FileTreeView) Render() error {
|
||||||
|
@ -3,8 +3,8 @@ package ui
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jroimartin/gocui"
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
|
"github.com/jroimartin/gocui"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StatusView struct {
|
type StatusView struct {
|
||||||
@ -43,7 +43,6 @@ func (view *StatusView) Setup(v *gocui.View) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (view *StatusView) CursorDown() error {
|
func (view *StatusView) CursorDown() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -54,15 +53,16 @@ func (view *StatusView) CursorUp() error {
|
|||||||
|
|
||||||
func (view *StatusView) KeyHelp() string {
|
func (view *StatusView) KeyHelp() string {
|
||||||
control := color.New(color.Bold).SprintFunc()
|
control := color.New(color.Bold).SprintFunc()
|
||||||
return control("[^C]") + ": Quit " +
|
return control("[^C]") + ": Quit " +
|
||||||
control("[^Space]") + ": Switch View "
|
control("[^Space]") + ": Switch View " +
|
||||||
|
control("[^/]") + ": Filter files"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (view *StatusView) Render() error {
|
func (view *StatusView) Render() error {
|
||||||
view.gui.Update(func(g *gocui.Gui) error {
|
view.gui.Update(func(g *gocui.Gui) error {
|
||||||
view.view.Clear()
|
view.view.Clear()
|
||||||
fmt.Fprintln(view.view, view.KeyHelp() + " | " + Views.lookup[view.gui.CurrentView().Name()].KeyHelp())
|
fmt.Fprintln(view.view, view.KeyHelp()+" | "+Views.lookup[view.gui.CurrentView().Name()].KeyHelp())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
26
ui/ui.go
26
ui/ui.go
@ -3,23 +3,24 @@ package ui
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
"github.com/jroimartin/gocui"
|
"github.com/jroimartin/gocui"
|
||||||
"github.com/wagoodman/docker-image-explorer/filetree"
|
"github.com/wagoodman/docker-image-explorer/filetree"
|
||||||
"github.com/wagoodman/docker-image-explorer/image"
|
"github.com/wagoodman/docker-image-explorer/image"
|
||||||
"github.com/fatih/color"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const debug = false
|
const debug = false
|
||||||
|
|
||||||
var Formatting struct {
|
var Formatting struct {
|
||||||
Header func(...interface{})(string)
|
Header func(...interface{}) string
|
||||||
}
|
}
|
||||||
|
|
||||||
var Views struct {
|
var Views struct {
|
||||||
Tree *FileTreeView
|
Tree *FileTreeView
|
||||||
Layer *LayerView
|
Layer *LayerView
|
||||||
Status *StatusView
|
Status *StatusView
|
||||||
lookup map[string]View
|
Command *CommandView
|
||||||
|
lookup map[string]View
|
||||||
}
|
}
|
||||||
|
|
||||||
type View interface {
|
type View interface {
|
||||||
@ -89,6 +90,9 @@ func keybindings(g *gocui.Gui) error {
|
|||||||
if err := g.SetKeybinding("main", gocui.KeyCtrlSpace, gocui.ModNone, toggleView); err != nil {
|
if err := g.SetKeybinding("main", gocui.KeyCtrlSpace, gocui.ModNone, toggleView); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := g.SetKeybinding("command", gocui.KeyCtrlSlash, gocui.ModNone, toggleView); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -133,6 +137,13 @@ func layout(g *gocui.Gui) error {
|
|||||||
}
|
}
|
||||||
Views.Status.Setup(view)
|
Views.Status.Setup(view)
|
||||||
|
|
||||||
|
}
|
||||||
|
if view, err := g.SetView(Views.Command.Name, -1, maxY-bottomRows-2, maxX, maxY-1); err != nil {
|
||||||
|
if err != gocui.ErrUnknownView {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
Views.Command.Setup(view)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -164,6 +175,9 @@ func Run(layers []*image.Layer, refTrees []*filetree.FileTree) {
|
|||||||
Views.Status = NewStatusView("status", g)
|
Views.Status = NewStatusView("status", g)
|
||||||
Views.lookup[Views.Status.Name] = Views.Status
|
Views.lookup[Views.Status.Name] = Views.Status
|
||||||
|
|
||||||
|
Views.Command = NewCommandView("command", g)
|
||||||
|
Views.lookup[Views.Command.Name] = Views.Command
|
||||||
|
|
||||||
g.Cursor = false
|
g.Cursor = false
|
||||||
//g.Mouse = true
|
//g.Mouse = true
|
||||||
g.SetManagerFunc(layout)
|
g.SetManagerFunc(layout)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user