diff --git a/tools/ColorTool/ColorTool/ConsoleAPI.cs b/tools/ColorTool/ColorTool/ConsoleAPI.cs
index 4e438111f..56cc115d6 100644
--- a/tools/ColorTool/ColorTool/ConsoleAPI.cs
+++ b/tools/ColorTool/ColorTool/ConsoleAPI.cs
@@ -56,6 +56,12 @@ namespace ColorTool
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool SetConsoleScreenBufferInfoEx(IntPtr ConsoleOutput, ref CONSOLE_SCREEN_BUFFER_INFO_EX ConsoleScreenBufferInfoEx);
+
+ [DllImport("kernel32.dll", SetLastError = true)]
+ public static extern bool SetConsoleMode(IntPtr hConsoleHandle, int mode);
+
+ [DllImport("kernel32.dll", SetLastError = true)]
+ public static extern bool GetConsoleMode(IntPtr handle, out int mode);
////////////////////////////////////////////////////////////////////////
public static uint RGB(int r, int g, int b)
diff --git a/tools/ColorTool/ColorTool/ISchemeParser.cs b/tools/ColorTool/ColorTool/ISchemeParser.cs
index 150ca35cc..f47f09f73 100644
--- a/tools/ColorTool/ColorTool/ISchemeParser.cs
+++ b/tools/ColorTool/ColorTool/ISchemeParser.cs
@@ -9,6 +9,6 @@ namespace ColorTool
{
string Name { get; }
- uint[] ParseScheme(string schemeName);
+ uint[] ParseScheme(string schemeName, bool reportErrors = true);
}
}
diff --git a/tools/ColorTool/ColorTool/IniSchemeParser.cs b/tools/ColorTool/ColorTool/IniSchemeParser.cs
index e20554b0b..a6a66bbd5 100644
--- a/tools/ColorTool/ColorTool/IniSchemeParser.cs
+++ b/tools/ColorTool/ColorTool/IniSchemeParser.cs
@@ -107,7 +107,7 @@ namespace ColorTool
return null;
}
- public uint[] ParseScheme(string schemeName)
+ public uint[] ParseScheme(string schemeName, bool reportErrors = true)
{
bool success = true;
@@ -127,7 +127,10 @@ namespace ColorTool
if (tableStrings[i].Length <= 0)
{
success = false;
- Console.WriteLine(string.Format(Resources.IniParseError, filename, name, tableStrings[i]));
+ if (reportErrors)
+ {
+ Console.WriteLine(string.Format(Resources.IniParseError, filename, name, tableStrings[i]));
+ }
break;
}
}
@@ -144,7 +147,10 @@ namespace ColorTool
}
catch (Exception /*e*/)
{
- Console.WriteLine(string.Format(Resources.IniLoadError, filename));
+ if (reportErrors)
+ {
+ Console.WriteLine(string.Format(Resources.IniLoadError, filename));
+ }
colorTable = null;
}
diff --git a/tools/ColorTool/ColorTool/Program.cs b/tools/ColorTool/ColorTool/Program.cs
index 2e45a4995..22391ee14 100644
--- a/tools/ColorTool/ColorTool/Program.cs
+++ b/tools/ColorTool/ColorTool/Program.cs
@@ -6,8 +6,11 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
+using System.Drawing;
+using System.IO;
using System.Linq;
using System.Reflection;
+using System.Runtime.InteropServices;
using static ColorTool.ConsoleAPI;
namespace ColorTool
@@ -184,6 +187,54 @@ namespace ColorTool
Console.BackgroundColor = currentBackground;
}
+ static void PrintSchemes()
+ {
+ if (Directory.Exists("./schemes"))
+ {
+ IntPtr handle = GetStdHandle(-11);
+ GetConsoleMode(handle, out var mode);
+ SetConsoleMode(handle, mode | 0x4);
+
+ int consoleWidth = Console.WindowWidth;
+ string fgText = " gYw ";
+ foreach (string schemeName in Directory.GetFiles("./schemes/").Select(Path.GetFileName))
+ {
+ uint[] colorTable = GetSchemeUints(schemeName, false);
+ if (colorTable != null)
+ {
+ string colors = string.Empty;
+ for (var index = 0; index < 8; index++)
+ {
+ uint t = colorTable[index];
+ var color = UIntToColor(t);
+ // Set the background color to the color in the scheme, plus some text to show how it looks
+ colors += $"\x1b[48;2;{color.R};{color.G};{color.B}m{fgText}";
+ }
+ // Align scheme colors right, or on newline if it doesn't fit
+ int schemeTextLength = fgText.Length * 8;
+ int bufferLength = consoleWidth - (schemeName.Length + schemeTextLength);
+
+ string bufferString = bufferLength >= 0
+ ? new string(' ', bufferLength)
+ : "\n" + new string(' ', consoleWidth - schemeTextLength);
+
+ string outputString = schemeName + bufferString + colors;
+ Console.WriteLine(outputString);
+ Console.ResetColor();
+ }
+ }
+ }
+ }
+
+ private static Color UIntToColor(uint color)
+ {
+ byte a = (byte)(color >> 24);
+ byte r = (byte)(color >> 16);
+ byte g = (byte)(color >> 8);
+ byte b = (byte)(color >> 0);
+ return Color.FromArgb(a, r, g, b);
+ }
+
static bool SetProperties(uint[] colorTable)
{
CONSOLE_SCREEN_BUFFER_INFO_EX csbiex = CONSOLE_SCREEN_BUFFER_INFO_EX.Create();
@@ -302,6 +353,10 @@ namespace ColorTool
OutputUsage();
}
return;
+ case "-s":
+ case "--schemes":
+ PrintSchemes();
+ return;
default:
break;
}
@@ -309,16 +364,7 @@ namespace ColorTool
string schemeName = args[args.Length - 1];
- uint[] colorTable = null;
- foreach (var parser in GetParsers())
- {
- uint[] table = parser.ParseScheme(schemeName);
- if (table != null)
- {
- colorTable = table;
- break;
- }
- }
+ uint[] colorTable = GetSchemeUints(schemeName);
if (colorTable == null)
{
@@ -342,5 +388,18 @@ namespace ColorTool
.Where(t => !t.IsAbstract && typeof(ISchemeParser).IsAssignableFrom(t))
.Select(t => (ISchemeParser)Activator.CreateInstance(t));
}
+
+ private static uint[] GetSchemeUints(string schemeName, bool reportErrors = true)
+ {
+ foreach (var parser in GetParsers())
+ {
+ uint[] table = parser.ParseScheme(schemeName, reportErrors);
+ if (table != null)
+ {
+ return table;
+ }
+ }
+ return null;
+ }
}
}
diff --git a/tools/ColorTool/ColorTool/Properties/launchSettings.json b/tools/ColorTool/ColorTool/Properties/launchSettings.json
new file mode 100644
index 000000000..5183ca3e3
--- /dev/null
+++ b/tools/ColorTool/ColorTool/Properties/launchSettings.json
@@ -0,0 +1,7 @@
+{
+ "profiles": {
+ "ColorTool": {
+ "commandName": "Project"
+ }
+ }
+}
\ No newline at end of file
diff --git a/tools/ColorTool/ColorTool/Resources.Designer.cs b/tools/ColorTool/ColorTool/Resources.Designer.cs
index 05b1cae0b..820f2a57d 100644
--- a/tools/ColorTool/ColorTool/Resources.Designer.cs
+++ b/tools/ColorTool/ColorTool/Resources.Designer.cs
@@ -1,143 +1,143 @@
-//------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
-// Runtime Version:4.0.30319.42000
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
-//------------------------------------------------------------------------------
-
-namespace ColorTool {
- using System;
-
-
- ///
- /// A strongly-typed resource class, for looking up localized strings, etc.
- ///
- // This class was auto-generated by the StronglyTypedResourceBuilder
- // class via a tool like ResGen or Visual Studio.
- // To add or remove a member, edit your .ResX file then rerun ResGen
- // with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- public class Resources {
-
- private static global::System.Resources.ResourceManager resourceMan;
-
- private static global::System.Globalization.CultureInfo resourceCulture;
-
- [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources() {
- }
-
- ///
- /// Returns the cached ResourceManager instance used by this class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- public static global::System.Resources.ResourceManager ResourceManager {
- get {
- if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ColorTool.Resources", typeof(Resources).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
-
- ///
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- public static global::System.Globalization.CultureInfo Culture {
- get {
- return resourceCulture;
- }
- set {
- resourceCulture = value;
- }
- }
-
- ///
- /// Looks up a localized string similar to Error loading ini file "{0}".
- ///
- public static string IniLoadError {
- get {
- return ResourceManager.GetString("IniLoadError", resourceCulture);
- }
- }
-
- ///
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace ColorTool {
+ using System;
+
+
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ public class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Returns the cached ResourceManager instance used by this class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ public static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ColorTool.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ public static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Error loading ini file "{0}".
+ ///
+ public static string IniLoadError {
+ get {
+ return ResourceManager.GetString("IniLoadError", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Error loading ini file "{0}"
/// for key "{1}"
- /// the value "{2}" is invalid.
- ///
- public static string IniParseError {
- get {
- return ResourceManager.GetString("IniParseError", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Invalid Color.
- ///
- public static string InvalidColor {
- get {
- return ResourceManager.GetString("InvalidColor", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Invalid scheme - did not find 16 colors.
- ///
- public static string InvalidNumberOfColors {
- get {
- return ResourceManager.GetString("InvalidNumberOfColors", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Usage: colortool -o <filename>.
- ///
- public static string OutputUsage {
- get {
- return ResourceManager.GetString("OutputUsage", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Could not find or load "{0}".
- ///
- public static string SchemeNotFound {
- get {
- return ResourceManager.GetString("SchemeNotFound", resourceCulture);
- }
- }
-
- ///
+ /// the value "{2}" is invalid.
+ ///
+ public static string IniParseError {
+ get {
+ return ResourceManager.GetString("IniParseError", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Invalid Color.
+ ///
+ public static string InvalidColor {
+ get {
+ return ResourceManager.GetString("InvalidColor", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Invalid scheme - did not find 16 colors.
+ ///
+ public static string InvalidNumberOfColors {
+ get {
+ return ResourceManager.GetString("InvalidNumberOfColors", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Usage: colortool -o <filename>.
+ ///
+ public static string OutputUsage {
+ get {
+ return ResourceManager.GetString("OutputUsage", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Could not find or load "{0}".
+ ///
+ public static string SchemeNotFound {
+ get {
+ return ResourceManager.GetString("SchemeNotFound", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Usage:
/// colortool.exe [options] <schemename>
///ColorTool is a utility for helping to set the color palette of the Windows Console.
///By default, applies the colors in the specified .itermcolors or .ini file to the current console window.
///This does NOT save the properties automatically. For that, you'll need to open the properties sheet and hit "Ok".
///Included should be a `schemes/` directory with a selection of schemes of both formats for examples.
- ///Feel free to add your own preferred scheme to that dire [rest of string was truncated]";.
- ///
- public static string Usage {
- get {
- return ResourceManager.GetString("Usage", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Wrote selected scheme to the defaults..
- ///
- public static string WroteToDefaults {
- get {
- return ResourceManager.GetString("WroteToDefaults", resourceCulture);
- }
- }
- }
-}
+ ///Feel free to add your own preferred scheme to that directory. [rest of string was truncated]";.
+ ///
+ public static string Usage {
+ get {
+ return ResourceManager.GetString("Usage", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Wrote selected scheme to the defaults..
+ ///
+ public static string WroteToDefaults {
+ get {
+ return ResourceManager.GetString("WroteToDefaults", resourceCulture);
+ }
+ }
+ }
+}
diff --git a/tools/ColorTool/ColorTool/Resources.resx b/tools/ColorTool/ColorTool/Resources.resx
index c603925e3..bdc439f9e 100644
--- a/tools/ColorTool/ColorTool/Resources.resx
+++ b/tools/ColorTool/ColorTool/Resources.resx
@@ -154,6 +154,7 @@ Options:
-q, --quiet : Don't print the color table after applying
-d, --defaults : Apply the scheme to only the defaults in the registry
-b, --both : Apply the scheme to both the current console and the defaults.
+ -s, --schemes : Displays all available schemes
-v, --version : Display the version number
-o, --output <filename> : output the current color table to an file (in .ini format)
diff --git a/tools/ColorTool/ColorTool/XmlSchemeParser.cs b/tools/ColorTool/ColorTool/XmlSchemeParser.cs
index d1b1424b1..2aa035af7 100644
--- a/tools/ColorTool/ColorTool/XmlSchemeParser.cs
+++ b/tools/ColorTool/ColorTool/XmlSchemeParser.cs
@@ -123,7 +123,7 @@ namespace ColorTool
}
- public uint[] ParseScheme(string schemeName)
+ public uint[] ParseScheme(string schemeName, bool reportErrors = true)
{
XmlDocument xmlDoc = loadXmlScheme(schemeName); // Create an XML document object
if (xmlDoc == null) return null;
@@ -167,7 +167,10 @@ namespace ColorTool
}
if (colorsFound < COLOR_TABLE_SIZE)
{
- Console.WriteLine(Resources.InvalidNumberOfColors);
+ if (reportErrors)
+ {
+ Console.WriteLine(Resources.InvalidNumberOfColors);
+ }
success = false;
}
if (!success)
diff --git a/tools/ColorTool/README.md b/tools/ColorTool/README.md
index 5ebdd1ce6..fba2abbae 100644
--- a/tools/ColorTool/README.md
+++ b/tools/ColorTool/README.md
@@ -17,6 +17,7 @@ Options:
-q, --quiet : Don't print the color table after applying
-d, --defaults : Apply the scheme to only the defaults in the registry
-b, --both : Apply the scheme to both the current console and the defaults.
+ -s, --schemes : Display all available schemes
-v, --version : Display the version number
```