Terminal UI V2, advanced binding
This commit is contained in:
14
src/Library/TerminalUI/Models/Color256.cs
Normal file
14
src/Library/TerminalUI/Models/Color256.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace TerminalUI.Models;
|
||||
|
||||
public record struct Color256(byte Color, ColorType Type) : IColor
|
||||
{
|
||||
public string ToConsoleColor()
|
||||
=> Type switch
|
||||
{
|
||||
ColorType.Foreground => $"\x1b[38;5;{Color}m",
|
||||
ColorType.Background => $"\x1b[48;5;{Color}m",
|
||||
_ => throw new InvalidEnumArgumentException(nameof(Type), (int) Type, typeof(ColorType))
|
||||
};
|
||||
}
|
||||
14
src/Library/TerminalUI/Models/ColorRGB.cs
Normal file
14
src/Library/TerminalUI/Models/ColorRGB.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace TerminalUI.Models;
|
||||
|
||||
public record struct ColorRgb(byte R, byte G, byte B, ColorType Type) : IColor
|
||||
{
|
||||
public string ToConsoleColor()
|
||||
=> Type switch
|
||||
{
|
||||
ColorType.Foreground => $"\x1b[38;2;{R};{G};{B};m",
|
||||
ColorType.Background => $"\x1b[48;2;{R};{G};{B};m",
|
||||
_ => throw new InvalidEnumArgumentException(nameof(Type), (int) Type, typeof(ColorType))
|
||||
};
|
||||
}
|
||||
8
src/Library/TerminalUI/Models/ColorType.cs
Normal file
8
src/Library/TerminalUI/Models/ColorType.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace TerminalUI.Models;
|
||||
|
||||
public enum ColorType
|
||||
{
|
||||
Unknown,
|
||||
Foreground,
|
||||
Background
|
||||
}
|
||||
83
src/Library/TerminalUI/Models/Colors.cs
Normal file
83
src/Library/TerminalUI/Models/Colors.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
namespace TerminalUI.Models;
|
||||
|
||||
public static class Color256Colors
|
||||
{
|
||||
public static class Backgrounds
|
||||
{
|
||||
public static readonly Color256 Black = new(0, ColorType.Background);
|
||||
public static readonly Color256 Blue = new(9, ColorType.Background);
|
||||
public static readonly Color256 Cyan = new(11, ColorType.Background);
|
||||
public static readonly Color256 DarkBlue = new(1, ColorType.Background);
|
||||
public static readonly Color256 DarkCyan = new(3, ColorType.Background);
|
||||
public static readonly Color256 DarkGray = new(8, ColorType.Background);
|
||||
public static readonly Color256 DarkGreen = new(2, ColorType.Background);
|
||||
public static readonly Color256 DarkMagenta = new(5, ColorType.Background);
|
||||
public static readonly Color256 DarkRed = new(4, ColorType.Background);
|
||||
public static readonly Color256 DarkYellow = new(6, ColorType.Background);
|
||||
public static readonly Color256 Gray = new(7, ColorType.Background);
|
||||
public static readonly Color256 Green = new(10, ColorType.Background);
|
||||
public static readonly Color256 Magenta = new(13, ColorType.Background);
|
||||
public static readonly Color256 Red = new(12, ColorType.Background);
|
||||
public static readonly Color256 White = new(15, ColorType.Background);
|
||||
}
|
||||
public static class Foregrounds
|
||||
{
|
||||
public static readonly Color256 Black = new(0, ColorType.Foreground);
|
||||
public static readonly Color256 Blue = new(9, ColorType.Foreground);
|
||||
public static readonly Color256 Cyan = new(11, ColorType.Foreground);
|
||||
public static readonly Color256 DarkBlue = new(1, ColorType.Foreground);
|
||||
public static readonly Color256 DarkCyan = new(3, ColorType.Foreground);
|
||||
public static readonly Color256 DarkGray = new(8, ColorType.Foreground);
|
||||
public static readonly Color256 DarkGreen = new(2, ColorType.Foreground);
|
||||
public static readonly Color256 DarkMagenta = new(5, ColorType.Foreground);
|
||||
public static readonly Color256 DarkRed = new(4, ColorType.Foreground);
|
||||
public static readonly Color256 DarkYellow = new(6, ColorType.Foreground);
|
||||
public static readonly Color256 Gray = new(7, ColorType.Foreground);
|
||||
public static readonly Color256 Green = new(10, ColorType.Foreground);
|
||||
public static readonly Color256 Magenta = new(13, ColorType.Foreground);
|
||||
public static readonly Color256 Red = new(12, ColorType.Foreground);
|
||||
public static readonly Color256 White = new(15, ColorType.Foreground);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConsoleColors
|
||||
{
|
||||
public static class Backgrounds
|
||||
{
|
||||
public static readonly ConsoleColor Black = new(System.ConsoleColor.Black, ColorType.Background);
|
||||
public static readonly ConsoleColor Blue = new(System.ConsoleColor.Blue, ColorType.Background);
|
||||
public static readonly ConsoleColor Cyan = new(System.ConsoleColor.Cyan, ColorType.Background);
|
||||
public static readonly ConsoleColor DarkBlue = new(System.ConsoleColor.DarkBlue, ColorType.Background);
|
||||
public static readonly ConsoleColor DarkCyan = new(System.ConsoleColor.DarkCyan, ColorType.Background);
|
||||
public static readonly ConsoleColor DarkGray = new(System.ConsoleColor.DarkGray, ColorType.Background);
|
||||
public static readonly ConsoleColor DarkGreen = new(System.ConsoleColor.DarkGreen, ColorType.Background);
|
||||
public static readonly ConsoleColor DarkMagenta = new(System.ConsoleColor.DarkMagenta, ColorType.Background);
|
||||
public static readonly ConsoleColor DarkRed = new(System.ConsoleColor.DarkRed, ColorType.Background);
|
||||
public static readonly ConsoleColor DarkYellow = new(System.ConsoleColor.DarkYellow, ColorType.Background);
|
||||
public static readonly ConsoleColor Gray = new(System.ConsoleColor.Gray, ColorType.Background);
|
||||
public static readonly ConsoleColor Green = new(System.ConsoleColor.Green, ColorType.Background);
|
||||
public static readonly ConsoleColor Magenta = new(System.ConsoleColor.Magenta, ColorType.Background);
|
||||
public static readonly ConsoleColor Red = new(System.ConsoleColor.Red, ColorType.Background);
|
||||
public static readonly ConsoleColor White = new(System.ConsoleColor.White, ColorType.Background);
|
||||
public static readonly ConsoleColor Yellow = new(System.ConsoleColor.Yellow, ColorType.Background);
|
||||
}
|
||||
public static class Foregrounds
|
||||
{
|
||||
public static readonly ConsoleColor Black = new(System.ConsoleColor.Black, ColorType.Foreground);
|
||||
public static readonly ConsoleColor Blue = new(System.ConsoleColor.Blue, ColorType.Foreground);
|
||||
public static readonly ConsoleColor Cyan = new(System.ConsoleColor.Cyan, ColorType.Foreground);
|
||||
public static readonly ConsoleColor DarkBlue = new(System.ConsoleColor.DarkBlue, ColorType.Foreground);
|
||||
public static readonly ConsoleColor DarkCyan = new(System.ConsoleColor.DarkCyan, ColorType.Foreground);
|
||||
public static readonly ConsoleColor DarkGray = new(System.ConsoleColor.DarkGray, ColorType.Foreground);
|
||||
public static readonly ConsoleColor DarkGreen = new(System.ConsoleColor.DarkGreen, ColorType.Foreground);
|
||||
public static readonly ConsoleColor DarkMagenta = new(System.ConsoleColor.DarkMagenta, ColorType.Foreground);
|
||||
public static readonly ConsoleColor DarkRed = new(System.ConsoleColor.DarkRed, ColorType.Foreground);
|
||||
public static readonly ConsoleColor DarkYellow = new(System.ConsoleColor.DarkYellow, ColorType.Foreground);
|
||||
public static readonly ConsoleColor Gray = new(System.ConsoleColor.Gray, ColorType.Foreground);
|
||||
public static readonly ConsoleColor Green = new(System.ConsoleColor.Green, ColorType.Foreground);
|
||||
public static readonly ConsoleColor Magenta = new(System.ConsoleColor.Magenta, ColorType.Foreground);
|
||||
public static readonly ConsoleColor Red = new(System.ConsoleColor.Red, ColorType.Foreground);
|
||||
public static readonly ConsoleColor White = new(System.ConsoleColor.White, ColorType.Foreground);
|
||||
public static readonly ConsoleColor Yellow = new(System.ConsoleColor.Yellow, ColorType.Foreground);
|
||||
}
|
||||
}
|
||||
6
src/Library/TerminalUI/Models/ConsoleColor.cs
Normal file
6
src/Library/TerminalUI/Models/ConsoleColor.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace TerminalUI.Models;
|
||||
|
||||
public record ConsoleColor(System.ConsoleColor Color, ColorType Type) : IColor
|
||||
{
|
||||
public string ToConsoleColor() => throw new NotImplementedException();
|
||||
}
|
||||
7
src/Library/TerminalUI/Models/IColor.cs
Normal file
7
src/Library/TerminalUI/Models/IColor.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace TerminalUI.Models;
|
||||
|
||||
public interface IColor
|
||||
{
|
||||
ColorType Type { get; }
|
||||
string ToConsoleColor();
|
||||
}
|
||||
3
src/Library/TerminalUI/Models/Position.cs
Normal file
3
src/Library/TerminalUI/Models/Position.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace TerminalUI.Models;
|
||||
|
||||
public record struct Position(int PosX, int PosY);
|
||||
Reference in New Issue
Block a user