[−][src]Function cansi::line_iter
ⓘImportant traits for CategorisedLineIterator<'text, 'iter>
pub fn line_iter<'text, 'iter>(
categorised_slices: &'iter CategorisedSlices<'text>
) -> CategorisedLineIterator<'text, 'iter>
Construct an iterator over each new line (\n
or \r\n
) and returns the categorised slices within those.
CategorisedSlice
s that include a new line are split with the same style.
Example
use colored::Colorize; use cansi::*; let s = format!("{}{}\nhow are you\r\ntoday", "hello, ".green(), "world".red()); let cat = categorise_text(&s); let mut iter = line_iter(&cat); let first = iter.next().unwrap(); assert_eq!(first[0].text, "hello, "); assert_eq!(first[0].fg_colour, Color::Green); assert_eq!(first[1].text, "world"); assert_eq!(first[1].fg_colour, Color::Red); assert_eq!(&construct_text_no_codes(&iter.next().unwrap()), "how are you"); assert_eq!(&construct_text_no_codes(&iter.next().unwrap()), "today"); assert_eq!(iter.next(), None);