Use ArgsParse API (CC_F)
This commit is contained in:
parent
f7dbac1d6e
commit
f2b251b16c
|
@ -1,21 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace OnScreenKeyboard
|
|
||||||
{
|
|
||||||
public static class ArgsParse
|
|
||||||
{
|
|
||||||
public static string Get(this string[] args, string argName)
|
|
||||||
{
|
|
||||||
string selected = null;
|
|
||||||
foreach (string s in args)
|
|
||||||
if (s.TrimStart('-', '/').ToLower().StartsWith($"{argName.ToLower()}:"))
|
|
||||||
selected = string.Join("", s.TrimStart('-', '/').Skip(argName.Length + 1));
|
|
||||||
return selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T Get<T>(this string[] args, string argName, Func<string, T> func) => func(args.Get(argName));
|
|
||||||
|
|
||||||
public static bool GetBool(this string[] args, string argName) => args.Any(s => s.ToLower().TrimStart('-', '/') == argName.ToLower());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,7 +15,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CC-Functions.Commandline" Version="1.1.7548.35332" />
|
<PackageReference Include="CC-Functions.Commandline" Version="1.1.7559.17553" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using CC_Functions.Commandline;
|
||||||
using System.Linq;
|
|
||||||
using System.Security;
|
|
||||||
using System.Threading;
|
|
||||||
using CC_Functions.Commandline.TUI;
|
using CC_Functions.Commandline.TUI;
|
||||||
using CC_Functions.Misc;
|
using CC_Functions.Core;
|
||||||
using D = CC_Functions.Commandline.TUI.DiffDraw;
|
using D = CC_Functions.Commandline.DiffDraw;
|
||||||
|
|
||||||
namespace OnScreenKeyboard
|
namespace OnScreenKeyboard
|
||||||
{
|
{
|
||||||
|
@ -20,12 +17,14 @@ namespace OnScreenKeyboard
|
||||||
private static Point _ballSpeed = new Point(1, -1);
|
private static Point _ballSpeed = new Point(1, -1);
|
||||||
private static int _peddle = 0;
|
private static int _peddle = 0;
|
||||||
private static string _input = "";
|
private static string _input = "";
|
||||||
static void Main(string[] args)
|
static void Main(string[] a)
|
||||||
{
|
{
|
||||||
|
ArgsParse args = new ArgsParse(a);
|
||||||
//args
|
//args
|
||||||
if (args.GetBool("help") || args.GetBool("?") || args.GetBool("h"))
|
if (args.GetBool("help") || args.GetBool("?") || args.GetBool("h"))
|
||||||
{
|
{
|
||||||
Console.WriteLine(@"JF OSK v1
|
Console.WriteLine(@"JF OSK v1
|
||||||
|
Shows an interactive keyboard (stdout and stdin) and logs the output to stderr
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
OSK [arguments]
|
OSK [arguments]
|
||||||
|
@ -34,12 +33,11 @@ Arguments:
|
||||||
delay The time to wait between ball movements.
|
delay The time to wait between ball movements.
|
||||||
no-color Do not output color. Use only if color doesn't work.
|
no-color Do not output color. Use only if color doesn't work.
|
||||||
peddle-length The length of the peddle.
|
peddle-length The length of the peddle.
|
||||||
output Output the result to a file.
|
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
OSK --delay:0.3 --peddle-length:3
|
OSK --delay:0.3 --peddle-length:3
|
||||||
OSK --no-color --output:file.txt
|
OSK --no-color
|
||||||
OSK");
|
OSK 2> output.txt");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TimeSpan ballSpeed = args.Get("delay", s => s == null ? new TimeSpan(0, 0, 1) : TimeSpan.Parse($"0:0:0:{s}", CultureInfo.InvariantCulture));
|
TimeSpan ballSpeed = args.Get("delay", s => s == null ? new TimeSpan(0, 0, 1) : TimeSpan.Parse($"0:0:0:{s}", CultureInfo.InvariantCulture));
|
||||||
|
@ -47,7 +45,6 @@ Examples:
|
||||||
int peddleLength = args.Get("peddle-length", s => s == null ? 4 : int.Parse(s, CultureInfo.InvariantCulture));
|
int peddleLength = args.Get("peddle-length", s => s == null ? 4 : int.Parse(s, CultureInfo.InvariantCulture));
|
||||||
if (peddleLength > Width)
|
if (peddleLength > Width)
|
||||||
peddleLength = Width;
|
peddleLength = Width;
|
||||||
string outputFile = args.Get("output");
|
|
||||||
//init
|
//init
|
||||||
Console.BackgroundColor = ConsoleColor.Black;
|
Console.BackgroundColor = ConsoleColor.Black;
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
@ -156,16 +153,7 @@ Examples:
|
||||||
}
|
}
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine(_input);
|
Console.Error.WriteLine(_input);
|
||||||
if (outputFile != null)
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File.WriteAllText(outputFile, _input);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Could not save output: {e.Message}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DrawString(Point start, string chars, ConsoleColor foreColor, ConsoleColor backColor)
|
private static void DrawString(Point start, string chars, ConsoleColor foreColor, ConsoleColor backColor)
|
||||||
|
|
Reference in New Issue