fdehau / tui-rs

Build terminal user interfaces and dashboards using Rust
MIT License
10.83k stars 483 forks source link

Is there a way to select text in a paragraph? #289

Closed empath-75 closed 1 year ago

empath-75 commented 4 years ago

Let's say I have some text I want to the user to be able to select in a long paragraph. I've figured out how to move the cursor around and scroll, but I can't figure out how to tell what is currently in the view port under a cursor -- is there any function that returns that?

DarrienG commented 4 years ago

If you are willing to "lie" about the cursor being the cursor and instead do the highlighting yourself (by setting the background color and watching where the user moves the cursor) you can simulate what you're trying to do. We do this at https://gitlab.com/ttyperacer/terminal-typeracer for a slightly different purpose.

The solution isn't perfectly clean, but it works if you need something.

It's worth noting there may be a better answer, but I am unaware of any.