Improve ANSI escape sequence parsing