Function cansi::line_iter

source ·
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>;
👎Deprecated: please use v3::line_iter to move to API v3.0. this function will be removed with v3.0 of cansi
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.


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 =;
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(&, "how are you");
assert_eq!(&construct_text_no_codes(&, "today");
assert_eq!(, None);