コード例 #1
0
        private void OnInputSubmitted(string input)
        {
            // First check that some input was submitted
            // If input is only whitespace, just clear the input and do nothing
            if (string.IsNullOrWhiteSpace(input))
            {
                InputField.text = string.Empty;
                InputField.ActivateInputField();
                return;
            }

            DeveloperConsole.Log($"{InputFieldPrefix.Text} {InputField.text}");

            mInputHistoryCache = string.Empty;
            mInputHistory.Insert(0, input);
            if (mInputHistory.Count > ConsoleSettings.MaxInputHistory)
            {
                mInputHistory.RemoveAt(mInputHistory.Count - 1);
            }

            // Copy input into the draft array
            mInputHistoryDraft.Clear();
            mInputHistoryDraft.AddRange(mInputHistory);

            mInputHistoryEdittingIndex = -1;
            InputField.text            = null;
            InputField.ActivateInputField();

            // Send the user's input to the console
            DeveloperConsole.Console.OnInputReceived(input);
        }
コード例 #2
0
        public override void Invoke(string data)
        {
            if (!MethodParser.TryParse(data, out var arguments))
            {
                // Failed to parse input. Show usage
                DeveloperConsole.Log(Help);
                return;
            }

            Method.Invoke(Target, arguments);
        }
コード例 #3
0
            public void Invoke(string data)
            {
                var args = DeveloperConsole.SplitArgs(data);

                if (args.Length != 0)
                {
                    LogWarning(Help);
                }
                else
                {
                    DeveloperConsole.Log(DeveloperConsole.WorkingDirectory);
                }
            }
コード例 #4
0
            public void Invoke(string data)
            {
                var args = DeveloperConsole.SplitArgs(data);

                if (args.Length > 1)
                {
                    LogWarning(kUsage);
                    return;
                }

                string dirPath;

                if (args.Length == 1)
                {
                    if (!TryNavigateDirectory(args[0], out dirPath))
                    {
                        // Inputted directory does not exist
                        LogWarning("not a directory");
                        return;
                    }
                }
                else
                {
                    dirPath = DeveloperConsole.WorkingDirectory;
                }

                // Get all directories and files in the current path and alphabetize
                var entries = Directory.GetFileSystemEntries(dirPath, "*", SearchOption.TopDirectoryOnly)
                              .OrderBy(e => e);

                // Write directories to console
                StringBuilder sb = new StringBuilder();

                foreach (var entry in entries)
                {
                    ConsoleUtilities.TryGetRelative(dirPath, entry, out var formatted);
                    if (Directory.Exists(entry))
                    {
                        formatted = $"<color=#{kDirectoryColorHtml}>{formatted}</color>";
                    }
                    sb.AppendLine(formatted);
                }

                DeveloperConsole.Log(sb.ToString());
            }
コード例 #5
0
        public void Invoke(string data)
        {
            var args = DeveloperConsole.SplitArgs(data);

            if (args.Length > 1)
            {
                LogWarning(kUsage);
            }
            if (args.Length == 0)
            {
                // No arguments provided, list all commands

                // Sort commands alphabetically
                var commands = from command in DeveloperConsole.Commands
                               orderby command.Name
                               select command;

                const int kRichTextMargin    = 23;              // Add characters for the additional <color=#xxxxxx></color> rich text tags
                var       commandColumnWidth = commands.Select(command => command.Name).Max(name => name.Length) + kIndent;

                // Compile string of all commands and descriptions
                StringBuilder sb = new StringBuilder();

                string essentialRowFormat = $"{{0,{-commandColumnWidth - kRichTextMargin}}}{{1}}";
                string rowFormat          = $"{{0,{-commandColumnWidth}}}{{1}}";

                foreach (var command in commands)
                {
                    string commandName = command.Name;

                    // Show commands in a special color if they are essential
                    if (command.Essential)
                    {
                        commandName = $"<color=#{kEssentialColor}>{commandName}</color>";
                    }

                    if (string.IsNullOrWhiteSpace(command.Description))
                    {
                        sb.AppendLine(command.Name);                                                                     // No description, so don't print it
                    }
                    else
                    {
                        // There is a description. Split it into lines and then print it out with the proper column indentation
                        var lines = Regex.Split(command.Description, "\r\n|\r|\n");
                        sb.AppendLine(string.Format(command.Essential ? essentialRowFormat : rowFormat, commandName, lines[0]));
                        for (int i = 1; i < lines.Length; i++)
                        {
                            sb.AppendLine(string.Format(rowFormat, string.Empty, lines[i]));
                        }
                    }
                }
                DeveloperConsole.Log(sb.ToString());
            }
            else if (args.Length == 1)
            {
                var cmdName  = args[0].Trim().ToLower();
                var commands = DeveloperConsole.Console.mCommands;

                foreach (var pair in commands)
                {
                    if (pair.Key.Equals(cmdName))
                    {
                        var description = pair.Value.Description;
                        var help        = pair.Value.Command.Help;

                        if (string.IsNullOrWhiteSpace(description))
                        {
                            if (string.IsNullOrWhiteSpace(help))
                            {
                                // No description or help text was provided with this command. Notify the user.
                                DeveloperConsole.Log($"No help information provided for <b>{pair.Key}</b>");
                            }
                            else
                            {
                                // Help was provided, but no description
                                // Just print help text
                                DeveloperConsole.Log(help);
                            }
                        }
                        else
                        {
                            if (string.IsNullOrWhiteSpace(help))
                            {
                                // A description was provided, but no help.
                                // Just print description
                                DeveloperConsole.Log($"<b>{pair.Key}:</b> {description}");
                            }
                            else
                            {
                                // Both a description and help text were provided.
                                // Print both with a paragraph break between
                                DeveloperConsole.Log($"<b>{pair.Key}:</b> {description}\n\n{help}");
                            }
                        }

                        return;
                    }
                }

                // No command found
                LogWarning($"'{cmdName}' is not a command");
            }
        }
コード例 #6
0
 /// <summary>
 /// A command that is called when this verb command is run without specifying a verb. By default, shows help text.
 /// </summary>
 protected virtual void Invoke() => DeveloperConsole.Log(Help);