fn annotate_line_numbers(
    mut lines: Vec<Vec<String>>,
    len_line_number: usize,
    cols: usize,
    #[cfg(feature = "search")] search_term: &Option<regex::Regex>,
) -> Vec<String> {
    // Calculate the amount of space required for the numbering ie. length of line
    // numbers + . + 2 spaces and wrap according to it
    let padding = len_line_number + 3;
    for (idx, line) in lines.iter_mut().enumerate() {
        crate::rewrap(line, cols.saturating_sub(padding));

        // Insert the line numbers
        #[cfg_attr(not(feature = "search"), allow(unused_mut))]
        for mut row in line.iter_mut() {
            #[cfg(feature = "search")]
            if let Some(st) = search_term {
                // Highlight the lines
                highlight_line_matches(&mut row, st);
            }
            // Make the formatted text
            // If function is called in a test run, reove the bold and reset
            // sequences because at that time we care more about correctness than
            // formatting
            let fmt_numbers = if cfg!(not(test)) {
                format!(
                    " {bold}{number: >len$}.{reset} ",
                    bold = crossterm::style::Attribute::Bold,
                    number = idx + 1,
                    len = len_line_number,
                    reset = crossterm::style::Attribute::Reset
                )
            } else {
                format!(
                    " {number: >len$}. ",
                    number = idx + 1,
                    len = len_line_number,
                )
            };
            // Insert line numbers at the beginning
            row.insert_str(0, &fmt_numbers);
        }
    }

    // Return the flattened lines
    lines.iter().flatten().map(ToOwned::to_owned).collect()
}
// Add line numbers to all the lines taking into considerations the wraps
Add line numbers to all the lines taking into considerations the wraps
Add line numbers to all the lines taking into considerations the wraps
fn annotate_line_numbers(
    mut lines: Vec<Vec<String>>,
    len_line_number: usize,
    cols: usize,
    #[cfg(feature = "search")] search_term: &Option<regex::Regex>,
) -> Vec<String> {
    // Calculate the amount of space required for the numbering ie. length of line
    // numbers + . + 2 spaces and wrap according to it
    let padding = len_line_number + 3;
    for (idx, line) in lines.iter_mut().enumerate() {
        crate::rewrap(line, cols.saturating_sub(padding));
        // Insert the line numbers
        #[cfg_attr(not(feature = "search"), allow(unused_mut))]
        for mut row in line.iter_mut() {
            #[cfg(feature = "search")]
            if let Some(st) = search_term {
                // Highlight the lines
                highlight_line_matches(&mut row, st);
            }
            // Make the formatted text
            // If function is called in a test run, reove the bold and reset
            // sequences because at that time we care more about correctness than
            // formatting
            let fmt_numbers = if cfg!(not(test)) {
                format!(
                    " {bold}{number: >len$}.{reset} ",
                    bold = crossterm::style::Attribute::Bold,
                    number = idx + 1,
                    len = len_line_number,
                    reset = crossterm::style::Attribute::Reset
                )
            } else {
                format!(
                    " {number: >len$}. ",
                    number = idx + 1,
                    len = len_line_number,
                )
            };
            // Insert line numbers at the beginning
            row.insert_str(0, &fmt_numbers);
        }
    }
    // Return the flattened lines
    lines.iter().flatten().map(ToOwned::to_owned).collect()
}
fn annotate_line_numbers ( mut lines : Vec < Vec < String > > , len_line_number : usize , cols : usize , # [ cfg ( feature " " ) ] search_term : & Option < regex :: Regex > , ) -> Vec < String > { // Calculate the amount of space required for the numbering ie. length of line // numbers + . + 2 spaces and wrap according to it let padding = len_line_number + 3 ; for ( idx , line ) in lines . iter_mut ( ) . enumerate ( ) { crate :: rewrap ( line , cols . saturating_sub ( padding ) ) ; // Insert the line numbers # [ cfg_attr ( not ( feature " " ) allow ( unused_mut ) ) ] for mut row in line . iter_mut ( ) { # [ cfg ( feature " " ) ] if let Some ( st ) = search_term { // Highlight the lines highlight_line_matches ( & mut row , st ) ; } // Make the formatted text // If function is called in a test run, reove the bold and reset // sequences because at that time we care more about correctness than // formatting let fmt_numbers = if cfg ! ( not ( test ) ) { format ! ( " " bold crossterm style Attribute Bold number idx 1 len len_line_number reset crossterm style Attribute Reset ) } else { format ! ( " " number idx 1 len len_line_number ) } ; // Insert line numbers at the beginning row . insert_str ( 0 , & fmt_numbers ) ; } } // Return the flattened lines lines . iter ( ) . flatten ( ) . map ( ToOwned :: to_owned ) . collect ( ) }
Add line numbers to all the lines taking into considerations the wraps
Add line numbers to all the lines taking into considerations the wraps
lines
Vec<Vec<String>>
len_line_number
usize
cols
usize
search_term
&Option<regex::Regex>
lines
Vec<Vec<String>>
len_line_number
usize
cols
usize
search_term
&Option<regex::Regex>