private void AppendText(string text, OutputEntryKind kind, InteractiveWindowColor color) { var newProps = new OutputEntryProperties(kind, color); if (_outputEntries.Count == 0 || _outputEntries[_outputEntries.Count - 1].Properties != newProps) { _outputEntries.Add(new OutputEntry(newProps)); } var buffer = _outputEntries[_outputEntries.Count - 1].Buffer; buffer.Append(text); }
public OutputEntryProperties(OutputEntryKind kind, ConsoleColor color) { Kind = kind; Color = color; }
private void AppendText(string text, OutputEntryKind kind, ConsoleColor color) { var newProps = new OutputEntryProperties(kind, color); if (_outputEntries.Count == 0 || _outputEntries[_outputEntries.Count - 1].Properties != newProps) { _outputEntries.Add(new OutputEntry(newProps)); } var buffer = _outputEntries[_outputEntries.Count - 1].Buffer; buffer.Append(text); }
private void AppendEscapedText(string text, bool isError, int escape) { OutputEntryKind kind = isError ? OutputEntryKind.StdErr : OutputEntryKind.StdOut; InteractiveWindowColor color = isError ? _errColor : _outColor; // http://en.wikipedia.org/wiki/ANSI_escape_code // process any ansi color sequences... int start = 0; List <int> codes = new List <int>(); do { if (escape != start) { // add unescaped text AppendText(text.Substring(start, escape - start), kind, color); } // process the escape sequence if (escape < text.Length - 1 && text[escape + 1] == '[') { // We have the Control Sequence Introducer (CSI) - ESC [ codes.Clear(); int?value = 0; for (int i = escape + 2; i < text.Length; i++) { // skip esc + [ if (text[i] >= '0' && text[i] <= '9') { // continue parsing the integer... if (value == null) { value = 0; } value = 10 * value.Value + (text[i] - '0'); } else if (text[i] == ';') { if (value != null) { codes.Add(value.Value); value = null; } else { // CSI ; - invalid or CSI ### ;;, both invalid break; } } else if (text[i] == 'm') { if (value != null) { codes.Add(value.Value); } // parsed a valid code start = i + 1; if (codes.Count == 0) { // reset color = isError ? _errColor : _outColor; } else { for (int j = 0; j < codes.Count; j++) { switch (codes[j]) { case 0: color = InteractiveWindowColor.White; break; case 1: // bright/bold color |= InteractiveWindowColor.DarkGray; break; case 2: // faint case 3: // italic case 4: // single underline break; case 5: // blink slow case 6: // blink fast break; case 7: // negative case 8: // conceal case 9: // crossed out case 10: // primary font case 11: // 11-19, n-th alternate font break; case 21: // bright/bold off case 22: // normal intensity color &= ~InteractiveWindowColor.DarkGray; break; case 24: // underline off break; case 25: // blink off break; case 27: // image - postive case 28: // reveal case 29: // not crossed out case 30: color = InteractiveWindowColor.Black | (color & InteractiveWindowColor.DarkGray); break; case 31: color = InteractiveWindowColor.DarkRed | (color & InteractiveWindowColor.DarkGray); break; case 32: color = InteractiveWindowColor.DarkGreen | (color & InteractiveWindowColor.DarkGray); break; case 33: color = InteractiveWindowColor.DarkYellow | (color & InteractiveWindowColor.DarkGray); break; case 34: color = InteractiveWindowColor.DarkBlue | (color & InteractiveWindowColor.DarkGray); break; case 35: color = InteractiveWindowColor.DarkMagenta | (color & InteractiveWindowColor.DarkGray); break; case 36: color = InteractiveWindowColor.DarkCyan | (color & InteractiveWindowColor.DarkGray); break; case 37: color = InteractiveWindowColor.Gray | (color & InteractiveWindowColor.DarkGray); break; case 38: // xterm 286 background color case 39: // default text color color = _outColor; break; case 40: // background colors case 41: case 42: case 43: case 44: case 45: case 46: case 47: break; case 90: color = InteractiveWindowColor.DarkGray; break; case 91: color = InteractiveWindowColor.Red; break; case 92: color = InteractiveWindowColor.Green; break; case 93: color = InteractiveWindowColor.Yellow; break; case 94: color = InteractiveWindowColor.Blue; break; case 95: color = InteractiveWindowColor.Magenta; break; case 96: color = InteractiveWindowColor.Cyan; break; case 97: color = InteractiveWindowColor.White; break; } } } break; } else { // unknown char, invalid escape break; } } escape = text.IndexOf('\x1b', escape + 1); }// else not an escape sequence, process as text } while (escape != -1); if (start != text.Length) { AppendText(text.Substring(start), kind, color); } }
public OutputEntryProperties(OutputEntryKind kind, InteractiveWindowColor color) { Kind = kind; Color = color; }
public OutputEntryProperties(OutputEntryKind kind, ConsoleColor color) { Kind = kind; Color = color; }