tconbeer / harlequin

The SQL IDE for Your Terminal.
https://harlequin.sh
MIT License
3.3k stars 76 forks source link

Create key bindings config and keymap plug-ins #541

Closed tconbeer closed 1 week ago

tconbeer commented 2 months ago

Hoping to satisfy #371 and #422 with the following design. VS Code docs on their config were informative.

Rough process is:

  1. look for keymap plugins ("harlequin.keymap" ep)
  2. look for key binding configs in loaded profiles
  3. configure bindings for widgets from 1 | 2

a binding config will be an Array of Tables:

[[harlequin.keymap.my_keys]]
target="App" # Widget or app label (will be an enum/mapping to a widget class)
key="ctrl+k"
action="export" # name of an action
description="Show Export Modal" # custom description for footer
show=true # show in footer
key_display="^e" # custom display text for key in footer

[[harlequin.keymap.my_keys]]
key="ctrl+e"
action="find"
target="Editor" 

Harlequin will discover the config and load them into a HarlequinKeyMap class with a name='my_keys' attribute. Other HarlequinKeyMaps will be discovered as plug-ins, including the default keymap, HarlequinVSCodeKeyMap (name='vscode').

In the profile, a user can configure the active key map(s); also at the command line: --keymap vscode --keymap my_keys. If given multiple maps, Harlequin will merge them, last one given priority.

Harlequin will have essentially no bindings without the default map (maybe just ctrl+q), and then will merge and load keymaps at start-up.

We should create an action that loads a keymap, so that it can be bound to a key to enable multiple "modes" like in Vim.

Finally, there should be some kind of keymap editor that spits out a keymap config and writes it to a config file. Would be great if that gave feedback on the keys currently being pressed, since it's not intuitive which key combinations will or won't work for each terminal. This can be its own Textual app, maybe harlequin --keys

cs2018ncsa commented 2 months ago

This sounds absolutely awesome. Seriously. Just wanted to say that before i click on the "Sponsor" button. :)

tconbeer commented 2 months ago

@cs2018ncsa Thank you so much for your support!

joshtemple commented 2 months ago

Super exciting stuff, can't wait to try out vim bindings, even in a limited form.

Harlequin will have essentially no bindings without the default map (maybe just ctrl+q), and then will merge and load keymaps at start-up.

What about the key combinations at the bottom of Harlequin like CTRL+J, CTRL+S, etc.?

I'm guessing the answer is yes, but will Mac-specific keys be supported?

tconbeer commented 2 months ago

Yes, this includes all of those, like ctrl+j.

You should be able to use any key combo that works for your terminal and gets forwarded to Harlequin... sometimes the virtual key names change a bit, but I think most terminals map cmd to ctrl, etc.

D10f commented 2 months ago

I just discovered this (through Terminal Trove) and this is the only feature that I find missing. I keep battling between using vim motions and default shell shortcuts to navigate between words in the query panel, but none work exactly as I would expect. Having a way to customize the keybindings to navigate between panels and other actions would be a killer feature.

wey-gu commented 2 weeks ago

So very much looking forward to this, I am an HHKB user on macOS with iterm2/alacritty/vscode-terminal/nvim-terminal.

ctrl-j was mapped to "down" for me so for now ctrl-enter is my hope but I tested with textual keys, and ctrl-enter was now enter in all above tty envs.

s1nistr4 commented 2 weeks ago

If this one feature was implemented this would replace every GUI/based database editor, vim-dadbod, and lazysql overnight.

This should be the single biggest priority of this project imo. Mainly because the default keybindings aren't that good. Like F2, F5 and F6 to switch windows...what? Imagine navigating with vim keybindings like hjkl and writing custom keymaps for queries and stuff. This app is really good so far and soooo close to finally being the way to interact with sql databases via the terminal which is like 30 years overdue.

tconbeer commented 2 weeks ago

@s1nistr4 I'm pretty annoyed by your tone, but yeah, I'm working on this. Well, actually right now I'm visiting family in the hospital but maybe after that I'll get back to working on this.

s1nistr4 commented 2 weeks ago

@s1nistr4 I'm pretty annoyed by your tone, but yeah, I'm working on this. Well, actually right now I'm visiting family in the hospital but maybe after that I'll get back to working on this.

It wasn't meant to be rude, I'm just saying you can monopolize the industry you're in overnight if this was implemented. If anything it's to help you and your project succeed. Harlequin is so far the best TUI SQL client I've used out of the many I've tried.

wey-gu commented 2 weeks ago

I'm visiting family in the hospital

Hoping he/she will be fine soon.

cs2018ncsa commented 2 weeks ago

@s1nistr4 I'm pretty annoyed by your tone, but yeah, I'm working on this. Well, actually right now I'm visiting family in the hospital but maybe after that I'll get back to working on this.

Priorities! Hope everything is ok. You've already done such an incredible favor to the community. Thank you.

tconbeer commented 1 week ago

This has been shipped in v1.22.0

Vim motions present a suite of challenges that will have to be tackled later; for now, though, you can customize bindings to any single key press. See the new docs: https://harlequin.sh/docs/keymaps/index

wey-gu commented 1 week ago

This has been shipped in v1.22.0

Vim motions present a suite of challenges that will have to be tackled later; for now, though, you can customize bindings to any single key press. See the new docs: https://harlequin.sh/docs/keymaps/index

It worked like a charm! Thanks!!!