1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
public void SetText(string Text) { if (this.Document.Blocks.Count >= MaxRows) { int iRempveNumber = this.Document.Blocks.Count - MaxRows; List<Paragraph> listRemoveTemp = new List<Paragraph>(); foreach (var item in this.Document.Blocks) { if (iRempveNumber > 0) { iRempveNumber--; listRemoveTemp.Add(item as Paragraph); } } if (listRemoveTemp != null && listRemoveTemp.Count >= 1) { foreach (var item in listRemoveTemp) { this.Document.Blocks.Remove(item); } } }
string ansiColor = null; Paragraph paragraph = new Paragraph(); foreach (var item in AnsiHelper.GetAnsiSplit(Text)) { if (item.Contains(AnsiHelper.AnsiStart)) { ansiColor = item; } else { paragraph.Inlines.Add(SetColorFromAnsi(new Run() { Text = item }, ansiColor)); } } this.Document.Blocks.Add(paragraph);
if (this.VerticalOffset / (this.ExtentHeight - this.ActualHeight) >= 0.8 || (this.ExtentHeight - this.ActualHeight) <= this.ActualHeight) { this.ScrollToEnd(); } }
private Run SetColorFromAnsi(Run run, string ansiColor) { if (string.IsNullOrEmpty(ansiColor)) { return run; } var vMatches = Regex.Matches(ansiColor, AnsiHelper.AnsiRegex); if (vMatches != null && vMatches.Count >= 1 && vMatches[0].Groups != null && vMatches[0].Groups.Count >= 2) { var vSplit = vMatches[0].Groups[1].Value.Split(';'); foreach (var item in vSplit) { switch (item) { case "30": run.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0)); break; case "40": run.Background = new SolidColorBrush(Color.FromRgb(0, 0, 0)); break;
case "31": run.Foreground = new SolidColorBrush(Color.FromRgb(128, 0, 0)); break; case "41": run.Background = new SolidColorBrush(Color.FromRgb(128, 0, 0)); break;
case "32": run.Foreground = new SolidColorBrush(Color.FromRgb(0, 128, 0)); break; case "42": run.Background = new SolidColorBrush(Color.FromRgb(0, 128, 0)); break;
case "33": run.Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 0)); break; case "43": run.Background = new SolidColorBrush(Color.FromRgb(128, 128, 0)); break;
case "34": run.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 128)); break; case "44": run.Background = new SolidColorBrush(Color.FromRgb(0, 0, 128)); break;
case "35": run.Foreground = new SolidColorBrush(Color.FromRgb(128, 0, 128)); break; case "45": run.Background = new SolidColorBrush(Color.FromRgb(128, 0, 128)); break;
case "36": run.Foreground = new SolidColorBrush(Color.FromRgb(0, 128, 128)); break; case "46": run.Background = new SolidColorBrush(Color.FromRgb(0, 128, 128)); break;
case "37": run.Foreground = new SolidColorBrush(Color.FromRgb(192, 192, 192)); break; case "47": run.Background = new SolidColorBrush(Color.FromRgb(192, 192, 192)); break;
case "90": run.Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128)); break; case "100": run.Background = new SolidColorBrush(Color.FromRgb(128, 128, 128)); break;
case "91": run.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0)); break; case "101": run.Background = new SolidColorBrush(Color.FromRgb(255, 0, 0)); break;
case "92": run.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0)); break; case "102": run.Background = new SolidColorBrush(Color.FromRgb(0, 255, 0)); break;
case "93": run.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 0)); break; case "103": run.Background = new SolidColorBrush(Color.FromRgb(255, 255, 0)); break;
case "94": run.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 255)); break; case "104": run.Background = new SolidColorBrush(Color.FromRgb(0, 0, 255)); break;
case "95": run.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 255)); break; case "105": run.Background = new SolidColorBrush(Color.FromRgb(255, 0, 255)); break;
case "96": run.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 255)); break; case "106": run.Background = new SolidColorBrush(Color.FromRgb(0, 255, 255)); break;
case "97": run.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); break; case "107": run.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255)); break; default: break; } } } return run; }
|