Skip to content

Make key bindings configurable#255

Merged
danvergara merged 10 commits intomainfrom
add-keybindings-config
Apr 27, 2025
Merged

Make key bindings configurable#255
danvergara merged 10 commits intomainfrom
add-keybindings-config

Conversation

@danvergara
Copy link
Copy Markdown
Owner

@danvergara danvergara commented Apr 18, 2025

Make configuration configurable

Description

Some users have asked a very specific feature which is making the key bindings configurable through the .dblab.yaml file. Some told me that they use dblab on Tmux and key bindings don't work because navigation bindings overlap with the vim-tmux-navigator key bindings. I have run into this issue as well and ended up using dblab on a naked terminal which is not ideal.

The new config file supports new fields like the ones shown below:

keybindings:
  run-query: 'Ctrl-Space'
  indexes: 'Ctrl-I'
  constraints: 'Ctrl-T'
  structure: 'Ctrl-S'
  clear-editor: 'Ctrl-D'
  navigation:
    up: 'Ctrl-K'
    down: 'Ctrl-J'
    left: 'Ctrl-H'
    right: 'Ctrl-L'

The values show above are the default ones if the fields are not present. The only way to change them is the config file, I've avoided adding new CLI flags because more flags are a burden I don't have the capacity to maintain and the config files is backward compatible, because if the values are not present, the default key bindings are picked.

The list of available key bindings come from the tcell library.

Fixes #225 #250 #233

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

QA'd the new change with new key bindings and added more assertions to the TestInit function.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

@danvergara danvergara changed the title Add keybindings config Make key bindings configurable Apr 18, 2025
@danvergara danvergara marked this pull request as ready for review April 18, 2025 19:37
@danvergara danvergara force-pushed the add-keybindings-config branch from db148d5 to 5d366b2 Compare April 19, 2025 21:25
Copy link
Copy Markdown

@hschne hschne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I did give this a try. Maybe I did something wrong, but testing this with go run . on gives me an error .

Error: non-empty values required to open a session with a database
exit status 1

Tried on master, works there. Tried to narrow it down, seems the issue is the backwards-compatibility code in root.go. Why those couple of lines cause problems is a mystery to me. Maybe some cobra-specific stuff I don't understand.

Navigation TUINavgationBindgins
}

type TUINavgationBindgins struct {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, probably should be TUINavigationBindings.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hschne Nice catch!

Thanks

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

cmd/root.go Outdated
Comment on lines +100 to +106
Up: tcell.KeyCtrlK,
Down: tcell.KeyCtrlJ,
Left: tcell.KeyCtrlH,
Right: tcell.KeyCtrlL,
Structure: tcell.KeyCtrlS,
Indexes: tcell.KeyCtrlI,
Constraints: tcell.KeyCtrlT,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing these lines enables running go run again. Absolutely beats my why those would be an issue 🤔

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's on me. Haven't tried the form. It's broken, forgot to ignore the new fields on the Options struct so the application can enter in the form mode.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a new commit that ignores the TUIKeyBindings struct at the emptiness validation.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I never run the go command on the project directly. There's a Makefile file for development. It covers the most of the commands available. Feel free to edit it so it fits your local setup requirements.

@hschne
Copy link
Copy Markdown

hschne commented Apr 22, 2025

Works with ./dblab --config 👌

navigation:
  up: "Up"
  down: "Down"
  left: "Left"
  right: "Right"

Tried various keybinds. What I didn't get to work were keybinds using composite keys, such as Alt-J, Ctrl-Shift-J and so on. I'm assuming that's some limitation with tcell, or just user error. Didn't get any wiser checking key.go.

@danvergara
Copy link
Copy Markdown
Owner Author

Works with ./dblab --config 👌

navigation:
  up: "Up"
  down: "Down"
  left: "Left"
  right: "Right"

Tried various keybinds. What I didn't get to work were keybinds using composite keys, such as Alt-J, Ctrl-Shift-J and so on. I'm assuming that's some limitation with tcell, or just user error. Didn't get any wiser checking key.go.

Yeah, KeyNames is the reference for the available keybindings plus a couple of more that work but haven't been included in the map. Might submit a PR fixing that later on the tcell side.

What do you think about the current implementation?
Do you like it the way it is rn?
Any suggestions @hschne?

@hschne
Copy link
Copy Markdown

hschne commented Apr 22, 2025

I think it's great, good to go as is 👍

@danvergara danvergara force-pushed the add-keybindings-config branch from 3dbe861 to d87f42f Compare April 24, 2025 05:25
@danvergara danvergara force-pushed the add-keybindings-config branch from d87f42f to 41d7b66 Compare April 24, 2025 05:30
@danvergara
Copy link
Copy Markdown
Owner Author

I just pushed more changes @hschne. Just moved the non-navigation keybindings one level above up to the KeyBinding structs, since they don't have to do with the navigation itslef. Also, I covered the new key binding added in v0.31.0 which clears the editor.

@danvergara danvergara merged commit db0e6b4 into main Apr 27, 2025
4 checks passed
@danvergara danvergara deleted the add-keybindings-config branch April 27, 2025 04:54
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request May 10, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [danvergara/dblab](https://github.com/danvergara/dblab) | minor | `v0.30.1` -> `v0.32.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>danvergara/dblab (danvergara/dblab)</summary>

### [`v0.32.0`](https://github.com/danvergara/dblab/releases/tag/v0.32.0)

[Compare Source](danvergara/dblab@v0.31.0...v0.32.0)

#### Changelog

-   [`db0e6b4`](danvergara/dblab@db0e6b4) feat:  configurable key bindings  ([#&#8203;255](danvergara/dblab#255))

### [`v0.31.0`](https://github.com/danvergara/dblab/releases/tag/v0.31.0)

[Compare Source](danvergara/dblab@v0.30.1...v0.31.0)

#### Changelog

-   [`2fd4b96`](danvergara/dblab@2fd4b96) build: bump go version 1.24 ([#&#8203;254](danvergara/dblab#254))
-   [`afb91a3`](danvergara/dblab@afb91a3) chore: housekeeping changes ([#&#8203;256](danvergara/dblab#256))
-   [`919d753`](danvergara/dblab@919d753) docs(mkdocs): update usage markdown file ([#&#8203;259](danvergara/dblab#259))
-   [`e8b7a93`](danvergara/dblab@e8b7a93) feat: add a key binding to clear the query editor ([#&#8203;258](danvergara/dblab#258))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yNTkuMCIsInVwZGF0ZWRJblZlciI6IjM5LjI1OS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] lazygit alike navigation and usage

2 participants