Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vim like arrow, scroll, and close filtering motions #501

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,11 @@ Key Binding | Description
<kbd>Ctrl + C</kbd> or <kbd>Q</kbd> | Exit
<kbd>Tab</kbd> | Switch between the layer and filetree views
<kbd>Ctrl + F</kbd> | Filter files
<kbd>PageUp</kbd> | Scroll up a page
<kbd>PageDown</kbd> | Scroll down a page
<kbd>ESC</kbd> | Close filter files
<kbd>PageUp</kbd> or <kbd>U</kbd> | Scroll up a page
<kbd>PageDown</kbd> or <kbd>D</kbd> | Scroll down a page
<kbd>Up</kbd> or <kbd>K</kbd> | Move up one line within a page
<kbd>Down</kbd> or <kbd>J</kbd> | Move down one line within a page
<kbd>Ctrl + A</kbd> | Layer view: see aggregated image modifications
<kbd>Ctrl + L</kbd> | Layer view: see current layer modifications
<kbd>Space</kbd> | Filetree view: collapse/uncollapse a directory
Expand All @@ -229,8 +232,8 @@ Key Binding | Description
<kbd>Ctrl + M</kbd> | Filetree view: show/hide modified files
<kbd>Ctrl + U</kbd> | Filetree view: show/hide unmodified files
<kbd>Ctrl + B</kbd> | Filetree view: show/hide file attributes
<kbd>PageUp</kbd> | Filetree view: scroll up a page
<kbd>PageDown</kbd> | Filetree view: scroll down a page
<kbd>PageUp</kbd> or <kbd>U</kbd> | Filetree view: scroll up a page
<kbd>PageDown</kbd> or <kbd>D</kbd> | Filetree view: scroll down a page

## UI Configuration

Expand All @@ -252,6 +255,11 @@ 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
right: right,l

# Layer view specific bindings
compare-all: ctrl+a
Expand All @@ -265,8 +273,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.
Expand Down
9 changes: 7 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -93,8 +94,12 @@ 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")
viper.SetDefault("keybinding.right", "right,l")

viper.SetDefault("diff.hide", "")

Expand Down
8 changes: 6 additions & 2 deletions runtime/ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions runtime/ui/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 8 additions & 8 deletions runtime/ui/view/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,22 @@ 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,
ConfigKeys: []string{"keybinding.left"},
Modifier: gocui.ModNone,
OnAction: v.CursorLeft,
},
{
Key: gocui.KeyArrowRight,
ConfigKeys: []string{"keybinding.right"},
Modifier: gocui.ModNone,
OnAction: v.CursorRight,
},
Expand Down
12 changes: 6 additions & 6 deletions runtime/ui/view/image_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
12 changes: 6 additions & 6 deletions runtime/ui/view/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
12 changes: 6 additions & 6 deletions runtime/ui/view/layer_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down