From f2b251b16c1ace58f9ea457e8e2382cccfc97700 Mon Sep 17 00:00:00 2001 From: JFronny <33260128+JFronny@users.noreply.github.com> Date: Fri, 11 Sep 2020 13:31:51 +0200 Subject: [PATCH] Use ArgsParse API (CC_F) --- OnScreenKeyboard/ArgsParse.cs | 21 ----------------- OnScreenKeyboard/OnScreenKeyboard.csproj | 2 +- OnScreenKeyboard/Program.cs | 30 +++++++----------------- 3 files changed, 10 insertions(+), 43 deletions(-) delete mode 100644 OnScreenKeyboard/ArgsParse.cs diff --git a/OnScreenKeyboard/ArgsParse.cs b/OnScreenKeyboard/ArgsParse.cs deleted file mode 100644 index 7b6b8c7..0000000 --- a/OnScreenKeyboard/ArgsParse.cs +++ /dev/null @@ -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(this string[] args, string argName, Func func) => func(args.Get(argName)); - - public static bool GetBool(this string[] args, string argName) => args.Any(s => s.ToLower().TrimStart('-', '/') == argName.ToLower()); - } -} \ No newline at end of file diff --git a/OnScreenKeyboard/OnScreenKeyboard.csproj b/OnScreenKeyboard/OnScreenKeyboard.csproj index 52fffb0..fe2c05a 100644 --- a/OnScreenKeyboard/OnScreenKeyboard.csproj +++ b/OnScreenKeyboard/OnScreenKeyboard.csproj @@ -15,7 +15,7 @@ - + diff --git a/OnScreenKeyboard/Program.cs b/OnScreenKeyboard/Program.cs index a0078fe..dde91ad 100644 --- a/OnScreenKeyboard/Program.cs +++ b/OnScreenKeyboard/Program.cs @@ -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)