iox/ANSI.cs
/// <summary>
/// Purify a string by removing all ANSI escapes.
/// </summary>
/// <returns>The purify.</returns>
/// <param name="str">String.</param>
Purify a string by removing all ANSI escapes.
Purify a string by removing all ANSI escapes .
public static string Purify (string str) {
			var receivedEscape = false;
			var inEscapeSequence = false;
			var escapeSequenceFinished = false;
			var accum = new StringBuilder ();
			foreach (var chr in str) {
				if (escapeSequenceFinished) {
					escapeSequenceFinished = false;
				}
				if (inEscapeSequence) {
					if (chr != 'm') {
						continue;
					}
					escapeSequenceFinished = true;
					inEscapeSequence = false;
					continue;
				}
				if (receivedEscape) {
					receivedEscape = false;
					if (chr == '[') {
						inEscapeSequence = true;
						continue;
					}
				}
				if (chr == ESC) {
					receivedEscape = true;
					continue;
				}
				accum.Append (chr);
			}
			return accum.ToString ();
		}
public static string Purify ( string str ) { var receivedEscape = false ; var inEscapeSequence = false ; var escapeSequenceFinished = false ; var accum = new StringBuilder ( ) ; foreach ( var chr in str ) { if ( escapeSequenceFinished ) { escapeSequenceFinished = false ; } if ( inEscapeSequence ) { if ( chr != ' ' ) { continue ; } escapeSequenceFinished = true ; inEscapeSequence = false ; continue ; } if ( receivedEscape ) { receivedEscape = false ; if ( chr == ' ' ) { inEscapeSequence = true ; continue ; } } if ( chr == ESC ) { receivedEscape = true ; continue ; } accum . Append ( chr ) ; } return accum . ToString ( ) ; }
Purify a string by removing all ANSI escapes.
Purify a string by removing all ANSI escapes .
// Initialize state // Iterate over all characters // Test if an escape sequence is ready to be printed // Test if we're inside of an escape sequence // Test if we're at the end of the sequence // Update state // Test if we've received the escape character // Test for ANSI escape character // Nothing special, just print the char
None
str
string
None