Class CliColorMapper
- Namespace
- ItTiger.TigerCli.Primitives
- Assembly
- ItTiger.TigerCli.dll
Converts between TigerCli's CliColor palette and the legacy
ConsoleColor API, and parses raw color names used by markup.
public static class CliColorMapper
- Inheritance
-
CliColorMapper
- Inherited Members
Remarks
The mapper intentionally knows only the built-in CliColor enum names.
Application color aliases are resolved by the markup layer before this fallback.
Methods
FromConsoleColorOrNull(ConsoleColor)
Converts a ConsoleColor read from the current console state to a
CliColor, returning
null when the value is not a valid standard color.
Only the 16 standard console colors (numeric 0–15) map to a CliColor.
ForegroundColor/BackgroundColor can report an
out-of-range sentinel (e.g. -1) when the console color is unavailable — typically on
Linux with redirected/captured output. Such a value must be treated as "no color" rather than
cast blindly into an invalid CliColor that later throws in the palette.
public static CliColor? FromConsoleColorOrNull(ConsoleColor color)
Parameters
colorConsoleColor
Returns
ToCliColor(ConsoleColor)
Converts a standard ConsoleColor value to the matching CliColor.
public static CliColor ToCliColor(ConsoleColor color)
Parameters
colorConsoleColor
Returns
ToConsoleColor(CliColor)
Converts a CliColor to a ConsoleColor. The legacy console only
supports the standard 0–15 colors, so ANSI 16–255 values are degraded explicitly to the
nearest standard color (ToNearestStandard(CliColor)) rather than cast to an
out-of-range ConsoleColor (which throws when assigned). 0–15 are unchanged.
public static ConsoleColor ToConsoleColor(CliColor color)
Parameters
colorCliColor
Returns
TryParse(string, out CliColor)
Parses a raw colour name into a CliColor. Only CliColor enum names
are recognized (case-insensitive); TigerCli ships no built-in colour aliases. Application- or
library-defined aliases are an app-scoped concern (see
TigerColorAliasRegistry) and are
applied by CliMarkupParser before this fallback — referencing a library
never mutates the colour vocabulary here.public static bool TryParse(string name, out CliColor color)