Merge.
This commit is contained in:
commit
550e197684
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
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)
|
||||
{
|
||||
foreach (var parser in GetParsers())
|
||||
{
|
||||
uint[] table = parser.ParseScheme(schemeName);
|
||||
if (table != null)
|
||||
{
|
||||
return table;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
270
tools/ColorTool/ColorTool/Resources.Designer.cs
generated
270
tools/ColorTool/ColorTool/Resources.Designer.cs
generated
|
@ -1,143 +1,143 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ColorTool {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// 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() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error loading ini file "{0}".
|
||||
/// </summary>
|
||||
public static string IniLoadError {
|
||||
get {
|
||||
return ResourceManager.GetString("IniLoadError", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ColorTool {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// 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() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error loading ini file "{0}".
|
||||
/// </summary>
|
||||
public static string IniLoadError {
|
||||
get {
|
||||
return ResourceManager.GetString("IniLoadError", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error loading ini file "{0}"
|
||||
/// for key "{1}"
|
||||
/// the value "{2}" is invalid.
|
||||
/// </summary>
|
||||
public static string IniParseError {
|
||||
get {
|
||||
return ResourceManager.GetString("IniParseError", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Invalid Color.
|
||||
/// </summary>
|
||||
public static string InvalidColor {
|
||||
get {
|
||||
return ResourceManager.GetString("InvalidColor", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Invalid scheme - did not find 16 colors.
|
||||
/// </summary>
|
||||
public static string InvalidNumberOfColors {
|
||||
get {
|
||||
return ResourceManager.GetString("InvalidNumberOfColors", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Usage: colortool -o <filename>.
|
||||
/// </summary>
|
||||
public static string OutputUsage {
|
||||
get {
|
||||
return ResourceManager.GetString("OutputUsage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Could not find or load "{0}".
|
||||
/// </summary>
|
||||
public static string SchemeNotFound {
|
||||
get {
|
||||
return ResourceManager.GetString("SchemeNotFound", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the value "{2}" is invalid.
|
||||
/// </summary>
|
||||
public static string IniParseError {
|
||||
get {
|
||||
return ResourceManager.GetString("IniParseError", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Invalid Color.
|
||||
/// </summary>
|
||||
public static string InvalidColor {
|
||||
get {
|
||||
return ResourceManager.GetString("InvalidColor", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Invalid scheme - did not find 16 colors.
|
||||
/// </summary>
|
||||
public static string InvalidNumberOfColors {
|
||||
get {
|
||||
return ResourceManager.GetString("InvalidNumberOfColors", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Usage: colortool -o <filename>.
|
||||
/// </summary>
|
||||
public static string OutputUsage {
|
||||
get {
|
||||
return ResourceManager.GetString("OutputUsage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Could not find or load "{0}".
|
||||
/// </summary>
|
||||
public static string SchemeNotFound {
|
||||
get {
|
||||
return ResourceManager.GetString("SchemeNotFound", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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]";.
|
||||
/// </summary>
|
||||
public static string Usage {
|
||||
get {
|
||||
return ResourceManager.GetString("Usage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Wrote selected scheme to the defaults..
|
||||
/// </summary>
|
||||
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]";.
|
||||
/// </summary>
|
||||
public static string Usage {
|
||||
get {
|
||||
return ResourceManager.GetString("Usage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Wrote selected scheme to the defaults..
|
||||
/// </summary>
|
||||
public static string WroteToDefaults {
|
||||
get {
|
||||
return ResourceManager.GetString("WroteToDefaults", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue