[GH-ISSUE #168] Feature request: Expose input field cursor position #133

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

Originally created by @asacainbbc on GitHub (Sep 25, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/168

When using inputfields you may need to know where within the input that the user's cursor is positioned.

An example use-case would be for tab completion of arbitrary words within the input field. Without exposing this from within inputfield the most reasonable course of action would be to wrap it and catch all printable keys (increase cursor position) and then track left/right arrow movements and clamp it to the string's length.

While that is certainly a viable method of tracking the user's cursor I believe that this is standard functionality that should be exposed from within Inputfield itself.

Originally created by @asacainbbc on GitHub (Sep 25, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/168 When using inputfields you may need to know where within the input that the user's cursor is positioned. An example use-case would be for tab completion of arbitrary words within the input field. Without exposing this from within inputfield the most reasonable course of action would be to wrap it and catch all printable keys (increase cursor position) and then track left/right arrow movements and clamp it to the string's length. While that is certainly a viable method of tracking the user's cursor I believe that this is standard functionality that should be exposed from within Inputfield itself.
kerem closed this issue 2026-03-04 01:02:16 +03:00
Author
Owner

@rivo commented on GitHub (Sep 26, 2018):

At the moment, there is no way to move the cursor within an input field without deleting trailing characters. So the solution right now is simple: len(inputField.GetText()) will give you the current cursor position.

But one of my next tasks is to work on #103. I will keep in mind to add a GetCursorPosition() once #103 is implemented.

<!-- gh-comment-id:424652135 --> @rivo commented on GitHub (Sep 26, 2018): At the moment, there is no way to move the cursor within an input field without deleting trailing characters. So the solution right now is simple: `len(inputField.GetText())` will give you the current cursor position. But one of my next tasks is to work on #103. I will keep in mind to add a `GetCursorPosition()` once #103 is implemented.
Author
Owner

@trestletech commented on GitHub (Dec 24, 2019):

Hi. Thanks tons for your work on this package; I'm really enjoying using it.

I came across this request while looking for GetCursorPosition and SetCursorPosition methods on InputField. It looks like the cursor movement functionality that would be needed is already implemented (here) so this might just be a matter of exporting a couple of methods that surface the cursorPos? I'm happy to open a new issue to track this work, but it felt like the original request here actually aligns with what I had in mind. If the straightforward approach is the right one, I'm happy to open a PR.

Perhaps tangential, but I'd love to be able to disable the default set of movement keys that you've defined. If that's something you'd be willing to consider, how would you want that surfaced to the user?

P.S. do you have a "sponsor" page anywhere for this package? I'd love to buy you a beer.

<!-- gh-comment-id:568800640 --> @trestletech commented on GitHub (Dec 24, 2019): Hi. Thanks tons for your work on this package; I'm really enjoying using it. I came across this request while looking for `GetCursorPosition` and `SetCursorPosition` methods on `InputField`. It looks like the cursor movement functionality that would be needed is already implemented ([here](https://github.com/rivo/tview/blob/c3d1d4bcf9d9946928c6e3fb2c0c163afc19e831/inputfield.go#L450)) so this might just be a matter of exporting a couple of methods that surface the `cursorPos`? I'm happy to open a new issue to track this work, but it felt like the original request here actually aligns with what I had in mind. If the straightforward approach is the right one, I'm happy to open a PR. Perhaps tangential, but I'd love to be able to disable the default set of movement keys that you've defined. If that's something you'd be willing to consider, how would you want that surfaced to the user? P.S. do you have a "sponsor" page anywhere for this package? I'd love to buy you a beer.
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#133
No description provided.