fdehau / tui-rs

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

Get the line number of a string in a paragraph #699

Closed ghost closed 1 year ago

ghost commented 1 year ago

Problem

I am rendering a giant document in a Paragraph widget. I have a search functionality. I'd like to be able to auto-scroll to the most relevant paragraph's title.

Solution

To do so, I need to be able to query the widget for the line number of some string. Since the line numbers change depending on the current size, I cannot determine this independently. This line number should be responsive to size changes.

Alternatives

I tried to predetermine the line number using String.lines(), however, when wrap occurs, this is no longer accurate. I also searched the crate for the functionality but couldn't find it.