Skip to content

Commit

Permalink
add - Added GetRgbIntFromColorCode()
Browse files Browse the repository at this point in the history
---

We've added a function that allows you to get the RGB numbers from the RGB code.

---

Type: add
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Apr 22, 2024
1 parent afb201b commit 7e5d82c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Terminaux/Colors/ColorTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,16 +470,30 @@ public static string RenderResetBackground() =>
/// </summary>
/// <param name="colorCode">The color code to get the RGB specifier from</param>
/// <returns>The RGB specifier string</returns>
public static string GetRgbSpecifierFromColorCode(int colorCode) =>
$"{(colorCode) & 0xff};{(colorCode >> 8) & 0xff};{(colorCode >> 16) & 0xff}";
public static string GetRgbSpecifierFromColorCode(int colorCode)
{
(int r, int g, int b) = GetRgbIntFromColorCode(colorCode);
return $"{r};{g};{b}";
}

/// <summary>
/// Gets the RGB instance from the color code
/// </summary>
/// <param name="colorCode">The color code to get the RGB specifier from</param>
/// <returns>The RGB specifier string</returns>
public static RedGreenBlue GetRgbFromColorCode(int colorCode) =>
new((colorCode) & 0xff, (colorCode >> 8) & 0xff, (colorCode >> 16) & 0xff);
public static RedGreenBlue GetRgbFromColorCode(int colorCode)
{
(int r, int g, int b) = GetRgbIntFromColorCode(colorCode);
return new(r, g, b);
}

/// <summary>
/// Gets the RGB numbers from the color code
/// </summary>
/// <param name="colorCode">The color code to get the RGB specifier from</param>
/// <returns>The RGB specifier string</returns>
public static (int R, int G, int B) GetRgbIntFromColorCode(int colorCode) =>
((colorCode) & 0xff, (colorCode >> 8) & 0xff, (colorCode >> 16) & 0xff);

internal static string GetColorIdStringFrom(ConsoleColors colorDef) =>
GetColorIdStringFrom((int)colorDef);
Expand Down

0 comments on commit 7e5d82c

Please sign in to comment.