diff options
author | dwillist <dthornton@vmware.com> | 2021-01-13 00:19:24 -0500 |
---|---|---|
committer | dwillist <dthornton@vmware.com> | 2021-01-13 00:19:24 -0500 |
commit | fb4644cf13e4b2a8529477007d5c8c7922fee6b1 (patch) | |
tree | 8e65c350c3afaeaef12dd14715dc304c3ea20322 | |
parent | be945d35019f9604cb4232e558db589626cdda83 (diff) |
add keybindings to grid that separates layerview from filetree
Signed-off-by: dwillist <dthornton@vmware.com>
-rw-r--r-- | cmd/root.go | 23 | ||||
-rw-r--r-- | runtime/ui/app.go | 25 |
2 files changed, 39 insertions, 9 deletions
diff --git a/cmd/root.go b/cmd/root.go index b682947..bf2e8bc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -80,18 +80,30 @@ func initConfig() { viper.SetDefault("log.path", "./dive.log") viper.SetDefault("log.enabled", false) // keybindings: status view / global - viper.SetDefault("keybinding.quit", "ctrl+c") - viper.SetDefault("keybinding.toggle-view", "tab") - viper.SetDefault("keybinding.filter-files", "ctrl+f, ctrl+slash") + + // This keybinding can be changed but ctrl+C may still quit the application + viper.SetDefault("keybinding.quit", components.NewKeyBinding( + "Quit", + tcell.NewEventKey(tcell.KeyCtrlC, rune(0), tcell.ModCtrl), + )) + viper.SetDefault("keybinding.toggle-view", components.NewKeyBinding( + "Switch View", + tcell.NewEventKey(tcell.KeyTab, rune(0), tcell.ModNone), + )) + + viper.SetDefault("keybinding.filter-files", components.NewKeyBinding( + "Find", + tcell.NewEventKey(tcell.KeyCtrlF, rune(0), tcell.ModCtrl), + )) // keybindings: layer view viper.SetDefault("keybinding.compare-all", components.NewKeyBinding( "Compare All", - tcell.NewEventKey(tcell.KeyCtrlA, rune(0), tcell.ModNone), + tcell.NewEventKey(tcell.KeyCtrlA, rune(0), tcell.ModCtrl), )) viper.SetDefault("keybinding.compare-layer", components.NewKeyBinding( "Compare Layer", - tcell.NewEventKey(tcell.KeyCtrlL, rune(0), tcell.ModNone), + tcell.NewEventKey(tcell.KeyCtrlL, rune(0), tcell.ModCtrl), )) // keybindings: filetree view @@ -104,7 +116,6 @@ func initConfig() { "Collapse All", tcell.NewEventKey(tcell.KeyCtrlSpace, rune(0), tcell.ModCtrl), )) - //viper.SetDefault("keybinding.toggle-filetree-attributes", "ctrl+b") viper.SetDefault("keybinding.toggle-filetree-attributes", components.NewKeyBinding( "FileTree Attributes", tcell.NewEventKey(tcell.KeyCtrlB, rune(0), tcell.ModCtrl), diff --git a/runtime/ui/app.go b/runtime/ui/app.go index f9bcf5c..2224e12 100644 --- a/runtime/ui/app.go +++ b/runtime/ui/app.go @@ -102,16 +102,35 @@ func newApp(app *tview.Application, analysis *image.AnalysisResult, cache filetr layers: layersBox, } + quitBinding, err := config.GetKeyBinding("keybinding.quit") + if err != nil { + // TODO handle this as an error + panic(err) + } + + filterBinding, err := config.GetKeyBinding("keybinding.filter-files") + if err != nil { + // TODO handle this as an error + panic(err) + } + switchBinding, err := config.GetKeyBinding("keybinding.toggle-view") + if err != nil { + // TODO handle this as an error + panic(err) + } + switchFocus := func(event *tcell.EventKey) *tcell.EventKey { var result *tcell.EventKey = nil - switch event.Key() { - case tcell.KeyTAB: + switch { + case quitBinding.Match(event): + app.Stop() + case switchBinding.Match(event): if appSingleton.app.GetFocus() == appSingleton.layers { appSingleton.app.SetFocus(appSingleton.fileTree) } else { appSingleton.app.SetFocus(appSingleton.layers) } - case tcell.KeyCtrlF: + case filterBinding.Match(event): if filterView.HasFocus() { filterView.Blur() appSingleton.app.SetFocus(fileTreeBox) |