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

Adding vim keybindings #24

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
- The config file has the following options:
```
{
SortMode: "closest"|"none", // changes how results are sorted (more to come)
Ncurses: bool, # Whether to default to ncurses or not (override by -n)
Update: bool, # Whether to update the pacman repos before every sync command
PrintPkg: bool, # Whether to print the PKGBUILD before install (for AUR)
AskPkg: bool, # Whether to ask to edit PKGBUILD before install (only if PrintPkg is true)
AskRedo: bool, # Whether to ask if you want to reselect packages before install
SilentUpdate: bool, # Whether you want to be asked to edit PKGBUILD during system update (overrides PrintPkg)
PacmanLimit: int, # The number of packages parsed from pacman to be sorted and searched
AurLimit: int, # The number of packages parsed from the AUR to be sorted and searched
SortMode: "closest"|"none", # changes how results are sorted (more to come)
Ncurses: bool, # Whether to default to ncurses or not (override by -n)
Update: bool, # Whether to update the pacman repos before every sync command
PrintPkg: bool, # Whether to print the PKGBUILD before install (for AUR)
AskPkg: bool, # Whether to ask to edit PKGBUILD before install (only if PrintPkg is true)
AskRedo: bool, # Whether to ask if you want to reselect packages before install
SilentUpdate: bool, # Whether you want to be asked to edit PKGBUILD during system update (overrides PrintPkg)
PacmanLimit: int, # The number of packages parsed from pacman to be sorted and searched
AurLimit: int, # The number of packages parsed from the AUR to be sorted and searched
VimKeybindings: bool, # Enabling Vim keybindings (j and k keys to go up and down)
}
```
## Usage
Expand Down
42 changes: 22 additions & 20 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (

// File struct
type File struct {
SortMode string `json:"sort_mode"`
Ncurses bool `json:"ncurses_mode"`
Update bool `json:"always_update_repos"`
PrintPkg bool `json:"print_pkgbuild"`
AskPkg bool `json:"ask_pkgbuild"`
AskRedo bool `json:"ask_redo"`
ConfigVersion string `json:"version"`
SilentUpdate bool `json:"silent_update"`
PacmanLimit int `json:"pacman_limit"`
AurLimit int `json:"aur_limit"`
SortMode string `json:"sort_mode"`
Ncurses bool `json:"ncurses_mode"`
Update bool `json:"always_update_repos"`
PrintPkg bool `json:"print_pkgbuild"`
AskPkg bool `json:"ask_pkgbuild"`
AskRedo bool `json:"ask_redo"`
ConfigVersion string `json:"version"`
SilentUpdate bool `json:"silent_update"`
PacmanLimit int `json:"pacman_limit"`
AurLimit int `json:"aur_limit"`
VimKeybindings bool `json:"vim_keybindings"`
}

// Config struct
Expand Down Expand Up @@ -109,16 +110,17 @@ func ReadConfigFile(version string) error {
// InitConfig writes the initial JSON to the file
func InitConfig(file *os.File, version string) error {
initFile := &File{
SortMode: "closest",
Ncurses: true,
Update: false,
PrintPkg: true,
AskPkg: true,
AskRedo: true,
ConfigVersion: version,
SilentUpdate: true,
PacmanLimit: 200,
AurLimit: 200,
SortMode: "closest",
Ncurses: true,
Update: false,
PrintPkg: true,
AskPkg: true,
AskRedo: true,
ConfigVersion: version,
SilentUpdate: true,
PacmanLimit: 200,
AurLimit: 200,
VimKeybindings: false,
}
write, err := json.MarshalIndent(initFile, "", " ")
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,18 @@ Resize:
if !timeout {
Sw:
switch goncurses.Key(ch) {
case 'k':
if config.GetConfig().UserFile.VimKeybindings && selected < len(*packs) {
// Scroll forward
selected += 1
update = true
}
case 'j':
if config.GetConfig().UserFile.VimKeybindings && selected > 1 {
// Scroll backward
selected -= 1
update = true
}
case goncurses.KEY_UP, goncurses.KEY_SF, 'w':
// Scroll forward
if selected < len(*packs) {
Expand Down