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>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CC-Functions.Commandline" Version="1.1.7548.35332" />
|
||||
<PackageReference Include="CC-Functions.Commandline" Version="1.1.7559.17553" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,13 +1,10 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
using System.Threading;
|
||||
using CC_Functions.Commandline;
|
||||
using CC_Functions.Commandline.TUI;
|
||||
using CC_Functions.Misc;
|
||||
using D = CC_Functions.Commandline.TUI.DiffDraw;
|
||||
using CC_Functions.Core;
|
||||
using D = CC_Functions.Commandline.DiffDraw;
|
||||
|
||||
namespace OnScreenKeyboard
|
||||
{
|
||||
@ -20,12 +17,14 @@ namespace OnScreenKeyboard
|
||||
private static Point _ballSpeed = new Point(1, -1);
|
||||
private static int _peddle = 0;
|
||||
private static string _input = "";
|
||||
static void Main(string[] args)
|
||||
static void Main(string[] a)
|
||||
{
|
||||
ArgsParse args = new ArgsParse(a);
|
||||
//args
|
||||
if (args.GetBool("help") || args.GetBool("?") || args.GetBool("h"))
|
||||
{
|
||||
Console.WriteLine(@"JF OSK v1
|
||||
Shows an interactive keyboard (stdout and stdin) and logs the output to stderr
|
||||
|
||||
Usage:
|
||||
OSK [arguments]
|
||||
@ -34,12 +33,11 @@ Arguments:
|
||||
delay The time to wait between ball movements.
|
||||
no-color Do not output color. Use only if color doesn't work.
|
||||
peddle-length The length of the peddle.
|
||||
output Output the result to a file.
|
||||
|
||||
Examples:
|
||||
OSK --delay:0.3 --peddle-length:3
|
||||
OSK --no-color --output:file.txt
|
||||
OSK");
|
||||
OSK --no-color
|
||||
OSK 2> output.txt");
|
||||
return;
|
||||
}
|
||||
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));
|
||||
if (peddleLength > Width)
|
||||
peddleLength = Width;
|
||||
string outputFile = args.Get("output");
|
||||
//init
|
||||
Console.BackgroundColor = ConsoleColor.Black;
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
@ -156,16 +153,7 @@ Examples:
|
||||
}
|
||||
Console.ResetColor();
|
||||
Console.Clear();
|
||||
Console.WriteLine(_input);
|
||||
if (outputFile != null)
|
||||
try
|
||||
{
|
||||
File.WriteAllText(outputFile, _input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Could not save output: {e.Message}");
|
||||
}
|
||||
Console.Error.WriteLine(_input);
|
||||
}
|
||||
|
||||
private static void DrawString(Point start, string chars, ConsoleColor foreColor, ConsoleColor backColor)
|
||||
|
Reference in New Issue
Block a user