static private CoreCommand ParseCmd(string cmd_with_args, string pipe_string = null) { KeyValuePair <string, string> kCmd = getCmdArgs(cmd_with_args); if (kCmd.Key.Length.Equals(0)) { return(null); } if (isValidCommand(kCmd.Key).Equals(false)) { CoreCommand.ConsoleWrite_Atom("command '{0}' not found", kCmd.Key); last_message_saved = last_message; return(null); } // load command CoreCommand cmd = Core.core_commands[kCmd.Key]; // prepare context cmd.results = pipe_string; //cmd.result_type = CoreCommand.RESULT_TYPE.NONE; cmd.cmd_with_args = cmd_with_args; cmd.cmd_without_args = kCmd.Key; cmd.args = kCmd.Value; cmd.last_message = last_message; //last_message = ""; // clear last_write/last_message used between pipes // execute command cmd.Run(); last_message_saved = last_message; return(cmd); }
static public string ParseTypedCmds(string prompt_cmds, bool force_silent = false) { if (string.IsNullOrEmpty(prompt_cmds)) { return(""); } prompt_cmds = TagCommandlineChars(prompt_cmds); string lres = "", last = ""; CoreCommand cmd = null; foreach (string cmd_with_args_and_pipes in prompt_cmds.Split(';')) // cmd1;cmd2|cmd3 { //bool isPipe = false; string[] cmd_with_args_pipeables = cmd_with_args_and_pipes.Split('|'); silent = cmd_with_args_pipeables.Length > 1; for (int i = 0; i < cmd_with_args_pipeables.Length; i++) { bool isLast = i == cmd_with_args_pipeables.Length - 1; string cmd_with_args = UntagCommandlineChars(cmd_with_args_pipeables[i]); if (!force_silent && isLast) { silent = false; } cmd = ParseCmd(cmd_with_args, last_message); //Console.WriteLine("debug>> cmd '{0}', piping '{1}' bytes, result '{2}' bytes type '{3}", // cmd_with_args, last_message.Length, cmd.results.Length, cmd.result_type); if (cmd == null) { continue; } if (cmd.result_type.Equals(CoreCommand.RESULT_TYPE.COMMANDS) /* || cmd.result_type.Equals(CoreCommand.RESULT_TYPE.NONE)*/) { string new_command = cmd.results; if (new_command.Contains("{ARGS}")) { new_command = new_command.Replace("{ARGS}", cmd.args); } else { new_command += " " + cmd.args; } lres = ParseTypedCmds(new_command, !isLast && Core.getCommandProperties(cmd_with_args).is_alias); // output are more commands last_message = lres; } else if (cmd.results != null && cmd.result_type.Equals(CoreCommand.RESULT_TYPE.NONE).Equals(false)) { //CoreCommand.ConsoleWrite(last_message); //CoreCommand.ConsoleWrite("Results: '{0}' Type: {1}", cmd.results, cmd.result_type.ToString()); } } last = Core.last_message; Core.last_message = ""; } return(last); }
public override string Help(params string[] help_args) { string name = help_args[0]; if (name.Equals("alias")) { return("I'm the alias command. Try: alias or alias [name] or alias [newalias] [commands]"); } return(string.Format("{0}{1}", CoreCommand.AnsiColorize("$ "), Core.EncodeNoAscii(Core.aliases[name]))); }
static private void AddNewCommand(string command, CoreCommand commandManager, CommandProperty properties) { bool isSetting = command.Equals("set").Equals(false) && commandManager.Equals(settingsManager); bool isAlias = commandManager.Equals(aliasManager); CommandProperty prop = (CommandProperty)properties.Clone(); prop.is_setting = isSetting; core_commands.Add(command, commandManager); RegisterNewProperty(command, prop); }
public IEnumerable <string> doLoop() { while (this.loop) { Console.Write(Core.UntagCommandlineChars(CoreCommand.AnsiColorize(this.PS1))); yield return(Console.ReadLine()); refreshVars(); } yield return(null); }