From b2c52db70bc0299a00f10fedad57492461e23fd3 Mon Sep 17 00:00:00 2001 From: Gwendolyn Goetz Date: Wed, 24 Jan 2024 08:16:57 -0800 Subject: [PATCH 1/5] Adding configurable keybindings for up/down arrows --- README.md | 4 ++++ cmd/root.go | 2 ++ runtime/ui/view/filetree.go | 12 ++++++------ runtime/ui/view/image_details.go | 12 ++++++------ runtime/ui/view/layer.go | 12 ++++++------ runtime/ui/view/layer_details.go | 12 ++++++------ 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index fd636be0..c4159681 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,8 @@ Key Binding | Description Ctrl + F | Filter files PageUp | Scroll up a page PageDown | Scroll down a page +Up or K | Move up one line within a page +Down or J | Move down one line within a page Ctrl + A | Layer view: see aggregated image modifications Ctrl + L | Layer view: see current layer modifications Space | Filetree view: collapse/uncollapse a directory @@ -252,6 +254,8 @@ keybinding: quit: ctrl+c toggle-view: tab filter-files: ctrl+f, ctrl+slash + up: up,k + down: down,j # Layer view specific bindings compare-all: ctrl+a diff --git a/cmd/root.go b/cmd/root.go index 5074bbeb..8f60f9a3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -95,6 +95,8 @@ func initConfig() { viper.SetDefault("keybinding.toggle-wrap-tree", "ctrl+p") viper.SetDefault("keybinding.page-up", "pgup") viper.SetDefault("keybinding.page-down", "pgdn") + viper.SetDefault("keybinding.up", "up,k") + viper.SetDefault("keybinding.down", "down,j") viper.SetDefault("diff.hide", "") diff --git a/runtime/ui/view/filetree.go b/runtime/ui/view/filetree.go index e92be37d..4dcea443 100644 --- a/runtime/ui/view/filetree.go +++ b/runtime/ui/view/filetree.go @@ -148,14 +148,14 @@ func (v *FileTree) Setup(view, header *gocui.View) error { OnAction: v.PageDown, }, { - Key: gocui.KeyArrowDown, - Modifier: gocui.ModNone, - OnAction: v.CursorDown, + ConfigKeys: []string{"keybinding.down"}, + Modifier: gocui.ModNone, + OnAction: v.CursorDown, }, { - Key: gocui.KeyArrowUp, - Modifier: gocui.ModNone, - OnAction: v.CursorUp, + ConfigKeys: []string{"keybinding.up"}, + Modifier: gocui.ModNone, + OnAction: v.CursorUp, }, { Key: gocui.KeyArrowLeft, diff --git a/runtime/ui/view/image_details.go b/runtime/ui/view/image_details.go index 08098ab6..977a72c0 100644 --- a/runtime/ui/view/image_details.go +++ b/runtime/ui/view/image_details.go @@ -44,14 +44,14 @@ func (v *ImageDetails) Setup(body, header *gocui.View) error { var infos = []key.BindingInfo{ { - Key: gocui.KeyArrowDown, - Modifier: gocui.ModNone, - OnAction: v.CursorDown, + ConfigKeys: []string{"keybinding.down"}, + Modifier: gocui.ModNone, + OnAction: v.CursorDown, }, { - Key: gocui.KeyArrowUp, - Modifier: gocui.ModNone, - OnAction: v.CursorUp, + ConfigKeys: []string{"keybinding.up"}, + Modifier: gocui.ModNone, + OnAction: v.CursorUp, }, { ConfigKeys: []string{"keybinding.page-up"}, diff --git a/runtime/ui/view/layer.go b/runtime/ui/view/layer.go index ce6954a0..413c0cdb 100644 --- a/runtime/ui/view/layer.go +++ b/runtime/ui/view/layer.go @@ -116,14 +116,14 @@ func (v *Layer) Setup(body *gocui.View, header *gocui.View) error { Display: "Show aggregated changes", }, { - Key: gocui.KeyArrowDown, - Modifier: gocui.ModNone, - OnAction: v.CursorDown, + ConfigKeys: []string{"keybinding.down"}, + Modifier: gocui.ModNone, + OnAction: v.CursorDown, }, { - Key: gocui.KeyArrowUp, - Modifier: gocui.ModNone, - OnAction: v.CursorUp, + ConfigKeys: []string{"keybinding.up"}, + Modifier: gocui.ModNone, + OnAction: v.CursorUp, }, { ConfigKeys: []string{"keybinding.page-up"}, diff --git a/runtime/ui/view/layer_details.go b/runtime/ui/view/layer_details.go index bfcb4252..891af896 100644 --- a/runtime/ui/view/layer_details.go +++ b/runtime/ui/view/layer_details.go @@ -39,14 +39,14 @@ func (v *LayerDetails) Setup(body, header *gocui.View) error { var infos = []key.BindingInfo{ { - Key: gocui.KeyArrowDown, - Modifier: gocui.ModNone, - OnAction: v.CursorDown, + ConfigKeys: []string{"keybinding.down"}, + Modifier: gocui.ModNone, + OnAction: v.CursorDown, }, { - Key: gocui.KeyArrowUp, - Modifier: gocui.ModNone, - OnAction: v.CursorUp, + ConfigKeys: []string{"keybinding.up"}, + Modifier: gocui.ModNone, + OnAction: v.CursorUp, }, } From f4ccc363b4471b8a3da51a20c1ca1d2d37da6550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=9Cmit=20=C3=96zden?= Date: Sun, 28 Jan 2024 22:01:36 +0300 Subject: [PATCH 2/5] Add configurable keybindings for left/right arrows --- README.md | 2 ++ cmd/root.go | 2 ++ runtime/ui/app.go | 4 ++-- runtime/ui/view/filetree.go | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c4159681..6a6c37f5 100644 --- a/README.md +++ b/README.md @@ -256,6 +256,8 @@ keybinding: filter-files: ctrl+f, ctrl+slash up: up,k down: down,j + left: left,h + right: right,l # Layer view specific bindings compare-all: ctrl+a diff --git a/cmd/root.go b/cmd/root.go index 8f60f9a3..f376798a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -97,6 +97,8 @@ func initConfig() { viper.SetDefault("keybinding.page-down", "pgdn") viper.SetDefault("keybinding.up", "up,k") viper.SetDefault("keybinding.down", "down,j") + viper.SetDefault("keybinding.left", "left,h") + viper.SetDefault("keybinding.right", "right,l") viper.SetDefault("diff.hide", "") diff --git a/runtime/ui/app.go b/runtime/ui/app.go index 608a6648..14a43507 100644 --- a/runtime/ui/app.go +++ b/runtime/ui/app.go @@ -77,11 +77,11 @@ func newApp(gui *gocui.Gui, imageName string, analysis *image.AnalysisResult, ca Display: "Switch view", }, { - Key: gocui.KeyArrowRight, + ConfigKeys: []string{"keybinding.right"}, OnAction: controller.NextPane, }, { - Key: gocui.KeyArrowLeft, + ConfigKeys: []string{"keybinding.left"}, OnAction: controller.PrevPane, }, { diff --git a/runtime/ui/view/filetree.go b/runtime/ui/view/filetree.go index 4dcea443..45d82bf9 100644 --- a/runtime/ui/view/filetree.go +++ b/runtime/ui/view/filetree.go @@ -158,12 +158,12 @@ func (v *FileTree) Setup(view, header *gocui.View) error { OnAction: v.CursorUp, }, { - Key: gocui.KeyArrowLeft, + ConfigKeys: []string{"keybinding.left"}, Modifier: gocui.ModNone, OnAction: v.CursorLeft, }, { - Key: gocui.KeyArrowRight, + ConfigKeys: []string{"keybinding.right"}, Modifier: gocui.ModNone, OnAction: v.CursorRight, }, From 2d1ed3e07784755b22834ee0cbce6cfecae2a3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=9Cmit=20=C3=96zden?= Date: Sun, 28 Jan 2024 22:13:38 +0300 Subject: [PATCH 3/5] Add u and d keys for page up/down alternatives --- README.md | 12 ++++++------ cmd/root.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6a6c37f5..388622dc 100644 --- a/README.md +++ b/README.md @@ -218,8 +218,8 @@ Key Binding | Description Ctrl + C or Q | Exit Tab | Switch between the layer and filetree views Ctrl + F | Filter files -PageUp | Scroll up a page -PageDown | Scroll down a page +PageUp or U | Scroll up a page +PageDown or D | Scroll down a page Up or K | Move up one line within a page Down or J | Move down one line within a page Ctrl + A | Layer view: see aggregated image modifications @@ -231,8 +231,8 @@ Key Binding | Description Ctrl + M | Filetree view: show/hide modified files Ctrl + U | Filetree view: show/hide unmodified files Ctrl + B | Filetree view: show/hide file attributes -PageUp | Filetree view: scroll up a page -PageDown | Filetree view: scroll down a page +PageUp or U | Filetree view: scroll up a page +PageDown or D | Filetree view: scroll down a page ## UI Configuration @@ -271,8 +271,8 @@ keybinding: toggle-modified-files: ctrl+m toggle-unmodified-files: ctrl+u toggle-filetree-attributes: ctrl+b - page-up: pgup - page-down: pgdn + page-up: pgup,u + page-down: pgdn,d diff: # You can change the default files shown in the filetree (right pane). All diff types are shown by default. diff --git a/cmd/root.go b/cmd/root.go index f376798a..09f1c121 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -93,8 +93,8 @@ func initConfig() { viper.SetDefault("keybinding.toggle-modified-files", "ctrl+m") viper.SetDefault("keybinding.toggle-unmodified-files", "ctrl+u") viper.SetDefault("keybinding.toggle-wrap-tree", "ctrl+p") - viper.SetDefault("keybinding.page-up", "pgup") - viper.SetDefault("keybinding.page-down", "pgdn") + viper.SetDefault("keybinding.page-up", "pgup,u") + viper.SetDefault("keybinding.page-down", "pgdn,d") viper.SetDefault("keybinding.up", "up,k") viper.SetDefault("keybinding.down", "down,j") viper.SetDefault("keybinding.left", "left,h") From 68e6aee819170212fa49221651e05160d07f474a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=9Cmit=20=C3=96zden?= Date: Mon, 29 Jan 2024 10:37:41 +0300 Subject: [PATCH 4/5] Add configurable keybinding to close filter --- README.md | 2 ++ cmd/root.go | 1 + runtime/ui/app.go | 4 ++++ runtime/ui/controller.go | 9 +++++++++ 4 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 388622dc..95fa9268 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,7 @@ Key Binding | Description Ctrl + C or Q | Exit Tab | Switch between the layer and filetree views Ctrl + F | Filter files +ESC | Close filter files PageUp or U | Scroll up a page PageDown or D | Scroll down a page Up or K | Move up one line within a page @@ -254,6 +255,7 @@ keybinding: quit: ctrl+c toggle-view: tab filter-files: ctrl+f, ctrl+slash + close-filter-files: esc up: up,k down: down,j left: left,h diff --git a/cmd/root.go b/cmd/root.go index 09f1c121..b08a3439 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -80,6 +80,7 @@ func initConfig() { viper.SetDefault("keybinding.quit", "ctrl+c,q") viper.SetDefault("keybinding.toggle-view", "tab") viper.SetDefault("keybinding.filter-files", "ctrl+f, ctrl+slash") + viper.SetDefault("keybinding.close-filter-files", "esc") // keybindings: layer view viper.SetDefault("keybinding.compare-all", "ctrl+a") viper.SetDefault("keybinding.compare-layer", "ctrl+l") diff --git a/runtime/ui/app.go b/runtime/ui/app.go index 14a43507..9497a1fe 100644 --- a/runtime/ui/app.go +++ b/runtime/ui/app.go @@ -90,6 +90,10 @@ func newApp(gui *gocui.Gui, imageName string, analysis *image.AnalysisResult, ca IsSelected: controller.views.Filter.IsVisible, Display: "Filter", }, + { + ConfigKeys: []string{"keybinding.close-filter-files"}, + OnAction: controller.CloseFilterView, + }, } globalHelpKeys, err = key.GenerateBindings(gui, "", infos) diff --git a/runtime/ui/controller.go b/runtime/ui/controller.go index 031955df..60faf87c 100644 --- a/runtime/ui/controller.go +++ b/runtime/ui/controller.go @@ -212,6 +212,15 @@ func (c *Controller) ToggleView() (err error) { return c.UpdateAndRender() } +func (c *Controller) CloseFilterView() error { + // filter view needs to be visible + if c.views.Filter.IsVisible() { + // toggle filter view + return c.ToggleFilterView() + } + return nil +} + func (c *Controller) ToggleFilterView() error { // delete all user input from the tree view err := c.views.Filter.ToggleVisible() From 95d0fa05f7aa2cea2894d89f4f4a3939d6cb5b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=9Cmit=20=C3=96zden?= Date: Fri, 2 Feb 2024 10:30:53 +0300 Subject: [PATCH 5/5] Fix format using gofmt --- runtime/ui/app.go | 4 ++-- runtime/ui/view/filetree.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runtime/ui/app.go b/runtime/ui/app.go index 9497a1fe..fc39a7f4 100644 --- a/runtime/ui/app.go +++ b/runtime/ui/app.go @@ -78,11 +78,11 @@ func newApp(gui *gocui.Gui, imageName string, analysis *image.AnalysisResult, ca }, { ConfigKeys: []string{"keybinding.right"}, - OnAction: controller.NextPane, + OnAction: controller.NextPane, }, { ConfigKeys: []string{"keybinding.left"}, - OnAction: controller.PrevPane, + OnAction: controller.PrevPane, }, { ConfigKeys: []string{"keybinding.filter-files"}, diff --git a/runtime/ui/view/filetree.go b/runtime/ui/view/filetree.go index 45d82bf9..4b4eb624 100644 --- a/runtime/ui/view/filetree.go +++ b/runtime/ui/view/filetree.go @@ -159,13 +159,13 @@ func (v *FileTree) Setup(view, header *gocui.View) error { }, { ConfigKeys: []string{"keybinding.left"}, - Modifier: gocui.ModNone, - OnAction: v.CursorLeft, + Modifier: gocui.ModNone, + OnAction: v.CursorLeft, }, { ConfigKeys: []string{"keybinding.right"}, - Modifier: gocui.ModNone, - OnAction: v.CursorRight, + Modifier: gocui.ModNone, + OnAction: v.CursorRight, }, }