rivo / tview

Terminal UI library with rich, interactive widgets — written in Golang
MIT License
10.8k stars 562 forks source link

Feature Request: Support hjkl navigation in TUI modals. #1003

Closed F1bonacc1 closed 2 months ago

F1bonacc1 commented 3 months ago

Feature Request

Allow using hjkl binding in modal dialogs as an alternative to arrow navigation.

Use Case:

Vimmers wanting to vim everywhere

Original issue: https://github.com/F1bonacc1/process-compose/issues/193

kivattt commented 3 months ago

You can add hjkl navigation by using SetInputCapture on the modal

This is what I've done before to add it to modals: https://github.com/kivattt/fen/blob/83643815f7e03aaf4c700e8342edfe20aeb95319/main.go#L271

F1bonacc1 commented 3 months ago

Thanks @kivattt, That will work for sure. Wouldn't it be better to make it consistent with other widgets in which hjkl is already supported?

rivo commented 2 months ago

To be honest, I think it was a mistake to add vim-like navigation to tview. At first, I did it because there are many vim users out there (myself included) and most widgets in the initial version of this package were read-only so it didn't hurt to add these keybinds. However, this doesn't work with widgets like InputField or the later introduced TextArea. At least not without adding modes. (And that's definitely something that's not going to be added to tview.) The bash-like / readline type of keybinds which use Ctrl lend themselves better to the widgets offered in this library, as they don't interfere with normal text input.

I know we're now left with a somewhat inconsistent state of affairs because of the backwards compatibility promise. I'm not going to remove these keybinds but I probably won't add new ones. As @kivattt mentioned, people can always customize their widgets to their liking.

I'm working on an API which will make it easier to add these kind of changes to widgets. Then you might even be able to include a third-party package that will enable vim-like navigation across the board.

F1bonacc1 commented 2 months ago

Thank you @rivo for the detailed answer. In this case, I will use @kivattt's suggestion. Thanks again for this amazing library!