From a3cd6c0e6045d12f0cb8c9355bcd50f12e367f3b Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 17 Jun 2017 21:03:27 -0400 Subject: [PATCH] Commands are parsed with a bash-style syntax by default --- ShiftOS.WinForms/Applications/Terminal.cs | 18 +++++--------- ShiftOS_TheReturn/CommandParser.cs | 29 +++++++++++++++-------- ShiftOS_TheReturn/Skinning.cs | 3 +++ ShiftOS_TheReturn/TerminalBackend.cs | 17 +++++-------- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 0470d68..54329df 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -260,23 +260,17 @@ namespace ShiftOS.WinForms.Applications } else { - if (CurrentCommandParser.parser == null) + var result = SkinEngine.LoadedSkin.CurrentParser.ParseCommand(text3); + + if (result.Equals(default(KeyValuePair>))) { - TerminalBackend.InvokeCommand(text3); + Console.WriteLine("{ERR_SYNTAXERROR}"); } else { - var result = CurrentCommandParser.parser.ParseCommand(text3); - - if (result.Equals(default(KeyValuePair, Dictionary>))) - { - Console.WriteLine("Syntax Error: Syntax Error"); - } - else - { - TerminalBackend.InvokeCommand(result.Key.Key, result.Key.Value, result.Value); - } + TerminalBackend.InvokeCommand(result.Key, result.Value); } + } } if (TerminalBackend.PrefixEnabled) diff --git a/ShiftOS_TheReturn/CommandParser.cs b/ShiftOS_TheReturn/CommandParser.cs index 868d27a..da1073f 100644 --- a/ShiftOS_TheReturn/CommandParser.cs +++ b/ShiftOS_TheReturn/CommandParser.cs @@ -85,10 +85,9 @@ namespace ShiftOS.Engine /// /// The command string to parse. /// The parsed command, ready to be invoked. - public KeyValuePair, Dictionary> ParseCommand(string cdd) + public KeyValuePair> ParseCommand(string cdd) { string command = ""; - string ns = ""; Dictionary arguments = new Dictionary(); string text = cdd; @@ -142,12 +141,7 @@ namespace ShiftOS.Engine if (part is CommandFormatMarker) { - if (part is CommandFormatNamespace) - { - ns = res; - help = -1; - } - else if (part is CommandFormatCommand) + if (part is CommandFormatCommand) { command = res; help = -1; @@ -197,7 +191,7 @@ namespace ShiftOS.Engine if (command == "+FALSE+") { //lblExampleCommand.Text = "Syntax Error"; - return new KeyValuePair, Dictionary>(); + return new KeyValuePair>(); } else { @@ -210,9 +204,24 @@ namespace ShiftOS.Engine argvs += "}"; lblExampleCommand.Text = command + argvs;*/ - return new KeyValuePair, Dictionary>(new KeyValuePair(ns, command), arguments); + return new KeyValuePair>(command, arguments); } } + + internal static CommandParser GenerateSample() + { + var parser = new CommandParser(); + parser.AddPart(new CommandFormatCommand()); + parser.AddPart(new CommandFormatText(" --")); + parser.AddPart(new CommandFormatArgument()); + parser.AddPart(new CommandFormatText(" ")); + parser.AddPart(new CommandFormatValue()); + parser.AddPart(new CommandFormatText(" --")); + parser.AddPart(new CommandFormatArgument()); + parser.AddPart(new CommandFormatText(" ")); + parser.AddPart(new CommandFormatValue()); + return parser; + } } public class CFValue diff --git a/ShiftOS_TheReturn/Skinning.cs b/ShiftOS_TheReturn/Skinning.cs index ab2d6b1..e00a2ef 100644 --- a/ShiftOS_TheReturn/Skinning.cs +++ b/ShiftOS_TheReturn/Skinning.cs @@ -637,6 +637,9 @@ namespace ShiftOS.Engine [ShifterDescription("The maximize button color")] public Color MaximizeButtonColor = Accent1; + [ShifterHidden] + public CommandParser CurrentParser = CommandParser.GenerateSample(); + [ShifterMeta("Windows")] [ShifterCategory("Title Buttons")] [ShifterName("Minimize Button Color")] diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 1ca31e0..d60b675 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -92,30 +92,25 @@ namespace ShiftOS.Engine /// /// Invokes a ShiftOS terminal command. /// - /// The command's namespace. /// The command name. /// The command arguments. /// Whether the command should be sent through Remote Terminal Session (RTS). - public static void InvokeCommand(string ns, string command, Dictionary arguments, bool isRemote = false) + public static void InvokeCommand(string command, Dictionary arguments, bool isRemote = false) { try { - if (string.IsNullOrWhiteSpace(ns)) - return; + bool commandWasClient = RunClient(command, arguments, isRemote); - - bool commandWasClient = RunClient(ns, command, arguments, isRemote); - - if (!commandWasClient && !string.IsNullOrWhiteSpace(ns)) + if (!commandWasClient) { - Console.WriteLine("Error: Command not found."); + Console.WriteLine("{ERR_COMMANDNOTFOUND}"); } - CommandProcessed?.Invoke(ns + "." + command, JsonConvert.SerializeObject(arguments)); + CommandProcessed?.Invoke(command, JsonConvert.SerializeObject(arguments)); } catch (Exception ex) { - Console.WriteLine($"Command parse error: {ex.Message}"); // This shouldn't ever be called now + Console.WriteLine("{ERR_SYNTAXERROR}"); PrefixEnabled = true; }