Fix ansi escape sequence handling