summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordwillist <dthornton@vmware.com>2021-01-22 14:07:16 -0500
committerdwillist <dthornton@vmware.com>2021-01-22 14:07:16 -0500
commit95387df56f4798902768be3b3893cfb524c294d7 (patch)
tree444d36769b86c9e02e21c58152cf17afa2b13ecb
parent43c0b96bac08eec89875962c8f2a6da52f2a1a97 (diff)
update keybinding display to not carry and state
Signed-off-by: dwillist <dthornton@vmware.com>
-rw-r--r--runtime/ui/app.go6
-rw-r--r--runtime/ui/components/app_config.go44
-rw-r--r--runtime/ui/components/dive_application.go3
-rw-r--r--runtime/ui/components/filetree_primative.go175
-rw-r--r--runtime/ui/components/key_config.go42
-rw-r--r--runtime/ui/components/keybinding_primitive.go4
-rw-r--r--runtime/ui/components/layers_primative.go77
-rw-r--r--runtime/ui/components/visible_grid.go2
-rw-r--r--runtime/ui/format/format.go6
-rw-r--r--runtime/ui/viewmodels/tree_view_model.go6
-rw-r--r--runtime/ui/viewmodels/tree_view_model_test.go5
11 files changed, 267 insertions, 103 deletions
diff --git a/runtime/ui/app.go b/runtime/ui/app.go
index 3d83a21..37a3de4 100644
--- a/runtime/ui/app.go
+++ b/runtime/ui/app.go
@@ -34,6 +34,7 @@ func newApp(app *tview.Application, analysis *image.AnalysisResult, cache filetr
format.SyncWithTermColors()
config := components.NewKeyConfig()
+ appConfig := components.AppConfig{}
diveApplication := components.NewDiveApplication(app)
//initialize viewmodels
@@ -90,8 +91,9 @@ func newApp(app *tview.Application, analysis *image.AnalysisResult, cache filetr
AddItem(filterView, 1, 0, false).
SetConsumers(filterView, fileTreeBox)
- totalVisibleGrid.AddItem(leftVisibleGrid, 0, 1, true).
- AddItem(rightVisibleGrid, 0, 1, false)
+ leftPortion, rightPortion := appConfig.GetPaneWidth()
+ totalVisibleGrid.AddItem(leftVisibleGrid, 0, leftPortion, true).
+ AddItem(rightVisibleGrid, 0, rightPortion, false)
uiSingleton = &UI{
app: diveApplication,
diff --git a/runtime/ui/components/app_config.go b/runtime/ui/components/app_config.go
new file mode 100644
index 0000000..02b568c
--- /dev/null
+++ b/runtime/ui/components/app_config.go
@@ -0,0 +1,44 @@
+package components
+
+import (
+ "github.com/spf13/viper"
+ "github.com/wagoodman/dive/dive/filetree"
+)
+
+type AppConfig struct {}
+
+func (a *AppConfig) GetDefaultHide() (result []filetree.DiffType) {
+ slice := viper.GetStringSlice("diff.hide")
+ for _, hideType := range slice {
+ switch hideType{
+ case "added":
+ result = append(result, filetree.Added)
+ case "removed":
+ result = append(result, filetree.Removed)
+ case "modified":
+ result = append(result, filetree.Modified)
+ case "unmodified":
+ result = append(result, filetree.Unmodified)
+ }
+ }
+
+ return result
+}
+
+func (a *AppConfig) GetAggregateLayerSetting() bool {
+ return viper.GetBool("layer.show-aggregated-changes")
+}
+
+func (a *AppConfig) GetCollapseDir() bool {
+ return viper.GetBool("filetree.collapse-dir")
+}
+
+func (a *AppConfig) GetPaneWidth() (int,int) {
+ fwp := viper.GetFloat64("filetree.pane-width")
+ lwp := 1 - fwp
+ return int(fwp*100), int(lwp*100)
+}
+
+func (a *AppConfig) GetShowAttributes() bool {
+ return viper.GetBool("filetree.show-attributes")
+}
diff --git a/runtime/ui/components/dive_application.go b/runtime/ui/components/dive_application.go
index 8f129b3..01e8f5d 100644
--- a/runtime/ui/components/dive_application.go
+++ b/runtime/ui/components/dive_application.go
@@ -12,7 +12,6 @@ type DiveApplication struct {
boundList []BoundView
- // todo remove this
bindings []KeyBinding
}
@@ -28,7 +27,7 @@ func (d *DiveApplication) GetKeyBindings() []KeyBindingDisplay {
for i := 0; i < len(d.bindings); i++ {
binding := d.bindings[i]
logrus.Debug(fmt.Sprintf("adding keybinding with name %s", binding.Display))
- result = append(result, KeyBindingDisplay{KeyBinding: &binding, Selected: false})
+ result = append(result, KeyBindingDisplay{KeyBinding: &binding, Selected: AlwaysFalse, Hide: AlwaysFalse})
}
for _, bound := range d.boundList {
diff --git a/runtime/ui/components/filetree_primative.go b/runtime/ui/components/filetree_primative.go
index 20347d5..4fc6656 100644
--- a/runtime/ui/components/filetree_primative.go
+++ b/runtime/ui/components/filetree_primative.go
@@ -11,7 +11,6 @@ import (
"github.com/wagoodman/dive/runtime/ui/format"
)
-// TODO simplify this interface.
type TreeModel interface {
StringBetween(int, int, bool) string
VisitDepthParentFirst(filetree.Visitor, filetree.VisitEvaluator) error
@@ -20,11 +19,13 @@ type TreeModel interface {
VisibleSize() int
SetLayerIndex(int) bool
ToggleHiddenFileType(filetype filetree.DiffType) bool
+ GetHiddenFileType(filetype filetree.DiffType) bool
+
}
type inputHandleFunc func(event *tcell.EventKey, setFocus func(p tview.Primitive))
-// TODO factor out KyeInputHandler and releated structs into a separate file
+// TODO factor out KeyInputHandler and related structs into a separate file
type KeyInputHandler struct {
Order []KeyBindingDisplay
HandlerMap map[*tcell.EventKey] func()
@@ -44,15 +45,6 @@ func (k *KeyInputHandler) AddBinding(binding KeyBindingDisplay, f func() ) *KeyI
return k
}
-func (k *KeyInputHandler) AddToggleBinding(binding KeyBindingDisplay, f func() ) *KeyInputHandler {
- index := len(k.Order)
- k.Order = append(k.Order, binding)
- k.HandlerMap[binding.EventKey] = func () {f(); k.Order[index].Selected = !k.Order[index].Selected}
-
- return k
-}
-
-
func (k *KeyInputHandler) Handle() inputHandleFunc {
return func(event *tcell.EventKey, setFocus func(p tview.Primitive) ) {
for _, m := range k.Order {
@@ -65,88 +57,150 @@ func (k *KeyInputHandler) Handle() inputHandleFunc {
type TreeViewOption func(t *TreeView)
-func UpBindingOption(k KeyBindingDisplay) TreeViewOption {
+func UpBindingOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- t.keyInputHandler.AddBinding(k, func() {t.keyUp()} )
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: AlwaysFalse,
+ Hide: AlwaysTrue,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() {t.keyUp()} )
}
}
-func DownBindingOption(k KeyBindingDisplay) TreeViewOption {
+func DownBindingOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- t.keyInputHandler.AddBinding(k, func() {t.keyDown()} )
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: AlwaysFalse,
+ Hide: AlwaysTrue,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() {t.keyDown()} )
}
}
-func RightBindingOption(k KeyBindingDisplay) TreeViewOption {
+func RightBindingOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- t.keyInputHandler.AddBinding(k, func() {t.keyRight()} )
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: AlwaysFalse,
+ Hide: AlwaysTrue,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() {t.keyRight()} )
}
}
-func LeftBindingOption(k KeyBindingDisplay) TreeViewOption {
+func LeftBindingOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- t.keyInputHandler.AddBinding(k, func() {t.keyLeft()} )
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: AlwaysFalse,
+ Hide: AlwaysTrue,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() {t.keyLeft()} )
}
}
-func PageUpBindingOption(k KeyBindingDisplay) TreeViewOption {
+func PageUpBindingOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- t.keyInputHandler.AddBinding(k, func() {t.pageUp()} )
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: AlwaysFalse,
+ Hide: AlwaysFalse,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() {t.pageUp()} )
}
}
-func PageDownBindingOption(k KeyBindingDisplay) TreeViewOption {
+func PageDownBindingOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- t.keyInputHandler.AddBinding(k, func() {t.pageDown()} )
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: AlwaysFalse,
+ Hide: AlwaysFalse,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() {t.pageDown()} )
}
}
-func CollapseDirBindingOption(k KeyBindingDisplay) TreeViewOption {
+func CollapseDirBindingOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- t.keyInputHandler.AddBinding(k, func() { t.collapseDir() } )
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: AlwaysFalse,
+ Hide: AlwaysFalse,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() { t.collapseDir() } )
}
}
-func CollapseAllBindingOption(k KeyBindingDisplay) TreeViewOption {
+func CollapseAllBindingOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- t.keyInputHandler.AddBinding(k, func() { t.collapseOrExpandAll() } )
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: AlwaysFalse,
+ Hide: AlwaysFalse,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() { t.collapseOrExpandAll() } )
}
}
-func ToggleAttributesOption(k KeyBindingDisplay) TreeViewOption {
+func ToggleAttributesOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- k.Selected = true
- t.keyInputHandler.AddToggleBinding(k, func() {t.showAttributes = !t.showAttributes})
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: func() bool {return t.showAttributes},
+ Hide: AlwaysFalse,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() {t.showAttributes = !t.showAttributes})
}
}
-func ToggleAddedFilesOption(k KeyBindingDisplay) TreeViewOption {
+func ToggleAddedFilesOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- k.Selected = true
- t.keyInputHandler.AddToggleBinding(k, func() { t.tree.ToggleHiddenFileType(filetree.Added) })
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: func() bool {return t.tree.GetHiddenFileType(filetree.Added)},
+ Hide: AlwaysFalse,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() { t.tree.ToggleHiddenFileType(filetree.Added) })
}
}
-func ToggleRemovedFilesOption(k KeyBindingDisplay) TreeViewOption {
+func ToggleRemovedFilesOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- k.Selected = true
- t.keyInputHandler.AddToggleBinding(k, func() { t.tree.ToggleHiddenFileType(filetree.Removed) })
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: func() bool {return t.tree.GetHiddenFileType(filetree.Removed)},
+ Hide: AlwaysFalse,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() { t.tree.ToggleHiddenFileType(filetree.Removed) })
}
}
-func ToggleModifiedFilesOption(k KeyBindingDisplay) TreeViewOption {
+func ToggleModifiedFilesOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- k.Selected = true
- t.keyInputHandler.AddToggleBinding(k, func() { t.tree.ToggleHiddenFileType(filetree.Modified) })
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: func() bool {return t.tree.GetHiddenFileType(filetree.Modified)},
+ Hide: AlwaysFalse,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() { t.tree.ToggleHiddenFileType(filetree.Modified) })
+
}
}
-func ToggleUnmodifiedFilesOption(k KeyBindingDisplay) TreeViewOption {
+func ToggleUnmodifiedFilesOption(k KeyBinding) TreeViewOption {
return func (t *TreeView) {
- t.keyInputHandler.AddBinding(k, func() { t.tree.ToggleHiddenFileType(filetree.Unmodified) })
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: func() bool {return t.tree.GetHiddenFileType(filetree.Unmodified)},
+ Hide: AlwaysFalse,
+ }
+ t.keyInputHandler.AddBinding(displayBinding, func() { t.tree.ToggleHiddenFileType(filetree.Unmodified) })
}
}
@@ -200,14 +254,25 @@ func (t *TreeView) Setup(config KeyBindingConfig) *TreeView {
t.tree.SetLayerIndex(0)
t.AddBindingOptions(
- UpBindingOption(NewKeyBindingDisplay(tcell.KeyUp, rune(0), tcell.ModNone, "", false, true)),
- DownBindingOption(NewKeyBindingDisplay(tcell.KeyDown, rune(0), tcell.ModNone, "", false, true)),
- LeftBindingOption(NewKeyBindingDisplay(tcell.KeyLeft, rune(0), tcell.ModNone, "", false, true)),
- RightBindingOption(NewKeyBindingDisplay(tcell.KeyRight, rune(0), tcell.ModNone, "", false, true)),
+ UpBindingOption(NewKeyBinding("Cursor Up", tcell.NewEventKey(tcell.KeyUp, rune(0), tcell.ModNone))),
+ DownBindingOption(NewKeyBinding("Cursor Down", tcell.NewEventKey(tcell.KeyDown, rune(0), tcell.ModNone))),
+ LeftBindingOption(NewKeyBinding("Cursor Left", tcell.NewEventKey(tcell.KeyLeft, rune(0), tcell.ModNone))),
+ RightBindingOption(NewKeyBinding("Cursor Right", tcell.NewEventKey(tcell.KeyRight, rune(0), tcell.ModNone))),
)
+ bindingOrder := []string{
+ "keybinding.toggle-collapse-dir",
+ "keybinding.toggle-collapse-all-dir",
+ "keybinding.toggle-filetree-attributes",
+ "keybinding.toggle-added-files",
+ "keybinding.toggle-removed-files",
+ "keybinding.toggle-modified-files",
+ "keybinding.toggle-unmodified-files",
+ "keybinding.page-up",
+ "keybinding.page-down",
+ }
- bindingSettings := map[string]func(KeyBindingDisplay) TreeViewOption{
+ bindingSettings := map[string]func(KeyBinding) TreeViewOption{
"keybinding.toggle-collapse-dir": CollapseDirBindingOption,
"keybinding.toggle-collapse-all-dir": CollapseAllBindingOption,
"keybinding.toggle-filetree-attributes": ToggleAttributesOption,
@@ -219,20 +284,14 @@ func (t *TreeView) Setup(config KeyBindingConfig) *TreeView {
"keybinding.page-down": PageDownBindingOption,
}
- hideBindings := map[string]interface{}{
- "keybinding.page-up": true,
- "keybinding.page-down": true,
- }
-
- for keybinding, action := range bindingSettings {
+ for _, keybinding := range bindingOrder {
+ action := bindingSettings[keybinding]
binding, err := config.GetKeyBinding(keybinding)
if err != nil {
panic(fmt.Errorf("setup error during %s: %w", keybinding, err))
}
- _, hideValue := hideBindings[keybinding]
-
- t.AddBindingOptions(action(KeyBindingDisplay{KeyBinding: &binding, Selected: false, Hide: hideValue}))
+ t.AddBindingOptions(action(binding))
}
return t
@@ -485,7 +544,7 @@ func (t *TreeView) Draw(screen tcell.Screen) {
t.Box.Draw(screen)
selectedIndex := t.treeIndex - t.bufferIndexLowerBound
x, y, width, _ := t.Box.GetInnerRect()
- showAttributes := width > 80 && t.showAttributes
+ showAttributes := width > 50 && t.showAttributes
treeString := t.tree.StringBetween(t.bufferIndexLowerBound, t.bufferIndexUpperBound(), showAttributes)
lines := strings.Split(treeString, "\n")
@@ -502,10 +561,12 @@ func (t *TreeView) Draw(screen tcell.Screen) {
break
}
lineStyle := tcell.StyleDefault
+ lineFormatter := format.None
if yIndex == selectedIndex {
+ lineFormatter = format.BoldReplace
lineStyle = format.SelectedStyle
}
- format.PrintLine(screen, line, x, y+yIndex, len(line), tview.AlignLeft, lineStyle)
+ tview.PrintWithStyle(screen, lineFormatter(line), x, y+yIndex, len(line), tview.AlignLeft, lineStyle)
}
diff --git a/runtime/ui/components/key_config.go b/runtime/ui/components/key_config.go
index 58993ab..98f9feb 100644
--- a/runtime/ui/components/key_config.go
+++ b/runtime/ui/components/key_config.go
@@ -9,6 +9,13 @@ import (
)
// TODO move this to a more appropriate place
+
+var KeyNames = extendKeyMaps(
+ tcell.KeyNames,
+ map[tcell.Key]string{
+ tcell.KeyCtrlM: "Ctrl-M",
+ })
+
type KeyConfig struct{}
type KeyBinding struct {
@@ -18,8 +25,8 @@ type KeyBinding struct {
type KeyBindingDisplay struct {
*KeyBinding
- Selected bool
- Hide bool
+ Selected func () bool
+ Hide func () bool
}
func (kb *KeyBindingDisplay) Name() string {
@@ -41,7 +48,7 @@ func (kb *KeyBindingDisplay) Name() string {
ok := false
key := kb.Key()
- if s, ok = tcell.KeyNames[key]; !ok {
+ if s, ok = KeyNames[key]; !ok {
if key == tcell.KeyRune {
if kb.Rune() == rune(' ') {
s = "Space"
@@ -68,14 +75,14 @@ func NewKeyBinding(name string, key *tcell.EventKey) KeyBinding {
}
}
-func NewKeyBindingDisplay(k tcell.Key, ch rune, modMask tcell.ModMask, name string, selected bool, hide bool) KeyBindingDisplay {
- kb := NewKeyBinding(name, tcell.NewEventKey(k, ch, modMask))
- return KeyBindingDisplay{
- KeyBinding: &kb,
- Selected: selected,
- Hide: hide,
- }
-}
+//func NewKeyBindingDisplay(k tcell.Key, ch rune, modMask tcell.ModMask, name string, selected bool, hide bool) KeyBindingDisplay {
+// kb := NewKeyBinding(name, tcell.NewEventKey(k, ch, modMask))
+// return KeyBindingDisplay{
+// KeyBinding: &kb,
+// Selected: selected,
+// Hide: hide,
+// }
+//}
func (k *KeyBinding) Match(event *tcell.EventKey) bool {
if k.Key() == tcell.KeyRune {
@@ -110,3 +117,16 @@ func (k *KeyConfig) GetKeyBinding(key string) (result KeyBinding, err error) {
}
return result, err
}
+
+func extendKeyMaps(m, extension map[tcell.Key]string) map[tcell.Key] string {
+ result := map[tcell.Key]string{}
+ for key, val := range m {
+ result[key] = val
+ }
+
+ for key, val := range extension {
+ result[key] = val
+ }
+
+ return result
+} \ No newline at end of file
diff --git a/runtime/ui/components/keybinding_primitive.go b/runtime/ui/components/keybinding_primitive.go
index 30966f3..a26c631 100644
--- a/runtime/ui/components/keybinding_primitive.go
+++ b/runtime/ui/components/keybinding_primitive.go
@@ -69,12 +69,12 @@ func (t *KeyMenuView) Draw(screen tcell.Screen) {
lines := []string{}
keyBindings := t.GetKeyBindings()
for idx, binding := range keyBindings {
- if binding.Hide {
+ if binding.Hide() {
continue
}
displayFormatter := format.StatusControlNormal
keyBindingFormatter := format.StatusControlNormalBold
- if binding.Selected {
+ if binding.Selected() {
displayFormatter = format.StatusControlSelected
keyBindingFormatter = format.StatusControlSelectedBold
}
diff --git a/runtime/ui/components/layers_primative.go b/runtime/ui/components/layers_primative.go
index 5cb97b6..0c3dce0 100644
--- a/runtime/ui/components/layers_primative.go
+++ b/runtime/ui/components/layers_primative.go
@@ -42,33 +42,62 @@ func NewLayerList(model LayersViewModel) *LayerList {
type LayerListViewOption func(ll *LayerList)
-func UpLayerListBindingOption(k KeyBindingDisplay) LayerListViewOption {
+var AlwaysFalse = func() bool {return false}
+var AlwaysTrue = func() bool {return true}
+
+
+func UpLayerListBindingOption(k KeyBinding) LayerListViewOption {
return func(ll *LayerList) {
- ll.keyInputHandler.AddBinding(k, func() { ll.keyUp() })
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: AlwaysFalse,
+ Hide: AlwaysTrue,
+ }
+ ll.keyInputHandler.AddBinding(displayBinding, func() { ll.keyUp() })
}
}
-func DownLayerListBindingOption(k KeyBindingDisplay) LayerListViewOption {
+func DownLayerListBindingOption(k KeyBinding) LayerListViewOption {
return func(ll *LayerList) {
- ll.keyInputHandler.AddBinding(k, func() { ll.keyDown() })
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: AlwaysFalse,
+ Hide: AlwaysTrue,
+ }
+ ll.keyInputHandler.AddBinding(displayBinding, func() { ll.keyDown() })
}
}
-func PageUpLayerListBindingOption(k KeyBindingDisplay) LayerListViewOption {
+func PageUpLayerListBindingOption(k KeyBinding) LayerListViewOption {
return func(ll *LayerList) {
- ll.keyInputHandler.AddBinding(k, func() { ll.pageUp() })
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: AlwaysFalse,
+ Hide: AlwaysFalse,
+ }
+ ll.keyInputHandler.AddBinding(displayBinding, func() { ll.pageUp() })
}
}
-func PageDownLayerListBindingOption(k KeyBindingDisplay) LayerListViewOption {
+func PageDownLayerListBindingOption(k KeyBinding) LayerListViewOption {
return func(ll *LayerList) {
- ll.keyInputHandler.AddBinding(k, func() { ll.pageDown() })
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: AlwaysFalse,
+ Hide: AlwaysFalse,
+ }
+ ll.keyInputHandler.AddBinding(displayBinding, func() { ll.pageDown() })
}
}
-func SwitchCompareLayerListBindingOption(k KeyBindingDisplay) LayerListViewOption {
- return func(ll *LayerList) {
- ll.keyInputHandler.AddToggleBinding(k, func() {
+func SwitchCompareLayerListBindingOption(k KeyBinding) LayerListViewOption {
+ return func(ll *LayerList) {
+ displayBinding := KeyBindingDisplay{
+ KeyBinding: &k,
+ Selected: func() bool {return ll.GetMode() == viewmodels.CompareAllLayers},
+ Hide: AlwaysFalse,
+ }
+ ll.keyInputHandler.AddBinding(displayBinding, func() {
if err := ll.SwitchLayerMode(); err != nil {
logrus.Error("SwitchCompareLayers error: ", err.Error())
}
@@ -87,32 +116,34 @@ func (ll *LayerList) AddBindingOptions(bindingOptions ...LayerListViewOption) *L
func (ll *LayerList) Setup(config KeyBindingConfig) *LayerList {
ll.AddBindingOptions(
- UpLayerListBindingOption(NewKeyBindingDisplay(tcell.KeyUp, rune(0), tcell.ModNone, "", false, true)),
- UpLayerListBindingOption(NewKeyBindingDisplay(tcell.KeyLeft, rune(0), tcell.ModNone, "", false, true)),
- DownLayerListBindingOption(NewKeyBindingDisplay(tcell.KeyDown, rune(0), tcell.ModNone, "", false, true)),
- DownLayerListBindingOption(NewKeyBindingDisplay(tcell.KeyRight, rune(0), tcell.ModNone, "", false, true)),
+ UpLayerListBindingOption(NewKeyBinding("Cursor Up", tcell.NewEventKey(tcell.KeyUp, rune(0), tcell.ModNone))),
+ UpLayerListBindingOption(NewKeyBinding("", tcell.NewEventKey(tcell.KeyLeft, rune(0), tcell.ModNone))),
+ DownLayerListBindingOption(NewKeyBinding("Cursor Down", tcell.NewEventKey(tcell.KeyDown, rune(0), tcell.ModNone))),
+ DownLayerListBindingOption(NewKeyBinding("", tcell.NewEventKey(tcell.KeyRight, rune(0), tcell.ModNone))),
)
- bindingSettings := map[string]func(KeyBindingDisplay) LayerListViewOption{
+ bindingOrder := []string {
+ "keybinding.page-up",
+ "keybinding.page-down",
+ "keybinding.compare-all",
+ }
+
+ bindingSettings := map[string]func(KeyBinding) LayerListViewOption{
"keybinding.page-up": PageUpLayerListBindingOption,
"keybinding.page-down": PageDownLayerListBindingOption,
"keybinding.compare-all": SwitchCompareLayerListBindingOption,
}
- hideBindings := map[string]interface{}{
- "keybinding.page-up": true,
- "keybinding.page-down": true,
- }
- for keybinding, action := range bindingSettings {
+ for _, keybinding := range bindingOrder {
+ action := bindingSettings[keybinding]
binding, err := config.GetKeyBinding(keybinding)
if err != nil {
panic(fmt.Errorf("setup error for keybinding: %s: %w", keybinding, err))
// TODO handle this error
//return nil
}
- _, hidden := hideBindings[keybinding]
- ll.AddBindingOptions(action(KeyBindingDisplay{KeyBinding: &binding, Selected: false, Hide: hidden}))
+ ll.AddBindingOptions(action(binding))
}
return ll
diff --git a/runtime/ui/components/visible_grid.go b/runtime/ui/components/visible_grid.go
index a42d12b..9b16f1c 100644
--- a/runtime/ui/components/visible_grid.go
+++ b/runtime/ui/components/visible_grid.go
@@ -47,7 +47,7 @@ func (f *VisibleFlex) GetKeyBindings() []KeyBindingDisplay {
result := []KeyBindingDisplay{}
for _, binding := range f.bindingArray {
- result = append(result, KeyBindingDisplay{KeyBinding: &binding, Selected: false})
+ result = append(result, KeyBindingDisplay{KeyBinding: &binding, Selected: AlwaysFalse, Hide: AlwaysTrue})
}
for _, item := range f.items {
diff --git a/runtime/ui/format/format.go b/runtime/ui/format/format.go
index ebdc797..b5538e8 100644
--- a/runtime/ui/format/format.go
+++ b/runtime/ui/format/format.go
@@ -83,7 +83,6 @@ var (
StatusControlNormalBold Formatter = GenerateFormatter("", "", "rb")
CompareTop Formatter = GenerateFormatter("", colorTranslate(tcell.ColorDarkMagenta), "")
CompareBottom Formatter = GenerateFormatter("", colorTranslate(tcell.ColorDarkGreen), "")
- FileTreeSelected Formatter = func(s string) string { return boldReplace(GenerateWholeLineFormatter("", "", "rb")(s)) }
// filediff types
Added Formatter = GenerateFormatter(colorTranslate(tcell.ColorGreen), "", "")
@@ -91,10 +90,7 @@ var (
Modified Formatter = GenerateFormatter(colorTranslate(tcell.ColorYellow), "", "")
// Styles these are needed to completely color a line
- HeaderStyle tcell.Style = tcell.Style{}.Bold(true).Reverse(true)
SelectedStyle tcell.Style = tcell.Style{}.Bold(true).Reverse(true)
- MenuStyle tcell.Style = tcell.Style{}.Reverse(true)
- SelectedMenuStyle tcell.Style = tcell.Style{}.Background(tcell.ColorDarkBlue).Foreground(tcell.ColorWhite).Bold(true)
)
func PrintLine(screen tcell.Screen, text string, x, y, maxWidth, align int, style tcell.Style) (int, int) {
@@ -115,7 +111,7 @@ func colorTranslate(c tcell.Color) string {
return fmt.Sprintf("#%06x", c.Hex())
}
-func boldReplace(s string) string {
+func BoldReplace(s string) string {
s = strings.ReplaceAll(s, leftBracketStr, selectedLeftBracketStr)
s = strings.ReplaceAll(s, rightBracketStr, selectedRightBracketStr)
s = strings.ReplaceAll(s, fillStr, selectedFillStr)
diff --git a/runtime/ui/viewmodels/tree_view_model.go b/runtime/ui/viewmodels/tree_view_model.go
index 52b35a4..8f669bb 100644
--- a/runtime/ui/viewmodels/tree_view_model.go
+++ b/runtime/ui/viewmodels/tree_view_model.go
@@ -100,6 +100,12 @@ func (tvm *TreeViewModel) ToggleHiddenFileType(filetype filetree.DiffType) bool
return true
}
+func (tvm *TreeViewModel) GetHiddenFileType(filetype filetree.DiffType) bool {
+ return tvm.hiddenDiffTypes[filetype]
+}
+
+
+
// TODO: maek this method private, cant think of a reason for this to be public
func (tvm *TreeViewModel) filterUpdate() error {
logrus.Debug("Updating filter!!!")
diff --git a/runtime/ui/viewmodels/tree_view_model_test.go b/runtime/ui/viewmodels/tree_view_model_test.go
index 2e95209..93e6ecb 100644
--- a/runtime/ui/viewmodels/tree_view_model_test.go
+++ b/runtime/ui/viewmodels/tree_view_model_test.go
@@ -18,6 +18,7 @@ func TestTreeViewModel(t *testing.T) {
testVisibleSize(t)
testSetFilter(t)
testToggleHiddenFileType(t)
+ testGetHiddenFileType(t)
testSetLayerIndex(t)
testSwitchLayerMode(t)
}
@@ -287,6 +288,10 @@ func testToggleHiddenFileType(t *testing.T) {
}
+func testGetHiddenFileType(t *testing.T) {
+
+}
+
func testSetLayerIndex(t *testing.T) {
fModel := &fakes.FilterModel{}
lModel := &fakes.LayersModel{}