[go: up one dir, main page]

line_iter

Function line_iter 

Source
pub fn line_iter<'text, 'iter>(
    categorised_slices: &'iter CategorisedSlices<'text>,
) -> CategorisedLineIterator<'text, 'iter> 
Expand description

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, Some(Color::Green));

assert_eq!(first[1].text, "world");
assert_eq!(first[1].fg, Some(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);