fn prepare_str(content: &str, width: usize, height: usize, x: u16, y: u16) -> String {
        const CSI_SGR_START: char = '\x1b';
        const CSI_SGR_END: char = 'm';

        let mut res = String::with_capacity(content.len() * 2);
        // Set cursor to cell top left corner
        res.push_str(&cursor::Goto(x, y).to_string());

        let mut line_start = 0;
        let mut ch_count = 0;
        let mut is_csi = false;
        let mut y = y;
        let mut height = height;
        for (i, ch) in UnicodeSegmentation::grapheme_indices(content, true) {
            if ch.as_bytes()[0] as char == CSI_SGR_START {
                is_csi = true;
            } else if is_csi && ch.as_bytes()[0] as char == CSI_SGR_END {
                is_csi = false;
            } else if !is_csi {
                ch_count += 1;
                if ch_count == width {
                    res.push_str(&content[line_start..i + ch.len()]);
                    ch_count = 0;
                    line_start = i + ch.len();
                    y += 1;
                    height -= 1;
                    if height > 0 {
                        res.push_str(&cursor::Goto(x, y).to_string());
                    } else {
                        break;
                    }
                }
            }
        }
        // Reset all styles at the end
        res.push_str(&style::Reset.to_string());
        res
    }
// Split cell content string into lines and add Goto sequences. Add style reset at the end.
Split cell content string into lines and add Goto sequences. Add style reset at the end.
Split cell content string into lines and add Goto sequences . Add style reset at the end .
fn prepare_str(content: &str, width: usize, height: usize, x: u16, y: u16) -> String {
        const CSI_SGR_START: char = '\x1b';
        const CSI_SGR_END: char = 'm';
        let mut res = String::with_capacity(content.len() * 2);
        // Set cursor to cell top left corner
        res.push_str(&cursor::Goto(x, y).to_string());
        let mut line_start = 0;
        let mut ch_count = 0;
        let mut is_csi = false;
        let mut y = y;
        let mut height = height;
        for (i, ch) in UnicodeSegmentation::grapheme_indices(content, true) {
            if ch.as_bytes()[0] as char == CSI_SGR_START {
                is_csi = true;
            } else if is_csi && ch.as_bytes()[0] as char == CSI_SGR_END {
                is_csi = false;
            } else if !is_csi {
                ch_count += 1;
                if ch_count == width {
                    res.push_str(&content[line_start..i + ch.len()]);
                    ch_count = 0;
                    line_start = i + ch.len();
                    y += 1;
                    height -= 1;
                    if height > 0 {
                        res.push_str(&cursor::Goto(x, y).to_string());
                    } else {
                        break;
                    }
                }
            }
        }
        // Reset all styles at the end
        res.push_str(&style::Reset.to_string());
        res
    }
fn prepare_str ( content : & str , width : usize , height : usize , x : u16 , y : u16 ) -> String { const CSI_SGR_START : char = '\x1b' ; const CSI_SGR_END : char = 'm' ; let mut res = String :: with_capacity ( content . len ( ) * 2 ) ; // Set cursor to cell top left corner res . push_str ( & cursor :: Goto ( x , y ) . to_string ( ) ) ; let mut line_start = 0 ; let mut ch_count = 0 ; let mut is_csi = false ; let mut y = y ; let mut height = height ; for ( i , ch ) in UnicodeSegmentation :: grapheme_indices ( content , true ) { if ch . as_bytes ( ) [ 0 ] as char == CSI_SGR_START { is_csi = true ; } else if is_csi && ch . as_bytes ( ) [ 0 ] as char == CSI_SGR_END { is_csi = false ; } else if ! is_csi { ch_count += 1 ; if ch_count == width { res . push_str ( & content [ line_start .. i + ch . len ( ) ] ) ; ch_count = 0 ; line_start = i + ch . len ( ) ; y += 1 ; height -= 1 ; if height > 0 { res . push_str ( & cursor :: Goto ( x , y ) . to_string ( ) ) ; } else { break ; } } } } // Reset all styles at the end res . push_str ( & style :: Reset . to_string ( ) ) ; res }
Split cell content string into lines and add Goto sequences.
Split cell content string into lines and add Goto sequences .
content
&str
width
usize
height
usize
x
u16
y
u16
content
&str
width
usize
height
usize
x
u16
y
u16