Class ColorTools
Color tools and management
Inheritance
Namespace: Terminaux.Colors
Assembly: Terminaux.dll
Syntax
public static class ColorTools
Properties
| Edit this page View SourceAllowBackground
Whether applications are allowed to set the current background color or not
Declaration
public static bool AllowBackground { get; set; }
Property Value
Type | Description |
---|---|
bool |
CurrentBackgroundColor
Current background color
Declaration
public static Color CurrentBackgroundColor { get; }
Property Value
Type | Description |
---|---|
Color |
CurrentForegroundColor
Current foreground color
Declaration
public static Color CurrentForegroundColor { get; }
Property Value
Type | Description |
---|---|
Color |
GlobalSettings
Global color settings
Declaration
public static ColorSettings GlobalSettings { get; }
Property Value
Type | Description |
---|---|
ColorSettings |
Methods
| Edit this page View SourceGetGray(Color, ColorContrastType)
Gets the gray color according to the brightness of the specified color
Declaration
public static Color GetGray(Color color, ColorContrastType contrastType = ColorContrastType.Light)
Parameters
Type | Name | Description |
---|---|---|
Color | color | Target color to use when getting the gray color |
ColorContrastType | contrastType | Contrast type |
Returns
Type | Description |
---|---|
Color |
GetGray(ColorContrastType)
Gets the gray color according to the brightness of the background color
Declaration
public static Color GetGray(ColorContrastType contrastType = ColorContrastType.Light)
Parameters
Type | Name | Description |
---|---|---|
ColorContrastType | contrastType | Contrast type |
Returns
Type | Description |
---|---|
Color |
GetRandomColor(bool, ColorSettings?)
Gets a random color instance (true color)
Declaration
public static Color GetRandomColor(bool selectBlack = true, ColorSettings? settings = null)
Parameters
Type | Name | Description |
---|---|---|
bool | selectBlack | Whether to select the black color or not |
ColorSettings | settings | Settings to use |
Returns
Type | Description |
---|---|
Color | A color instance |
GetRandomColor(ColorType, bool, ColorSettings?)
Gets a random color instance
Declaration
public static Color GetRandomColor(ColorType type, bool selectBlack = true, ColorSettings? settings = null)
Parameters
Type | Name | Description |
---|---|---|
ColorType | type | Color type to generate |
bool | selectBlack | Whether to select the black color or not |
ColorSettings | settings | Settings to use |
Returns
Type | Description |
---|---|
Color | A color instance |
GetRandomColor(ColorType, int, int, int, int, int, int, int, int, ColorSettings?)
Gets a random color instance
Declaration
public static Color GetRandomColor(ColorType type, int minColor, int maxColor, int minColorR, int maxColorR, int minColorG, int maxColorG, int minColorB, int maxColorB, ColorSettings? settings = null)
Parameters
Type | Name | Description |
---|---|---|
ColorType | type | Color type to generate |
int | minColor | The minimum color level |
int | maxColor | The maximum color level |
int | minColorR | The minimum red color level |
int | maxColorR | The maximum red color level |
int | minColorG | The minimum green color level |
int | maxColorG | The maximum green color level |
int | minColorB | The minimum blue color level |
int | maxColorB | The maximum blue color level |
ColorSettings | settings | Settings to use |
Returns
Type | Description |
---|---|
Color | A color instance |
GetRgbFromColorCode(int)
Gets the RGB instance from the color code
Declaration
public static RedGreenBlue GetRgbFromColorCode(int colorCode)
Parameters
Type | Name | Description |
---|---|---|
int | colorCode | The color code to get the RGB specifier from |
Returns
Type | Description |
---|---|
RedGreenBlue | The RGB specifier string |
GetRgbIntFromColorCode(int)
Gets the RGB numbers from the color code
Declaration
public static (int R, int G, int B) GetRgbIntFromColorCode(int colorCode)
Parameters
Type | Name | Description |
---|---|---|
int | colorCode | The color code to get the RGB specifier from |
Returns
Type | Description |
---|---|
(int R, int G, int B) | The RGB specifier string |
GetRgbSpecifierFromColorCode(int)
Gets the RGB specifier from the color code
Declaration
public static string GetRgbSpecifierFromColorCode(int colorCode)
Parameters
Type | Name | Description |
---|---|---|
int | colorCode | The color code to get the RGB specifier from |
Returns
Type | Description |
---|---|
string | The RGB specifier string |
LoadBack()
Loads the background
Declaration
public static void LoadBack()
LoadBack(Color, bool)
Loads the background
Declaration
public static void LoadBack(Color ColorSequence, bool Force = false)
Parameters
Type | Name | Description |
---|---|---|
Color | ColorSequence | Color sequence used to load background |
bool | Force | Force set background even if background setting is disabled |
LoadBackDry()
Loads the background dryly
Declaration
public static void LoadBackDry()
LoadBackDry(Color, bool)
Loads the background dryly
Declaration
public static void LoadBackDry(Color ColorSequence, bool Force = false)
Parameters
Type | Name | Description |
---|---|---|
Color | ColorSequence | Color sequence used to load background |
bool | Force | Force set background even if background setting is disabled |
RenderResetBackground()
Gets a sequence that resets the background color without clearing screen
Declaration
public static string RenderResetBackground()
Returns
Type | Description |
---|---|
string |
RenderResetColors()
Gets a sequence that resets the console colors without clearing screen
Declaration
public static string RenderResetColors()
Returns
Type | Description |
---|---|
string |
RenderResetForeground()
Gets a sequence that resets the foreground color without clearing screen
Declaration
public static string RenderResetForeground()
Returns
Type | Description |
---|---|
string |
RenderRevertBackground()
Gets a sequence that reverts the background color without clearing screen
Declaration
public static string RenderRevertBackground()
Returns
Type | Description |
---|---|
string |
RenderRevertColors()
Gets a sequence that reverts the console colors without clearing screen
Declaration
public static string RenderRevertColors()
Returns
Type | Description |
---|---|
string |
RenderRevertForeground()
Gets a sequence that reverts the foreground color without clearing screen
Declaration
public static string RenderRevertForeground()
Returns
Type | Description |
---|---|
string |
RenderSetConsoleColor(Color)
Gets the console color setting sequence
Declaration
public static string RenderSetConsoleColor(Color ColorSequence)
Parameters
Type | Name | Description |
---|---|---|
Color | ColorSequence | The color instance |
Returns
Type | Description |
---|---|
string |
RenderSetConsoleColor(Color, bool)
Gets the console color setting sequence
Declaration
public static string RenderSetConsoleColor(Color ColorSequence, bool Background)
Parameters
Type | Name | Description |
---|---|---|
Color | ColorSequence | The color instance |
bool | Background | Whether to set background or not |
Returns
Type | Description |
---|---|
string |
RenderSetConsoleColor(Color, bool, bool, bool)
Gets the console color setting sequence
Declaration
public static string RenderSetConsoleColor(Color ColorSequence, bool Background = false, bool ForceSet = false, bool canSet = true)
Parameters
Type | Name | Description |
---|---|---|
Color | ColorSequence | The color instance |
bool | Background | Whether to set background or not |
bool | ForceSet | Force set background even if background setting is disabled or if the current background color doesn't match the provided color |
bool | canSet | Can the console set this color? |
Returns
Type | Description |
---|---|
string |
ResetBackground()
Resets the background color without clearing screen
Declaration
public static void ResetBackground()
ResetColors()
Resets the console colors without clearing screen
Declaration
public static void ResetColors()
ResetForeground()
Resets the foreground color without clearing screen
Declaration
public static void ResetForeground()
RevertBackground()
Reverts the background color without clearing screen
Declaration
public static void RevertBackground()
RevertColors()
Reverts the console colors without clearing screen
Declaration
public static void RevertColors()
RevertForeground()
Reverts the foreground color without clearing screen
Declaration
public static void RevertForeground()
SetConsoleColor(Color, bool)
Sets the console color
Declaration
public static void SetConsoleColor(Color ColorSequence, bool Background)
Parameters
Type | Name | Description |
---|---|---|
Color | ColorSequence | The color instance |
bool | Background | Whether to set background or not |
SetConsoleColor(Color, bool, bool, bool)
Sets the console color
Declaration
public static void SetConsoleColor(Color ColorSequence, bool Background = false, bool ForceSet = false, bool canSet = true)
Parameters
Type | Name | Description |
---|---|---|
Color | ColorSequence | The color instance |
bool | Background | Whether to set background or not |
bool | ForceSet | Force set background even if background setting is disabled or if the current background color doesn't match the provided color |
bool | canSet | Can the console set this color? |
SetConsoleColorDry(Color, bool)
Sets the console color dryly
Declaration
public static void SetConsoleColorDry(Color ColorSequence, bool Background)
Parameters
Type | Name | Description |
---|---|---|
Color | ColorSequence | The color instance |
bool | Background | Whether to set background or not |
SetConsoleColorDry(Color, bool, bool, bool)
Sets the console color dryly
Declaration
public static void SetConsoleColorDry(Color ColorSequence, bool Background = false, bool ForceSet = false, bool canSet = true)
Parameters
Type | Name | Description |
---|---|---|
Color | ColorSequence | The color instance |
bool | Background | Whether to set background or not |
bool | ForceSet | Force set background even if background setting is disabled or if the current background color doesn't match the provided color |
bool | canSet | Can the console set this color? |
TryParseColor(int, int, int, ColorSettings?)
Tries parsing the color from the specifier string
Declaration
public static bool TryParseColor(int R, int G, int B, ColorSettings? settings = null)
Parameters
Type | Name | Description |
---|---|---|
int | R | The red level |
int | G | The green level |
int | B | The blue level |
ColorSettings | settings | Settings to use |
Returns
Type | Description |
---|---|
bool | True if successful; False if failed |
TryParseColor(int, ColorSettings?)
Tries parsing the color from the specifier string
Declaration
public static bool TryParseColor(int ColorNum, ColorSettings? settings = null)
Parameters
Type | Name | Description |
---|---|---|
int | ColorNum | The color number |
ColorSettings | settings | Settings to use |
Returns
Type | Description |
---|---|
bool | True if successful; False if failed |
TryParseColor(string, ColorSettings?)
Tries parsing the color from the specifier string
Declaration
public static bool TryParseColor(string ColorSpecifier, ColorSettings? settings = null)
Parameters
Type | Name | Description |
---|---|---|
string | ColorSpecifier | A color specifier. It must be a valid number from 0-255 if using 255-colors, or a VT sequence if using true color as follows: <R>;<G>;<B> |
ColorSettings | settings | Settings to use |
Returns
Type | Description |
---|---|
bool | True if successful; False if failed |
TrySetConsoleColor(Color, bool, bool, bool)
Sets the console color
Declaration
public static bool TrySetConsoleColor(Color ColorSequence, bool Background = false, bool ForceSet = false, bool canSet = true)
Parameters
Type | Name | Description |
---|---|---|
Color | ColorSequence | The color instance |
bool | Background | Whether to set background or not |
bool | ForceSet | Force set background even if background setting is disabled or if the current background color doesn't match the provided color |
bool | canSet | Can the console set this color? |
Returns
Type | Description |
---|---|
bool | True if successful; False if unsuccessful |
TrySetConsoleColorDry(Color, bool, bool, bool)
Sets the console color dryly
Declaration
public static bool TrySetConsoleColorDry(Color ColorSequence, bool Background = false, bool ForceSet = false, bool canSet = true)
Parameters
Type | Name | Description |
---|---|---|
Color | ColorSequence | The color instance |
bool | Background | Whether to set background or not |
bool | ForceSet | Force set background even if background setting is disabled or if the current background color doesn't match the provided color |
bool | canSet | Can the console set this color? |
Returns
Type | Description |
---|---|
bool | True if successful; False if unsuccessful |