rivo / tview

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

Support more key press types for SetDoneFunc #937

Closed spacez320 closed 10 months ago

spacez320 commented 10 months ago

I'm wondering if we could consider supporting more key presses for something like TextView's SetDoneFunc. Currently it only supports Enter, Esc, Tab, and Backtab (ref: https://github.com/rivo/tview/blob/b3bd1aa5e9f23ba61af8160d1021dab4df701eb0/textview.go#L1279).

Use Case

Mainly I'm trying to get more interaction out of a widget, and I've run out of keys. It would be cool if we could include other control keys like Home, Pause, Del, Space, etc.

Is this something worth considering? I'm happy to contribute something, if so.

rivo commented 10 months ago

The SetDoneFunc is mainly used to indicate to a Form that the user wants to jump to the next (or previous) form element. I wouldn't consider Home or Del a key that the user presses to indicate that they are "done" and want to advance to the next item in a form.

I have a feeling that you want to achieve something else unrelated to SetDoneFunc. For example, the Home key already works in a TextView. I'm not sure what Del should do (there's not editing functionality in that widget).

Maybe you can explain exactly what you're trying to do in your application that is currently not possible?

spacez320 commented 10 months ago

@rivo Sure thing. I'm actually using SetDoneFunc in a TextView that has focus to register some key-presses in order to get the TextView to do certain things.

More specifically, I have the TextView re-draw itself with different data, or change into a Table, or pause some auto-updating text. It's specifically the latter where I ran into the motivation for this issue, as "space" (which was my first inclination for pausing) isn't allowed in the list of tcell keys tview responds to, and I had actually already exhausted all the tcell keys I could use for other interactions. Hence wondering if we can do more.

I hear you that in something like a Form or Table widget, different keystrokes make sense for various behaviors. Primarily I'm just displaying some updating text to a user and want to give them a suite of keys to press to do different things with that display (less about navigating data within the TextView or things like that, if that makes sense).

Is SetDoneFunc not the way I should go about this?

Thanks for the help!

rivo commented 10 months ago

I think you'll want to use SetInputCapture. That's the preferred method to add custom key binds to a widget.

spacez320 commented 10 months ago

I will give this a shot, thanks for the guidance @rivo . Also great work on the project.