namespace Spectre.Console { /// /// Represents console capabilities. /// public sealed class Capabilities { /// /// Gets a value indicating whether or not /// the console supports Ansi. /// public bool SupportsAnsi { get; } /// /// Gets a value indicating whether or not /// the console support links. /// /// /// There is probably a lot of room for improvement here /// once we have more information about the terminal /// we're running inside. /// public bool SupportLinks => SupportsAnsi && !LegacyConsole; /// /// Gets the color system. /// public ColorSystem ColorSystem { get; } /// /// Gets a value indicating whether or not /// this is a legacy console (cmd.exe). /// /// /// Only relevant when running on Microsoft Windows. /// public bool LegacyConsole { get; } /// /// Initializes a new instance of the class. /// /// Whether or not ANSI escape sequences are supported. /// The color system that is supported. /// Whether or not this is a legacy console. public Capabilities(bool supportsAnsi, ColorSystem colorSystem, bool legacyConsole) { SupportsAnsi = supportsAnsi; ColorSystem = colorSystem; LegacyConsole = legacyConsole; } /// /// Checks whether the current capabilities supports /// the specified color system. /// /// The color system to check. /// true if the color system is supported, otherwise false. public bool Supports(ColorSystem colorSystem) { return (int)colorSystem <= (int)ColorSystem; } /// public override string ToString() { var supportsAnsi = SupportsAnsi ? "Yes" : "No"; var legacyConsole = LegacyConsole ? "Legacy" : "Modern"; var bits = ColorSystem switch { ColorSystem.NoColors => "1 bit", ColorSystem.Legacy => "3 bits", ColorSystem.Standard => "4 bits", ColorSystem.EightBit => "8 bits", ColorSystem.TrueColor => "24 bits", _ => "?", }; return $"ANSI={supportsAnsi}, Colors={ColorSystem}, Kind={legacyConsole} ({bits})"; } } }