Merge branch 'dynamic-parser-list' of https://github.com/twsouthwick/console into tsouthwich-dynamic-parser-list
This commit is contained in:
commit
21b618648b
|
@ -7,6 +7,8 @@ namespace ColorTool
|
|||
{
|
||||
interface ISchemeParser
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
uint[] ParseScheme(string schemeName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace ColorTool
|
|||
[DllImport("kernel32")]
|
||||
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
|
||||
|
||||
// These are in Windows Color table order - BRG, not RGB.
|
||||
// These are in Windows Color table order - BRG, not RGB.
|
||||
public static string[] COLOR_NAMES = {
|
||||
"DARK_BLACK",
|
||||
"DARK_BLUE",
|
||||
|
@ -36,6 +36,8 @@ namespace ColorTool
|
|||
"BRIGHT_WHITE"
|
||||
};
|
||||
|
||||
public string Name => "INI File Parser";
|
||||
|
||||
static uint ParseHex(string arg)
|
||||
{
|
||||
System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml(arg);
|
||||
|
@ -44,11 +46,12 @@ namespace ColorTool
|
|||
|
||||
static uint ParseRgb(string arg)
|
||||
{
|
||||
int[] components = { 0, 0, 0};
|
||||
int[] components = { 0, 0, 0 };
|
||||
string[] args = arg.Split(',');
|
||||
if (args.Length != components.Length) throw new Exception("Invalid color format \"" + arg + "\"");
|
||||
if (args.Length != 3) throw new Exception("Invalid color format \"" + arg + "\"");
|
||||
for (int i = 0; i < args.Length; i++){
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
components[i] = Int32.Parse(args[i]);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
// Licensed under the terms described in the LICENSE file in the root of this project.
|
||||
//
|
||||
|
||||
using System;
|
||||
using static ColorTool.ConsoleAPI;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using static ColorTool.ConsoleAPI;
|
||||
|
||||
namespace ColorTool
|
||||
{
|
||||
|
@ -86,7 +88,8 @@ namespace ColorTool
|
|||
|
||||
static void Usage()
|
||||
{
|
||||
Console.WriteLine(Resources.Usage);
|
||||
Console.WriteLine(Resources.Usage,
|
||||
string.Join($"{Environment.NewLine} ", GetParsers().Select(p => p.Name)));
|
||||
}
|
||||
|
||||
static void OutputUsage()
|
||||
|
@ -141,7 +144,7 @@ namespace ColorTool
|
|||
"46m",
|
||||
"47m"
|
||||
};
|
||||
|
||||
|
||||
Console.Write("\t");
|
||||
for (int bg = 0; bg < BGs.Length; bg++)
|
||||
{
|
||||
|
@ -307,8 +310,7 @@ namespace ColorTool
|
|||
string schemeName = args[args.Length - 1];
|
||||
|
||||
uint[] colorTable = null;
|
||||
ISchemeParser[] parsers = { new XmlSchemeParser(), new IniSchemeParser() };
|
||||
foreach (var parser in parsers)
|
||||
foreach (var parser in GetParsers())
|
||||
{
|
||||
uint[] table = parser.ParseScheme(schemeName);
|
||||
if (table != null)
|
||||
|
@ -334,5 +336,11 @@ namespace ColorTool
|
|||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<ISchemeParser> GetParsers()
|
||||
{
|
||||
return typeof(Program).Assembly.GetTypes()
|
||||
.Where(t => !t.IsAbstract && typeof(ISchemeParser).IsAssignableFrom(t))
|
||||
.Select(t => (ISchemeParser)Activator.CreateInstance(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
4
tools/ColorTool/ColorTool/Resources.Designer.cs
generated
4
tools/ColorTool/ColorTool/Resources.Designer.cs
generated
|
@ -19,7 +19,7 @@ namespace ColorTool {
|
|||
// 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", "4.0.0.0")]
|
||||
[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 {
|
||||
|
@ -123,7 +123,7 @@ namespace ColorTool {
|
|||
///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 prefered scheme to that direc [rest of string was truncated]";.
|
||||
///Feel free to add your own preferred scheme to that dire [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
public static string Usage {
|
||||
get {
|
||||
|
|
|
@ -156,7 +156,9 @@ Options:
|
|||
-b, --both : Apply the scheme to both the current console and the defaults.
|
||||
-v, --version : Display the version number
|
||||
-o, --output <filename> : output the current color table to an file (in .ini format)
|
||||
</value>
|
||||
|
||||
Available importers:
|
||||
{0}</value>
|
||||
</data>
|
||||
<data name="WroteToDefaults" xml:space="preserve">
|
||||
<value>Wrote selected scheme to the defaults.</value>
|
||||
|
|
|
@ -34,6 +34,8 @@ namespace ColorTool
|
|||
static string GREEN_KEY = "Green Component";
|
||||
static string BLUE_KEY = "Blue Component";
|
||||
|
||||
public string Name => "iTerm Parser";
|
||||
|
||||
static bool parseRgbFromXml(XmlNode components, ref uint rgb)
|
||||
{
|
||||
int r = -1;
|
||||
|
|
Loading…
Reference in a new issue