diff --git a/.github/actions/spelling/allow/allow.txt b/.github/actions/spelling/allow/allow.txt index 6cc94d3f86..bdbcfc923b 100644 --- a/.github/actions/spelling/allow/allow.txt +++ b/.github/actions/spelling/allow/allow.txt @@ -82,3 +82,4 @@ We'd wildcards yeru zhe +allcolors diff --git a/src/tools/ColorTool/ColorTool/ColorTable.cs b/src/tools/ColorTool/ColorTool/ColorTable.cs index af3c3d2271..93e1508117 100644 --- a/src/tools/ColorTool/ColorTool/ColorTable.cs +++ b/src/tools/ColorTool/ColorTool/ColorTable.cs @@ -31,9 +31,8 @@ namespace ColorTool private const int BrightWhite = 15; // This is the order of colors when output by the table. - private static readonly IReadOnlyList Foregrounds = new[] + private static readonly IReadOnlyList TableColors = new[] { - BrightWhite, DarkBlack, BrightBlack, DarkRed, @@ -52,88 +51,91 @@ namespace ColorTool BrightWhite }; - private static readonly IReadOnlyList Backgrounds = new[] - { - DarkBlack, - DarkRed, - DarkGreen, - DarkYellow, - DarkBlue, - DarkMagenta, - DarkCyan, - DarkWhite - }; - - private const string TestText = " gYw "; - private static readonly IReadOnlyList AnsiForegroundSequences = new[] { - "m", - "1m", "30m", - "1;30m", + "90m", "31m", - "1;31m", + "91m", "32m", - "1;32m", + "92m", "33m", - "1;33m", + "93m", "34m", - "1;34m", + "94m", "35m", - "1;35m", + "95m", "36m", - "1;36m", + "96m", "37m", - "1;37m" + "97m" }; private static readonly IReadOnlyList AnsiBackgroundSequences = new[] { - "m", "40m", + "100m", "41m", + "101m", "42m", + "102m", "43m", + "103m", "44m", + "104m", "45m", + "105m", "46m", - "47m" + "106m", + "47m", + "107m" }; - public static void PrintTable() + private const string AnsiDefaultFg = "39m"; + private const string AnsiDefaultBg = "49m"; + + public static void PrintTable(bool compact) { + string TestText = compact ? " gYw " : " gYw "; ConsoleColor[] colors = (ConsoleColor[])ConsoleColor.GetValues(typeof(ConsoleColor)); // Save the current background and foreground colors. ConsoleColor currentBackground = Console.BackgroundColor; ConsoleColor currentForeground = Console.ForegroundColor; - Console.Write("\t"); - for (int bg = 0; bg < AnsiBackgroundSequences.Count; bg++) + // first column + Console.Write("\t "); + if (compact) Console.Write(" "); + Console.Write(AnsiDefaultBg); + if (compact) Console.Write(" "); + Console.Write(" "); + + for (int bg = 0; bg < AnsiBackgroundSequences.Count; bg += 1 + Convert.ToUInt16(compact)) { - if (bg > 0) Console.Write(" "); - Console.Write(" "); - Console.Write(bg == 0 ? " " : AnsiBackgroundSequences[bg]); Console.Write(" "); + if (compact) Console.Write(" "); + Console.Write(AnsiBackgroundSequences[bg]); + if (compact) Console.Write(" "); + if (AnsiBackgroundSequences[bg].Length == 3) Console.Write(" "); } Console.WriteLine(); - for (int fg = 0; fg < AnsiForegroundSequences.Count; fg++) + for (int fg = 0; fg <= TableColors.Count && fg <= AnsiForegroundSequences.Count; fg++) { Console.ForegroundColor = currentForeground; Console.BackgroundColor = currentBackground; - if (fg >= 0) Console.Write(AnsiForegroundSequences[fg] + "\t"); + Console.Write(fg == 0 ? AnsiDefaultFg : AnsiForegroundSequences[fg - 1]); + Console.Write("\t"); if (fg == 0) Console.ForegroundColor = currentForeground; - else Console.ForegroundColor = colors[Foregrounds[fg - 1]]; + else Console.ForegroundColor = colors[TableColors[fg - 1]]; - for (int bg = 0; bg < AnsiBackgroundSequences.Count; bg++) + for (int bg = 0; bg <= TableColors.Count; bg += 1 + Convert.ToUInt16(compact)) { if (bg > 0) Console.Write(" "); if (bg == 0) Console.BackgroundColor = currentBackground; - else Console.BackgroundColor = colors[Backgrounds[bg - 1]]; + else Console.BackgroundColor = colors[TableColors[bg - (1 + Convert.ToUInt16(compact))]]; Console.Write(TestText); Console.BackgroundColor = currentBackground; } @@ -146,50 +148,41 @@ namespace ColorTool Console.BackgroundColor = currentBackground; } - public static void PrintTableWithVt() + public static void PrintTableWithVt(bool compact) { - Console.Write("\t"); - for (int bg = 0; bg < AnsiBackgroundSequences.Count; bg++) + string TestText = compact ? " gYw " : " gYw "; + // first column + Console.Write("\t "); + if (compact) Console.Write(" "); + Console.Write(AnsiDefaultBg); + if (compact) Console.Write(" "); + Console.Write(" "); + + for (int bg = 0; bg < AnsiBackgroundSequences.Count; bg += 1 + Convert.ToUInt16(compact)) { - if (bg > 0) Console.Write(" "); - Console.Write(" "); - Console.Write(bg == 0 ? " " : AnsiBackgroundSequences[bg]); Console.Write(" "); + if (compact) Console.Write(" "); + Console.Write(AnsiBackgroundSequences[bg]); + if (compact) Console.Write(" "); + if (AnsiBackgroundSequences[bg].Length == 3) Console.Write(" "); } Console.WriteLine(); - for (int fg = 0; fg < AnsiForegroundSequences.Count; fg++) + for (int fg = 0; fg <= AnsiForegroundSequences.Count; fg++) { Console.Write("\x1b[m"); - if (fg >= 0) - { - Console.Write(AnsiForegroundSequences[fg] + "\t"); - } + Console.Write(fg == 0 ? AnsiDefaultFg : AnsiForegroundSequences[fg - 1]); + Console.Write("\t"); - if (fg == 0) - { - Console.Write("\x1b[39m"); - } - else - { - Console.Write("\x1b[" + AnsiForegroundSequences[fg]); - } + if (fg == 0) Console.Write("\x1b[" + AnsiDefaultFg); + else Console.Write("\x1b[" + AnsiForegroundSequences[fg - 1]); - for (int bg = 0; bg < AnsiBackgroundSequences.Count; bg++) + for (int bg = 0; bg <= AnsiBackgroundSequences.Count; bg += 1 + Convert.ToUInt16(compact)) { - if (bg > 0) - { - Console.Write(" "); - } - if (bg == 0) - { - Console.Write("\x1b[49m"); - } - else - { - Console.Write("\x1b[" + AnsiBackgroundSequences[bg]); - } + if (bg != 0) Console.Write(" "); + if (bg == 0) Console.Write("\x1b[" + AnsiDefaultBg); + else Console.Write("\x1b[" + AnsiBackgroundSequences[bg - (1 + Convert.ToUInt16(compact))]); Console.Write(TestText); Console.Write("\x1b[49m"); diff --git a/src/tools/ColorTool/ColorTool/ConsoleTargets/CurrentConsoleTarget.cs b/src/tools/ColorTool/ColorTool/ConsoleTargets/CurrentConsoleTarget.cs index bec325773e..e85944ba34 100644 --- a/src/tools/ColorTool/ColorTool/ConsoleTargets/CurrentConsoleTarget.cs +++ b/src/tools/ColorTool/ColorTool/ConsoleTargets/CurrentConsoleTarget.cs @@ -13,7 +13,7 @@ namespace ColorTool.ConsoleTargets /// class CurrentConsoleTarget : IConsoleTarget { - public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode) + public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode, bool compactColortable) { CONSOLE_SCREEN_BUFFER_INFO_EX csbiex = CONSOLE_SCREEN_BUFFER_INFO_EX.Create(); IntPtr hOut = GetStdOutputHandle(); @@ -40,7 +40,7 @@ namespace ColorTool.ConsoleTargets if (!quietMode) { - ColorTable.PrintTable(); + ColorTable.PrintTable(compactColortable); } } } diff --git a/src/tools/ColorTool/ColorTool/ConsoleTargets/DefaultConsoleTarget.cs b/src/tools/ColorTool/ColorTool/ConsoleTargets/DefaultConsoleTarget.cs index fa8e104716..f96c7047c5 100644 --- a/src/tools/ColorTool/ColorTool/ConsoleTargets/DefaultConsoleTarget.cs +++ b/src/tools/ColorTool/ColorTool/ConsoleTargets/DefaultConsoleTarget.cs @@ -13,7 +13,7 @@ namespace ColorTool.ConsoleTargets /// class DefaultConsoleTarget : IConsoleTarget { - public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode) + public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode, bool compactColortable) { RegistryKey consoleKey = Registry.CurrentUser.OpenSubKey("Console", true); for (int i = 0; i < colorScheme.ColorTable.Length; i++) diff --git a/src/tools/ColorTool/ColorTool/ConsoleTargets/IConsoleTarget.cs b/src/tools/ColorTool/ColorTool/ConsoleTargets/IConsoleTarget.cs index 12d30a802b..2dc6b7be82 100644 --- a/src/tools/ColorTool/ColorTool/ConsoleTargets/IConsoleTarget.cs +++ b/src/tools/ColorTool/ColorTool/ConsoleTargets/IConsoleTarget.cs @@ -10,6 +10,6 @@ namespace ColorTool.ConsoleTargets /// interface IConsoleTarget { - void ApplyColorScheme(ColorScheme colorScheme, bool quietMode); + void ApplyColorScheme(ColorScheme colorScheme, bool quietMode, bool compactColortable); } } diff --git a/src/tools/ColorTool/ColorTool/ConsoleTargets/TerminalSchemeConsoleTarget.cs b/src/tools/ColorTool/ColorTool/ConsoleTargets/TerminalSchemeConsoleTarget.cs index 8bacf9d7f8..5f19cb7d95 100644 --- a/src/tools/ColorTool/ColorTool/ConsoleTargets/TerminalSchemeConsoleTarget.cs +++ b/src/tools/ColorTool/ColorTool/ConsoleTargets/TerminalSchemeConsoleTarget.cs @@ -8,7 +8,7 @@ namespace ColorTool.ConsoleTargets { class TerminalSchemeConsoleTarget : IConsoleTarget { - public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode) + public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode, bool compactColortable) { Console.WriteLine("Copy and paste the following text into the schemes array of your Windows Terminal settings.json file to add this color scheme. (Don't forget to add a comma separator after the previous scheme.)"); Console.WriteLine("{"); diff --git a/src/tools/ColorTool/ColorTool/ConsoleTargets/VirtualTerminalConsoleTarget.cs b/src/tools/ColorTool/ColorTool/ConsoleTargets/VirtualTerminalConsoleTarget.cs index 177b3c1611..8f30cad55d 100644 --- a/src/tools/ColorTool/ColorTool/ConsoleTargets/VirtualTerminalConsoleTarget.cs +++ b/src/tools/ColorTool/ColorTool/ConsoleTargets/VirtualTerminalConsoleTarget.cs @@ -36,7 +36,7 @@ namespace ColorTool.ConsoleTargets 8+7, // Bright White }; - public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode) + public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode, bool compactColortable) { Program.DoInVTMode(() => { @@ -58,7 +58,6 @@ namespace ColorTool.ConsoleTargets string s = $"\x1b]12;rgb:{color.R:X2}/{color.G:X2}/{color.B:X2}\x1b\\"; Console.Write(s); } - for (int i = 0; i < colorScheme.ColorTable.Length; i++) { int vtIndex = VirtualTerminalIndices[i]; @@ -69,7 +68,7 @@ namespace ColorTool.ConsoleTargets if (!quietMode) { - ColorTable.PrintTableWithVt(); + ColorTable.PrintTableWithVt(compactColortable); } }); } diff --git a/src/tools/ColorTool/ColorTool/Program.cs b/src/tools/ColorTool/ColorTool/Program.cs index cd1c283d56..9c7295358c 100644 --- a/src/tools/ColorTool/ColorTool/Program.cs +++ b/src/tools/ColorTool/ColorTool/Program.cs @@ -4,8 +4,8 @@ // using ColorTool.ConsoleTargets; -using ColorTool.SchemeWriters; using static ColorTool.ConsoleAPI; +using ColorTool.SchemeWriters; using System; using System.Collections.Generic; using System.Linq; @@ -20,6 +20,8 @@ namespace ColorTool private static bool setProperties = true; private static bool setUnixStyle = false; private static bool setTerminalStyle = false; + private static bool compactTableStyle = true; + private static bool printCurrent = false; public static void Main(string[] args) { @@ -39,8 +41,8 @@ namespace ColorTool return; case "-c": case "--current": - ColorTable.PrintTable(); - return; + printCurrent = true; + break; case "-l": case "--location": SchemeManager.PrintSchemesDirectory(); @@ -66,36 +68,46 @@ namespace ColorTool return; case "-e": case "--errors": - reportErrors = true; + reportErrors = true; break; case "-q": case "--quiet": - quietMode = true; + quietMode = true; break; case "-d": case "--defaults": - setDefaults = true; - setProperties = false; + setDefaults = true; + setProperties = false; break; case "-b": case "--both": - setDefaults = true; - setProperties = true; + setDefaults = true; + setProperties = true; break; case "-x": case "--xterm": - setUnixStyle = true; - setProperties = true; + setUnixStyle = true; + setProperties = true; + break; + case "-a": + case "--allcolors": + compactTableStyle = false; break; case "-t": case "--terminal": setTerminalStyle = true; - setProperties = true; + setProperties = true; break; default: break; } } + if (printCurrent) + { + if (setUnixStyle) DoInVTMode(() => ColorTable.PrintTableWithVt(compactTableStyle)); + else ColorTable.PrintTable(compactTableStyle); + return; + } string schemeName = args[args.Length - 1]; @@ -109,7 +121,7 @@ namespace ColorTool foreach (var target in GetConsoleTargets()) { - target.ApplyColorScheme(colorScheme, quietMode); + target.ApplyColorScheme(colorScheme, quietMode, compactTableStyle); } } diff --git a/src/tools/ColorTool/ColorTool/Resources.resx b/src/tools/ColorTool/ColorTool/Resources.resx index 195c976b59..5fb4bbb083 100644 --- a/src/tools/ColorTool/ColorTool/Resources.resx +++ b/src/tools/ColorTool/ColorTool/Resources.resx @@ -1,17 +1,17 @@ - @@ -121,8 +121,8 @@ Error loading ini file "{0}" - Error loading ini file "{0}" - for key "{1}" + Error loading ini file "{0}" + for key "{1}" the value "{2}" is invalid @@ -160,7 +160,7 @@ Parameters: Functions: You may specify only one of the following switches each time you invoke ColorTool. Any additional switches before or after the first one of them will be ignored. - + -?, --help : Display this help message -c, --current : Print the color table for the currently applied scheme -v, --version : Display the version number @@ -180,11 +180,11 @@ Options: -x, --xterm : Set the colors using VT sequences. Used for setting the colors in WSL. Only works in Windows versions >= 17048. -t, --terminal : Output the colors in JSON format for copying into a Windows Terminal settings file. - + -a, --allcolors: Output extended color table. best for >110 column terminals Available importers: {0} Wrote selected scheme to the defaults. - \ No newline at end of file + diff --git a/src/tools/ColorTool/README.md b/src/tools/ColorTool/README.md index b360411d5e..ca1c949fd8 100644 --- a/src/tools/ColorTool/README.md +++ b/src/tools/ColorTool/README.md @@ -45,6 +45,7 @@ Options: -x, --xterm : Set the colors using VT sequences. Used for setting the colors in WSL. Only works in Windows versions >= 17048. -t, --terminal : Output the colors in JSON format for copying into a Windows Terminal settings file. + -a, --allcolors: Output extended color table. best for >110 column terminals ``` ## Included Schemes