Skip to content

Commit 63c8b21

Browse files
committed
Added implicit conversion for simple Color to RGB
1 parent 4bdce6d commit 63c8b21

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed
File renamed without changes.

Meep.Tech.ANSI.sln renamed to Meep.Tech.Text.ANSI.sln

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.10.34804.81
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meep.Tech.ANSI", "Meep.Tech.ANSI.csproj", "{8BD4D17A-78D3-41C0-8033-D3FEE54A9EAB}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meep.Tech.Text.ANSI", "Meep.Tech.Text.ANSI.csproj", "{8BD4D17A-78D3-41C0-8033-D3FEE54A9EAB}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Meep.Tech.ANSI.Tests", "tests\Meep.Tech.ANSI.Tests.csproj", "{6B76952E-6D2D-4463-810E-9990B97B60B4}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Meep.Tech.Text.ANSI.Tests", "tests\Meep.Tech.Text.ANSI.Tests.csproj", "{6B76952E-6D2D-4463-810E-9990B97B60B4}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/RGB.cs

+25
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,31 @@ public static implicit operator (byte r, byte g, byte b)(RGB rgb)
223223
/// </summary>
224224
public static implicit operator (int r, int g, int b)(RGB rgb)
225225
=> (rgb.R, rgb.G, rgb.B);
226+
227+
/// <summary>
228+
/// Implicitly convert an ANSI Console color to an RGB color.
229+
/// </summary>
230+
public static implicit operator RGB(Color color)
231+
=> color switch {
232+
Color.Reset => White,
233+
Color.Black => Black,
234+
Color.Red => Red,
235+
Color.Green => Green,
236+
Color.Blue => Blue,
237+
Color.Yellow => Yellow,
238+
Color.Magenta => Magenta,
239+
Color.Cyan => Cyan,
240+
Color.White => White,
241+
Color.BrightBlack => Gray,
242+
Color.BrightRed => Red.Brighter,
243+
Color.BrightGreen => Green.Brighter,
244+
Color.BrightBlue => Blue.Brighter,
245+
Color.BrightYellow => Yellow.Brighter,
246+
Color.BrightMagenta => Magenta.Brighter,
247+
Color.BrightCyan => Cyan.Brighter,
248+
Color.BrightWhite => White.Brighter,
249+
_ => throw new ArgumentOutOfRangeException(nameof(color), color, "Unknown ANSI Console color.")
250+
};
226251
}
227252
}
228253
}

tests/Meep.Tech.ANSI.Tests.csproj renamed to tests/Meep.Tech.Text.ANSI.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</ItemGroup>
2222

2323
<ItemGroup>
24-
<ProjectReference Include="..\Meep.Tech.ANSI.csproj" />
24+
<ProjectReference Include="..\Meep.Tech.Text.ANSI.csproj" />
2525
</ItemGroup>
2626

2727
</Project>

0 commit comments

Comments
 (0)