public static bool TryParseEscape(char *buffer, int length, out int charsProcessed) { var parser = new AnsiEscapeParser(buffer, buffer + length); bool wasSuccessful; try { wasSuccessful = parser.TryParseEscape(); } catch (EndOfFileException) { charsProcessed = 0; return(false); } if (!wasSuccessful) { charsProcessed = 0; return(false); } charsProcessed = (int)(parser.Current - buffer) + 1; return(true); }
private unsafe bool TryIncrementColumn( char *buffer, int length, out int charsProcessed, out bool shouldSkip) { charsProcessed = 1; shouldSkip = false; if (length == 0) { return(true); } char c = *buffer; if (c == '\r') { shouldSkip = true; if (length == 1 || buffer[1] != '\n') { return(true); } charsProcessed = 2; return(false); } if (c == '\n') { shouldSkip = true; return(false); } if (c == '\x1b') { if (AnsiEscapeParser.TryParseEscape(buffer, length, out charsProcessed)) { return(true); } // If we couldn't parse the escape sequence then treat it like // every other character. charsProcessed = 1; } if (c == '\b') { if (_columns > 0) { _columns--; } return(true); } if (_columns - 1 == _width) { return(false); } _columns++; return(true); }