/// <summary> /// Does the actual writing. /// </summary> /// <param name="text">The text.</param> /// <param name="style">The style.</param> private void WriteInternal(string text, Style style) { bool withNewLine = false; if (text.EndsWith(Environment.NewLine)) { withNewLine = true; text = text.TrimEnd(); } var line = new Paragraph(); // format timestamp color if (TimestampEnabled && style != Style.Prompt) { string timestamp = string.Format("[{0:H:mm:ss}] ", DateTime.Now); line.Inlines.Add(new Run(timestamp) { Foreground = timestampColor }); } // format chatroom room color if (text.StartsWith("[#")) { int endIndex = text.IndexOf("]"); string roomToken = text.Substring(0, endIndex).Trim('[', ']'); text = text.Remove(0, endIndex + 1); line.Inlines.Add(new Run("[") { Foreground = Brushes.White }); line.Inlines.Add(new Run(roomToken) { Foreground = Brushes.DarkCyan }); line.Inlines.Add(new Run("]") { Foreground = Brushes.White }); } Brush outColor = this.outColor; if (text.StartsWith("===")) outColor = Brushes.Yellow; else if (TimestampEnabled && text.StartsWith("***")) outColor = Brushes.Cyan; switch (style) { case Style.Prompt: WriteColor(line, text, promptColor, withNewLine); break; case Style.Out: WriteColor(line, text, outColor, withNewLine); break; case Style.Error: WriteColor(line, text, errorColor, withNewLine); break; case Style.Warning: WriteColor(line, text, warningColor, withNewLine); break; } Logger.Info(string.Format("Console> {0}", text)); }
/// <summary> /// Writes the text to the console with the provided style. /// </summary> /// <param name="text">Text to write.</param> /// <param name="style">Style for text.</param> public void Write(string text, Style style) { dispatcher.CheckBeginInvokeOnUI(() => { WriteInternal(text, style); }); }
/// <summary> /// Writes the text on a line to the console with the provided style. /// </summary> /// <param name="text">The text.</param> /// <param name="style">The style.</param> public void WriteLine(string text, Style style = Style.Out) { Write(text + Environment.NewLine, style); }