[GH-ISSUE #22] Watch for additional keys for making cell, row or column selection #16

Closed
opened 2026-03-04 01:01:09 +03:00 by kerem · 1 comment
Owner

Originally created by @andrewuhl on GitHub (Jan 13, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/22

Currently, table watches for ENTER key press to enter the table for selection of cell/row/column. It would be useful to have an additional key (or keys) watched so that, e.g., one key could be captured to make a full row selection, while different (possibly user-defined) key(s) could be captured to make a full column selection: E.g.

table.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) {
		if key == tcell.KeyEscape {
			table.SetSelectable(false, false)
		} else if key == tcell.KeyEnter { // select row
			table.SetSelectable(true, false)
		} else if key == tcell.KeyBackspace { // select column, requires changes to table.go
			table.SetSelectable(false, true)
		}
	})
Originally created by @andrewuhl on GitHub (Jan 13, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/22 Currently, table watches for ENTER key press to enter the table for selection of cell/row/column. It would be useful to have an additional key (or keys) watched so that, e.g., one key could be captured to make a full row selection, while different (possibly user-defined) key(s) could be captured to make a full column selection: E.g. ```go table.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) { if key == tcell.KeyEscape { table.SetSelectable(false, false) } else if key == tcell.KeyEnter { // select row table.SetSelectable(true, false) } else if key == tcell.KeyBackspace { // select column, requires changes to table.go table.SetSelectable(false, true) } }) ```
kerem closed this issue 2026-03-04 01:01:09 +03:00
Author
Owner

@rivo commented on GitHub (Jan 14, 2018):

Sorry for the late response. I had to think about this a bit. And this was related to an internal todo I've had in mind for a while. Many primitives offer a default key handling, e.g. the TextView allows you to navigate the view's content in a Vim-like fashion. This may not be what you want so you should be able to change that handling or install a custom key event handler for additional functionality (like you suggested).

The Box primitive now has a function SetInputCapture() which allows you to intercept any key events sent to a primitive. Because Box is the superclass of all other primitives, this is available to all of them.

Btw, The same function also exists for Application, allowing you to intercept all key events. (This was previously SetKeyCapture() which has been removed in favour of this new function.)

Anyway, using those new functions, you should be able to achieve what you described.

<!-- gh-comment-id:357541392 --> @rivo commented on GitHub (Jan 14, 2018): Sorry for the late response. I had to think about this a bit. And this was related to an internal todo I've had in mind for a while. Many primitives offer a default key handling, e.g. the `TextView` allows you to navigate the view's content in a Vim-like fashion. This may not be what you want so you should be able to change that handling or install a custom key event handler for additional functionality (like you suggested). The `Box` primitive now has a function `SetInputCapture()` which allows you to intercept any key events sent to a primitive. Because `Box` is the superclass of all other primitives, this is available to all of them. Btw, The same function also exists for `Application`, allowing you to intercept *all* key events. (This was previously `SetKeyCapture()` which has been removed in favour of this new function.) Anyway, using those new functions, you should be able to achieve what you described.
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#16
No description provided.