charmbracelet/bubbletea

Add support for setting terminal cursor position

indiejames opened this issue · 3 comments

Is your feature request related to a problem? Please describe.
I am unable to set the terminal cursor position reliably (the real one, not the one rendered by the TextArea bubble). I have tried using direct ANSI escape codes as well as instantiating a separate termenv Output structure. In both cases the cursor can be moved, but as soon as I render anything with my View method the cursor pops back down to the bottom left corner of the terminal.

Note that I am able to make the cursor visible by returning a tea.ShowCursor message from my Update method.

Describe the solution you'd like
I would like to see a new command generator function added to the API, similar to the SetWindowTitle function. Perhaps

func SetCursorPosition(row int, column int) Cmd

Using this function should set the position of the cursor and it should stay in that position until the method is called again.

Describe alternatives you've considered
I know that the TextArea bubble uses a rendered cursor by setting a background color on the character at the cursor position. This works for a block cursor, and an underscore cursor could work similarly, but I'm not aware of a way to render a bar cursor (vertical line to the left of the character under the cursor) with this approach.

Additional context
Add any other context or screenshots about the feature request here.

I don't think this is something we'll support, sorry. For the tea renderer to work, it needs to reset the cursor position before rendering.

Contextual note here that we should ultimately support this for IME (see #874) — however we'll need to reexamine the renderer to get there and I don't see that happening in the short term.

Thanks for the feedback. I have moved on to tview/tcell for my application, although I still love bubbletea and would use it if I could control the cursor. But I understand that this is not a priority for most users. Feel free to close this issue or leave it open as you see fit.