protected virtual void FlushTextBuffer(Document doc, Color foregroundColor, Color backgroundColor, StringBuilder buffer) { if (buffer.Length <= 0) { return; } doc.BeginUpdate(); try { var text = buffer.ToString(); /* * var range = doc.AppendText(text); * if (foregroundColor != SystemColors.WindowText || backgroundColor != SystemColors.Window) * { * var cp = doc.BeginUpdateCharacters(range); * try * { * if (foregroundColor != SystemColors.WindowText) * cp.ForeColor = foregroundColor; * if (backgroundColor != SystemColors.Window) * cp.BackColor = backgroundColor; * } * finally * { * doc.EndUpdateCharacters(cp); * } * } * * if (range != null) * { * doc.CaretPosition = range.End; * ScrollToCaret(); * }*/ using (var reader = new StringReader(text)) { ReadOutputBuffer(doc, reader, ScriptOutputType.Text, backgroundColor, foregroundColor); } buffer.Clear(); SCCmdlet.WriteTextToConsole(text); } catch (Exception ex) { ReportError(doc, ex); } finally { doc.EndUpdate(); } }
protected virtual void DoReportError(Document doc, string errorMessage) { var range = doc.AppendText($"ERROR: {errorMessage}{Environment.NewLine}"); var cp = doc.BeginUpdateCharacters(range); try { cp.Reset(); cp.ForeColor = Color.Red; } finally { doc.EndUpdateCharacters(cp); } SCCmdlet.WriteErrorToConsole(errorMessage); }