Skip to content

Commit

Permalink
using keybinding lib
Browse files Browse the repository at this point in the history
  • Loading branch information
wagoodman committed Dec 15, 2018
1 parent 8b4c302 commit 1abb210
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 279 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ require (
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/mattn/go-runewidth v0.0.3 // indirect
github.com/mitchellh/go-homedir v1.0.0
github.com/nsf/termbox-go v0.0.0-20181027232701-60ab7e3d12ed // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/phayes/permbits v0.0.0-20180830030258-59f2482cd460
github.com/pkg/errors v0.8.0 // indirect
github.com/sirupsen/logrus v1.2.0
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.2.1
github.com/wagoodman/keybinding v0.0.0-20181213133715-6a824da6df05
golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869 // indirect
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ github.com/spf13/viper v1.2.1/go.mod h1:P4AexN0a+C9tGAnUFNwDMYYZv3pjFuvmeiMyKRaN
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/wagoodman/keybinding v0.0.0-20181213133715-6a824da6df05 h1:YMcRwVDe8DLDZ/vrhuImCfqjjG/+gZs6SF61DDQkL/8=
github.com/wagoodman/keybinding v0.0.0-20181213133715-6a824da6df05/go.mod h1:gXFkc2sM2o06uzn5Lgo6Ql76uweGdxNfeAlFyKiHAdk=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869 h1:kkXA53yGe04D0adEYJwEVQjeBppL01Exg+fnMjfUraU=
golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
72 changes: 51 additions & 21 deletions ui/filetreeview.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/wagoodman/dive/utils"
"github.com/wagoodman/keybinding"
"log"
"regexp"
"strings"

Expand Down Expand Up @@ -37,13 +39,13 @@ type FileTreeView struct {
bufferIndexUpperBound uint
bufferIndexLowerBound uint

keybindingToggleCollapse []Key
keybindingToggleAdded []Key
keybindingToggleRemoved []Key
keybindingToggleModified []Key
keybindingToggleUnchanged []Key
keybindingPageDown []Key
keybindingPageUp []Key
keybindingToggleCollapse []keybinding.Key
keybindingToggleAdded []keybinding.Key
keybindingToggleRemoved []keybinding.Key
keybindingToggleModified []keybinding.Key
keybindingToggleUnchanged []keybinding.Key
keybindingPageDown []keybinding.Key
keybindingPageUp []keybinding.Key
}

// NewFileTreeView creates a new view object attached the the global [gocui] screen object.
Expand Down Expand Up @@ -74,13 +76,41 @@ func NewFileTreeView(name string, gui *gocui.Gui, tree *filetree.FileTree, refTr
}
}

treeView.keybindingToggleCollapse = getKeybindings(viper.GetString("keybinding.toggle-collapse-dir"))
treeView.keybindingToggleAdded = getKeybindings(viper.GetString("keybinding.toggle-added-files"))
treeView.keybindingToggleRemoved = getKeybindings(viper.GetString("keybinding.toggle-removed-files"))
treeView.keybindingToggleModified = getKeybindings(viper.GetString("keybinding.toggle-modified-files"))
treeView.keybindingToggleUnchanged = getKeybindings(viper.GetString("keybinding.toggle-unchanged-files"))
treeView.keybindingPageUp = getKeybindings(viper.GetString("keybinding.page-up"))
treeView.keybindingPageDown = getKeybindings(viper.GetString("keybinding.page-down"))
var err error
treeView.keybindingToggleCollapse, err = keybinding.ParseAll(viper.GetString("keybinding.toggle-collapse-dir"))
if err != nil {
log.Panicln(err)
}

treeView.keybindingToggleAdded, err = keybinding.ParseAll(viper.GetString("keybinding.toggle-added-files"))
if err != nil {
log.Panicln(err)
}

treeView.keybindingToggleRemoved, err = keybinding.ParseAll(viper.GetString("keybinding.toggle-removed-files"))
if err != nil {
log.Panicln(err)
}

treeView.keybindingToggleModified, err = keybinding.ParseAll(viper.GetString("keybinding.toggle-modified-files"))
if err != nil {
log.Panicln(err)
}

