Skip to main content

push_str_cells_sgr

Function push_str_cells_sgr 

Source
pub fn push_str_cells_sgr(
    row: &mut Vec<Cell>,
    s: &str,
    working_style: CellStyle,
) -> CellStyle
Expand description

Like push_str_cells but parses embedded SGR escape sequences (\x1b[...m) inline, mutating a working CellStyle so subsequent cells pick up the colour / bold / faint / reverse attributes the terminal would otherwise paint via raw ANSI. Returns the style state at end-of-input so a caller wrapping a single physical line into multiple chunks can carry attributes across chunk boundaries (e.g. \x1b[31m on one chunk and \x1b[39m on the next).

Why this exists: the retained renderer paints from a cell grid rather than streaming raw bytes to stdout, so SGR sequences that survive crate::sanitize::scrub_controls_keep_sgr would otherwise land as literal ^[[31m characters in cells. This function is the cell-pipeline equivalent of alt-screen’s truncate_to_width_sgr_aware — it understands SGR enough to translate it into CellStyle mutations on the way in.

Non-SGR CSI sequences (cursor moves, DSR, etc.) are silently dropped — they should have been scrubbed upstream; this is belt-and-suspenders.