From: Thomas Csovcsity <thc.fr13nd@gmail.com> Remove Control Sequence Introducer(CSI) commands avoids console scrambling --- programs/conhost/conhost.c | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/programs/conhost/conhost.c b/programs/conhost/conhost.c index 8298743553f..6bf81f97407 100644 --- a/programs/conhost/conhost.c +++ b/programs/conhost/conhost.c @@ -2107,6 +2107,9 @@ static NTSTATUS write_console( struct screen_buffer *screen_buffer, const WCHAR { RECT update_rect; size_t i, j; + enum { + ST_START, ST_PARAM, ST_INTER, ST_FINAL + } state; TRACE( "%s\n", debugstr_wn(buffer, len) ); @@ -2143,6 +2146,63 @@ static NTSTATUS write_console( struct screen_buffer *screen_buffer, const WCHAR case '\r': screen_buffer->cursor_x = 0; continue; + case '\e': + if ( buffer[i+1] == '[') + { + FIXME( "CSI sequences not supported fully yet, only skipping control sequences\n" ); + state = ST_PARAM; + i+=2; + } + else + { + ERR("Invalid CSI start sequence\n"); + break; + } + /* intermediate bytes 0x30 - 0x3f (0-?) */ + for (; i<len && (state == ST_PARAM); i++) + { + switch (buffer[i]) + { + case 0x30 ... 0x3b: + continue; + case 0x3c ... 0x3f: /* private for terminal manufacturers */ + WARN("This is a private -terminal manufacturer only- CSI sequence\n"); + continue; + default: + state = ST_INTER; + break; + } + break; + } + /* intermediate bytes 0x20 - 0x2f*/ + for (; i<len && (state == ST_INTER || state == ST_PARAM); i++) + { + switch (buffer[i]) + { + case 0x20 ... 0x2f: + continue; + default: + state = ST_FINAL; + break; + } + break; + } + if ( state == ST_START || state == ST_FINAL ) + { + switch (buffer[i]) + { + case 0x40 ... 0x6F: + break; + case 0x70 ... 0x7E: /* private for terminal manufacturers */ + WARN("This is a private -terminal manufacturer only- CSI sequence\n"); + break; + default: + ERR("This was no valid CSI sequence\n"); + break; + } + i++; + break; + } } } if (screen_buffer->cursor_x == screen_buffer->width && !(screen_buffer->mode & ENABLE_WRAP_AT_EOL_OUTPUT)) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9973