treeView.keybindingToggleUnchanged, err = keybinding.ParseAll(viper.GetString("keybinding.toggle-unchanged-files"))
if err != nil {
log.Panicln(err)
}

treeView.keybindingPageUp, err = keybinding.ParseAll(viper.GetString("keybinding.page-up"))
if err != nil {
log.Panicln(err)
}

treeView.keybindingPageDown, err = keybinding.ParseAll(viper.GetString("keybinding.page-down"))
if err != nil {
log.Panicln(err)
}

return treeView
}
Expand Down Expand Up @@ -114,37 +144,37 @@ func (view *FileTreeView) Setup(v *gocui.View, header *gocui.View) error {
}

for _, key := range view.keybindingPageUp {
if err := view.gui.SetKeybinding(view.Name, key.value, key.modifier, func(*gocui.Gui, *gocui.View) error { return view.PageUp() }); err != nil {
if err := view.gui.SetKeybinding(view.Name, key.Value, key.Modifier, func(*gocui.Gui, *gocui.View) error { return view.PageUp() }); err != nil {
return err
}
}
for _, key := range view.keybindingPageDown {
if err := view.gui.SetKeybinding(view.Name, key.value, key.modifier, func(*gocui.Gui, *gocui.View) error { return view.PageDown() }); err != nil {
if err := view.gui.SetKeybinding(view.Name, key.Value, key.Modifier, func(*gocui.Gui, *gocui.View) error { return view.PageDown() }); err != nil {
return err
}
}
for _, key := range view.keybindingToggleCollapse {
if err := view.gui.SetKeybinding(view.Name, key.value, key.modifier, func(*gocui.Gui, *gocui.View) error { return view.toggleCollapse() }); err != nil {
if err := view.gui.SetKeybinding(view.Name, key.Value, key.Modifier, func(*gocui.Gui, *gocui.View) error { return view.toggleCollapse() }); err != nil {
return err
}
}
for _, key := range view.keybindingToggleAdded {
if err := view.gui.SetKeybinding(view.Name, key.value, key.modifier, func(*gocui.Gui, *gocui.View) error { return view.toggleShowDiffType(filetree.Added) }); err != nil {
if err := view.gui.SetKeybinding(view.Name, key.Value, key.Modifier, func(*gocui.Gui, *gocui.View) error { return view.toggleShowDiffType(filetree.Added) }); err != nil {
return err
}
}
for _, key := range view.keybindingToggleRemoved {
if err := view.gui.SetKeybinding(view.Name, key.value, key.modifier, func(*gocui.Gui, *gocui.View) error { return view.toggleShowDiffType(filetree.Removed) }); err != nil {
if err := view.gui.SetKeybinding(view.Name, key.Value, key.Modifier, func(*gocui.Gui, *gocui.View) error { return view.toggleShowDiffType(filetree.Removed) }); err != nil {
return err
}
}
for _, key := range view.keybindingToggleModified {
if err := view.gui.SetKeybinding(view.Name, key.value, key.modifier, func(*gocui.Gui, *gocui.View) error { return view.toggleShowDiffType(filetree.Changed) }); err != nil {
if err := view.gui.SetKeybinding(view.Name, key.Value, key.Modifier, func(*gocui.Gui, *gocui.View) error { return view.toggleShowDiffType(filetree.Changed) }); err != nil {
return err
}
}
for _, key := range view.keybindingToggleUnchanged {
if err := view.gui.SetKeybinding(view.Name, key.value, key.modifier, func(*gocui.Gui, *gocui.View) error { return view.toggleShowDiffType(filetree.Unchanged) }); err != nil {
if err := view.gui.SetKeybinding(view.Name, key.Value, key.Modifier, func(*gocui.Gui, *gocui.View) error { return view.toggleShowDiffType(filetree.Unchanged) }); err != nil {
return err
}
}
Expand Down
186 changes: 0 additions & 186 deletions ui/keybinding.go

This file was deleted.

55 changes: 0 additions & 55 deletions ui/keybinding_test.go

This file was deleted.

Loading

0 comments on commit 1abb210

Please sign in to comment.