Closed joshka closed 6 months ago
It looks like we converged on the same ideas and between the Stylize
trait and the new text!
, line!
and span!
macros, there's only one macro that we haven't brought over the functionality for.
/// Create a [`Vec<Spans>`](ratatui::text::Spans) from lines of a string separated by '\n'
#[macro_export]
macro_rules! split {
($e:expr) => {{
$e.lines()
.map(|l| ::ratatui::text::Spans::from(l))
.collect::<Vec<::ratatui::text::Spans>>()
}};
}
We can bring this over too in the future if we think this is something users might want. I'll close this issue for now.
We can bring this over too in the future if we think this is something users might want. I'll close this issue for now.
Text has functionality to split \n to lines built in, so I think we can skip this probably unless I'm missing something obvious.
The Text
struct in ratatui has functionality to split new line characters?
let lines: Vec<_> = match content.into() {
Cow::Borrowed("") => vec![Line::from("")],
Cow::Borrowed(s) => s.lines().map(Line::from).collect(),
Cow::Owned(s) if s.is_empty() => vec![Line::from("")],
Cow::Owned(s) => s.lines().map(|l| Line::from(l.to_owned())).collect(),
Ah, TIL!
@sophacles wrote a few interesting macros in https://github.com/sophacles/extra-widgets/tree/main/src/text_macros Ref https://github.com/ratatui-org/ratatui/issues/118
These might be good candidates to bring into this repo.
@sophacles, can you clarify these are ok to be MIT licensed to "The Ratatui Developers"