pub fn serialize_patches(patches: &[Patch]) -> Vec<u8> ⓘExpand description
Serialise patches into ANSI bytes with an SGR state machine: emit cursor-position only when we’re jumping, emit SGR only when the outgoing cell’s style differs from the last one we set, and run-pack adjacent same-style patches into contiguous character streams.
Ends with \x1b[0m so the caller’s subsequent writes (body text,
cursor positioning, etc.) start from a clean SGR state — leaving a
bold/reverse bit set across paint boundaries was a class of rare
but hard-to-reproduce “random colour leak” bugs in the old path.