2022-05-02 22:24:22 +08:00
|
|
|
use smartstring::{LazyCompact, SmartString};
|
2023-10-21 20:58:36 +08:00
|
|
|
use textwrap::{Options, WordSplitter::NoHyphenation};
|
2022-05-02 22:24:22 +08:00
|
|
|
|
|
|
|
/// Given a slice of text, return the text re-wrapped to fit it
|
|
|
|
/// within the given width.
|
2023-03-08 10:02:11 +08:00
|
|
|
pub fn reflow_hard_wrap(text: &str, text_width: usize) -> SmartString<LazyCompact> {
|
2024-11-21 06:40:43 +08:00
|
|
|
let options = Options::new(text_width)
|
|
|
|
.word_splitter(NoHyphenation)
|
|
|
|
.word_separator(textwrap::WordSeparator::AsciiSpace);
|
2023-10-21 20:58:36 +08:00
|
|
|
textwrap::refill(text, options).into()
|
2022-05-02 22:24:22 +08:00
|
|
|
}
|