[GH-ISSUE #937] Support more key press types for SetDoneFunc #685

Closed
opened 2026-03-04 01:07:02 +03:00 by kerem · 4 comments
Owner

Originally created by @spacez320 on GitHub (Jan 12, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/937

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: github.com/rivo/tview@b3bd1aa5e9/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.

Originally created by @spacez320 on GitHub (Jan 12, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/937 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.
kerem closed this issue 2026-03-04 01:07:02 +03:00
Author
Owner

@rivo commented on GitHub (Jan 13, 2024):

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?

<!-- gh-comment-id:1890448115 --> @rivo commented on GitHub (Jan 13, 2024): 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 <kbd>Home</kbd> or <kbd>Del</kbd> 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 <kbd>Home</kbd> key [already works](https://pkg.go.dev/github.com/rivo/tview#hdr-Navigation) in a `TextView`. I'm not sure what <kbd>Del</kbd> 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?
Author
Owner

@spacez320 commented on GitHub (Jan 13, 2024):

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

<!-- gh-comment-id:1890473307 --> @spacez320 commented on GitHub (Jan 13, 2024): @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!
Author
Owner

@rivo commented on GitHub (Jan 13, 2024):

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

<!-- gh-comment-id:1890475152 --> @rivo commented on GitHub (Jan 13, 2024): I think you'll want to use [`SetInputCapture`](https://pkg.go.dev/github.com/rivo/tview#Box.SetInputCapture). That's the preferred method to add custom key binds to a widget.
Author
Owner

@spacez320 commented on GitHub (Jan 13, 2024):

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

<!-- gh-comment-id:1890475917 --> @spacez320 commented on GitHub (Jan 13, 2024): I will give this a shot, thanks for the guidance @rivo . Also great work on the project.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#685
No description provided.