[−][src]Function cansi::line_iter
pub fn line_iter<'text, 'iter>(
categorised_slices: &'iter CategorisedSlices<'text>
) -> CategorisedLineIterator<'text, 'iter>ⓘNotable traits for CategorisedLineIterator<'text, 'iter>
impl<'text, 'iter> Iterator for CategorisedLineIterator<'text, 'iter> type Item = CategorisedLine<'text>;
Construct an iterator over each new line (\n or \r\n) and returns the categorised slices within those.
CategorisedSlices that include a new line are split with the same style.
Example
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);