Beispiel #1
0
        /// <summary>
        /// Pretty format the specified object.
        /// </summary>
        /// <returns>The format.</returns>
        /// <param name="obj">Object.</param>
        public static string Format(IodineObject obj)
        {
            // Get the type of the object
            var type = obj.GetType();

            // Exceptions are special snowflakes
            if (obj.Base?.GetType().Name == "IodineException")
            {
                type = obj.Base.GetType();
            }

            // Try getting the formatting color
            ANSIColor color;

            ColorScheme.TryGetValue(type, out color);

            // Test if the object has a custom formatter
            if (Formatters.ContainsKey(type))
            {
                // Invoke the formatter
                return(ANSI.Sanitize(Formatters [type] (obj, color?.fg ?? string.Empty, $"{ANSI.ESC}[0m")));
            }

            // Oops, there's no custom formatter for that object
            Logger.Warn($"No formatter for type '{type.Name}'");
            return(ANSI.Sanitize($"{color ?? White}{obj}"));
        }
Beispiel #2
0
 /// <summary>
 /// Convert the powerline to an ANSI string.
 /// </summary>
 /// <returns>The ANSI string.</returns>
 public string ToAnsiString() => ANSI.Sanitize($"{Builder}{lastbg.fg}{ANSI.ESC}[49m{PLColor}");