rivo / tview

Terminal UI library with rich, interactive widgets — written in Golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support more key press types for SetDoneFunc

spacez320 opened this issue · comments

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:

tview/textview.go

Line 1279 in b3bd1aa

if key == tcell.KeyEscape || key == tcell.KeyEnter || key == tcell.KeyTab || key == tcell.KeyBacktab {
).

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.

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?

@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!

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

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