Add JSDoc to splitAnsiCarryover function

This commit is contained in:
Jared Miller 2026-01-31 09:10:07 -05:00
parent a8eea4e694
commit c09654c6c7
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -81,8 +81,22 @@ function broadcastSSE(event: SSEEvent): void {
} }
} }
// Detect and split any incomplete ANSI control sequence at the end of a chunk. /**
// Returns [body, carry] where carry should be saved and prepended to the next chunk. * Detect and split any incomplete ANSI control sequence at the end of a chunk.
*
* ANSI sequences can span multiple network packets. This function identifies
* incomplete sequences at the end of a chunk to prevent them from being
* rendered as partial/broken control codes.
*
* @param chunk - Raw output string potentially containing ANSI sequences
* @returns Tuple of [body, carry] where:
* - body: Complete portion safe to render
* - carry: Incomplete sequence to prepend to next chunk
*
* @example
* const [body, carry] = splitAnsiCarryover("hello\x1b[31");
* // body = "hello", carry = "\x1b[31"
*/
function splitAnsiCarryover(chunk: string): [string, string] { function splitAnsiCarryover(chunk: string): [string, string] {
if (!chunk) return ["", ""]; if (!chunk) return ["", ""];