Exemplo n.º 1
0
        public ConsoleColor ToConsoleColor()
        {
            var @this = this;

            if (!ColorCache.TryGetValue(this, out var retClr))
            {
                ColorCache[this] = retClr = Get();
            }

            return(retClr);

            ConsoleColor Get()
            {
                ConsoleColor ret = 0;
                double       rr = @this.R, gg = @this.G, bb = @this.B, delta = double.MaxValue;

                foreach (ConsoleColor cc in Enum.GetValues(typeof(ConsoleColor)))
                {
                    var n = Enum.GetName(typeof(ConsoleColor), cc);
                    var c = CColor.FromName(n == "DarkYellow" ? "Orange" : n); // bug fix
                    var t = Math.Pow(c.R - rr, 2.0) + Math.Pow(c.G - gg, 2.0) + Math.Pow(c.B - bb, 2.0);
                    if (t == 0.0)
                    {
                        return(cc);
                    }
                    if (t < delta)
                    {
                        delta = t;
                        ret   = cc;
                    }
                }
                return(ret);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Writes a colored string, delimited by a newline separator at the end.
        /// </summary>
        /// <param name="str">The line to write.</param>
        /// <param name="color">The color to write this line in.</param>
        public static void WriteLine(string str, CColor color)
        {
            lock (LineLock)
            {
                LineWritten(str);

                Frontend.PauseInput();
                Frontend.WriteLine(str, color);
                Frontend.ResumeInput();
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Writes a colored string, delimited by a newline separator at the end.
 /// </summary>
 /// <param name="obj">The line to write.</param>
 public static void WriteLine(object obj, CColor color) => WriteLine(obj?.ToString(), color);
Exemplo n.º 4
0
 internal static void Write(string format, CColor color, params object[] args) => Write(string.Format(format, args), color);
Exemplo n.º 5
0
 internal static void Write(string str, CColor color) => Frontend.Write(str, color);
Exemplo n.º 6
0
 /// <summary>
 /// Writes a colored formatted string, delimited by a newline separator at the end.
 /// </summary>
 /// <param name="format">The format string.</param>
 /// <param name="color">The color to write this line in.</param>
 /// <param name="args">The arguments to format the string with.</param>
 public static void WriteLine(string format, CColor color, params object[] args) => WriteLine(string.Format(format, args), color);