public void ExecuteCommand(string command) { if (string.IsNullOrEmpty(command)) { return; } outputList.Add(command); commandHistory.Insert(0, command); EditorInvoker.Invoke(() => { try { object result = CommandExecuter.ExecuteCommandLine(command); string text = result == null ? "" : result.ToString(); if (!string.IsNullOrEmpty(text)) { outputList.Add(text); } } catch (Exception e) { if (e is TargetParameterCountException) { outputList.Add($"ERROR: parameters do not match {command} command signature"); } else { outputList.Add("ERROR: " + e.Message); Debug.LogException(e); } } Repaint(); }); }
public void ContemplateOptions() { CommandExecuter.ParseCommand(currentCommand, out string commandName, out string[] args); options.Clear(); ICommand command = CommandExecuter.FindCommand(x => x != null && x.Name == commandName); if (command != null && (args.Length > 0 || currentCommand.EndsWith(" "))) { currentArg = Mathf.Max(0, args.Length - 1); string currentText = ""; if (currentArg < args.Length) { currentText = args[currentArg]; } if (currentCommand.EndsWith(" ") && args.Length > 0) { currentArg += 1; currentText = ""; } if (!cachedSuggestions.TryGetValue(currentArg, out List <string> suggestions)) { suggestions = command.GetSuggestions(currentArg); cachedSuggestions.Add(currentArg, suggestions); } else { suggestions = cachedSuggestions[currentArg]; } foreach (string s in suggestions) { if (s.Contains(currentText) || currentText == "") { options.Add(new AutocompleteOption(s)); } } } else { currentArg = -1; cachedSuggestions.Clear(); // Show commands autocomplete foreach (var c in CommandExecuter.CommandListReadOnly) { if (c != null && c.Name.Contains(commandName)) { StringBuilder additional = new StringBuilder(c.Name); foreach (var arg in c.ParamInfo) { if (arg == null) { additional.Append(" unknown"); } else { additional.Append(" ").Append(arg.ParameterName); } } var o = new AutocompleteOption(c.Name, additional.ToString()); options.Add(o); } } } selectionInDropDown = -1; selectionInHistory = -1; showDropDown = true; }