/// <summary> /// Gets a random combination of colors. /// </summary> /// <param name="random"> /// The <see cref="Random"/> to use when selecting colors. /// </param> /// <returns> /// A <see cref="TerminalColors"/> containing random colors. /// </returns> public static TerminalColors GetRandom(Random random) { TerminalColor foreground = CachedColors[random.Next(0, CachedColors.Count)]; TerminalColor background = CachedColors[random.Next(0, CachedColors.Count)]; return(new TerminalColors(foreground, background)); }
public static void Print(TextWriter writer, LogInfo[] logs) { var count = 0; writer.WriteLine(); writer.WriteLine(string.Empty.PadRight(Console.BufferWidth - 1, '=')); foreach (var item in logs) { if (LogProperties.Limit >= 0 && LogProperties.Limit <= count) { break; } using (TerminalColor.SetForeground(ConsoleColor.Cyan)) { writer.WriteLine($"Revision: {item.Revision}"); } writer.WriteLine($"Author : {item.UserID}"); writer.WriteLine($"Date : {item.DateTime}"); if (IsQuiet == false) { writer.WriteLine(); writer.WriteLine(item.Comment); } writer.WriteLine(string.Empty.PadRight(Console.BufferWidth - 1, '=')); count++; } writer.WriteLine(); }
public void WriteLine(TerminalColor foregroundColor, object value) { lock (_syncRoot) { var originalColor = this.ForegroundColor; this.ForegroundColor = foregroundColor; Console.WriteLine(value); this.ForegroundColor = originalColor; } }
public void WriteLine(TerminalColor foregroundColor, string text) { lock (_syncRoot) { var originalColor = this.ForegroundColor; this.ForegroundColor = foregroundColor; Console.WriteLine(text); this.ForegroundColor = originalColor; } }
public void WriteLine(TerminalColor foregroundColor, string format, params object[] args) { lock (_syncRoot) { var originalColor = this.ForegroundColor; this.ForegroundColor = foregroundColor; Console.WriteLine(format, args); this.ForegroundColor = originalColor; } }
private ConsoleColor ConvertColor(TerminalColor color, ConsoleColor defaultColor) { ConsoleColor result; if (Enum.TryParse <ConsoleColor>(color.ToString(), out result)) { return(result); } else { return(defaultColor); } }
public void Print(Action action) { if (this.isLoaded == false) { using (TerminalColor.SetForeground(ConsoleColor.DarkGray)) { action(); } } else { action(); } }
public void Print(Action action) { if (this.isCategory == true) { using (TerminalColor.SetForeground(ConsoleColor.Cyan)) { action(); } } else { action(); } }
protected override void OnDrawPrompt(TextWriter writer, string prompt) { if (this.IsCommandMode == false) { base.OnDrawPrompt(writer, prompt); } else { if (prompt == string.Empty) { return; } var postfixPattern = string.Join(string.Empty, this.Postfix.Select(item => $"[{item}]")); if (this.commandContext.IsOnline == false) { var match = Regex.Match(prompt, $"(.+)(?<postfix>{postfixPattern})$"); using (TerminalColor.SetForeground(ConsoleColor.Green)) { writer.Write(match.Groups[1].Value); } Console.ResetColor(); writer.Write(match.Groups[2].Value); } else { var uri = new Uri(prompt); //var match = Regex.Match(prompt, $"(.+)([:])({PathUtility.Separator}.*)({postfixPattern})$"); using (TerminalColor.SetForeground(ConsoleColor.Green)) { writer.Write(uri.Scheme); } writer.Write(Uri.SchemeDelimiter); using (TerminalColor.SetForeground(ConsoleColor.Cyan)) { writer.Write(uri.UserInfo); } writer.Write("@"); using (TerminalColor.SetForeground(ConsoleColor.Cyan)) { writer.Write(uri.Host); } Console.ResetColor(); writer.Write(uri.LocalPath); } } }
private static void RegisterTasks(TaskHandler handler) { var helloWorld = new HelloWorld(handler); var userProps = new UserProps(handler); var terminalColor = new TerminalColor(handler); var datePrinterte = new DatePrinter(handler); var largestNumberPrinter = new LargestNumberPrinter(handler); var numberGuesser = new NumberGuesser(handler); var writeFile = new FileStream(handler); var maxCharPrinter = new MaxChar(handler); var multiplicationTable = new MultiplicationTablePrinter(handler); var palindrome = new Palindrome(handler); var arrayBuilder = new ArrayBuilder(handler); var numberBetween = new NumbersBetween(handler); var math = new MathTask(handler); var printOddsAndEvens = new PrintOddsAndEvens(handler); var addNumbers = new AddNumbers(handler); var characterBuilder = new CharacterBuilder(handler); }
private void PrintItem(UserMetaData item, Action action) { if (item.BanInfo.Path != string.Empty) { using (TerminalColor.SetForeground(ConsoleColor.Red)) { action(); } } else if (item.UserState != UserState.Online) { //using (TerminalColor.SetForeground(ConsoleColor.Gray)) { action(); } } else { using (TerminalColor.SetForeground(ConsoleColor.Blue)) { action(); } } }
public ListItem(string text, TerminalColor foregroundColor, TerminalColor backgroundColor) { Text = text; ForegroundColor = foregroundColor; BackgroundColor = backgroundColor; }
public void WriteLine(TerminalColor foregroundColor, string format, params object[] args) { lock(_syncRoot) { var originalColor = this.ForegroundColor; this.ForegroundColor = foregroundColor; Console.WriteLine(format, args); this.ForegroundColor = originalColor; } }
private static Range ParseSpan( string token, ushort startIndexInclusive, ushort endIndexExclusive, TerminalColors defaultColors, ushort defaultDelay) { token = token.Remove(token.Length - 1).Substring(SpanStart.Length); Dictionary <string, List <string> > result = new Dictionary <string, List <string> >(); string[] pairs = token.Split(Space, StringSplitOptions.RemoveEmptyEntries); foreach (string pair in pairs) { string[] components = pair.Split('='); string key = components[0]; if (!result.TryGetValue(key, out List <string> values)) { values = new List <string>(); result[key] = values; } if (components.Length == 2) { string value = components[1]; if (value.Length > 1) { if (value[0] == '"' && value[value.Length - 1] == '"') { value = value.Substring(1, value.Length - 2); } } values.Add(value); } } TerminalColor fg = defaultColors.Foreground; TerminalColor bg = defaultColors.Background; ushort dtime = defaultDelay; foreach (KeyValuePair <string, List <string> > kvp in result) { switch (kvp.Key) { case "fg": if (!Enum.TryParse <TerminalColor>(kvp.Value[0], out fg)) { throw new InvalidOperationException( $"Unrecognized color '{kvp.Value[0]}'"); } break; case "bg": if (!Enum.TryParse <TerminalColor>(kvp.Value[0], out bg)) { throw new InvalidOperationException( $"Unrecognized color '{kvp.Value[0]}'"); } break; case "dtime": dtime = ushort.Parse(kvp.Value[0]); break; default: throw new InvalidOperationException( $"Unrecognized key '{kvp.Key}'"); } } return(new Range( startIndexInclusive, endIndexExclusive, new TerminalColors(fg, bg), dtime)); }
public static extern void SetColor(TerminalColor color);
/// <summary> /// Initializes a new instance of the <see cref="TerminalColors"/> struct. /// </summary> /// <param name="foreground"> /// The foreground (text) color. /// </param> /// <param name="background"> /// The background color. /// </param> public TerminalColors(TerminalColor foreground, TerminalColor background) { this.Foreground = foreground; this.Background = background; }
private ConsoleColor ConvertColor(TerminalColor color, ConsoleColor defaultColor) { ConsoleColor result; if(Enum.TryParse<ConsoleColor>(color.ToString(), out result)) return result; else return defaultColor; }
public void WriteLine(TerminalColor foregroundColor, object value) { lock(_syncRoot) { var originalColor = this.ForegroundColor; this.ForegroundColor = foregroundColor; Console.WriteLine(value); this.ForegroundColor = originalColor; } }
public StatusMessage(string t, TerminalColor col = Info) { color = col; text = t; }
public static TerminalKey Say(string text, TerminalColor col = Info) { StatusMessage msg = new StatusMessage(text); return msg.Run(); }
public void WriteLine(TerminalColor foregroundColor, string text) { lock(_syncRoot) { var originalColor = this.ForegroundColor; this.ForegroundColor = foregroundColor; Console.WriteLine(text); this.ForegroundColor = originalColor; } }