Parse OSC codes in escape_code_length(). They begin with <esc> ] and are terminated with ST (<esc> backslash) or BEL (ASCII 7).
Fix up OSC / iTerm2 escape code parsing as part of #1565