Beispiel #1
0
        private void Awake()
        {
            _console = new CommandLineConsole(OutputMessage);
            if (InputField == null)
            {
                throw new NullReferenceException("InputField cannot be null.");
            }
            if (OutputText == null)
            {
                throw new NullReferenceException("OutputText cannot be null.");
            }
            if (Scrollbar == null)
            {
                throw new NullReferenceException("Scrollbar cannot be null.");
            }
            if (ScrollRect == null)
            {
                throw new NullReferenceException("ScrollRect cannot be null.");
            }

            // Register non-exist command
            _console.RegisterCommand(CommandLineConsole.CommandNotExist, NonExistCommand.Invoke);

            // Register normal command
            foreach (var command in Commands)
            {
                _console.RegisterCommand(command.Name, command.Command.Invoke);
            }

            InputField.onEndEdit.AddListener(OnSumbit);
            // Add Auto complete.
            // If you want more auto complete option duplicate the Button under Auto Complete.
            if (!AutoComplete)
            {
                return;
            }
            InputField.onValueChanged.AddListener(HandleAutoComplete);
            _autoCompleteOptions = AutoComplete.GetComponentsInChildren <Button>(true);

            foreach (var option in _autoCompleteOptions)
            {
                var currentOption = option;
                option.onClick.AddListener(() =>
                {
                    var text        = currentOption.GetComponentInChildren <Text>(true).text;
                    InputField.text = text;
                    AutoComplete.SetActive(false);
                });
            }
        }
Beispiel #2
0
        private static OptionAction AddHelp() => new OptionAction()
        {
            Option       = new Option(new[] { "--help", "-h" }, "Print this help statement."),
            Stage        = OptionAction.StageEnum.CommandBuilder,
            HandleOption = (opt, cmd, ctx, cfg) =>
            {
                var console     = new CommandLineConsole();
                var helpBuilder = new HelpBuilder(console);
                helpBuilder.Write(cmd.RootCommand);

                var helpStr = $"Bifrost Compiler ({Core.AssemblyInfo.Version}) - Parse and extract hooks from C/C++ files.\n\n";
                helpStr += $"Usage:\n  {Core.AssemblyInfo.Name}.exe [options] <inputs>\n\n";

                var optionString = console.ToString();
                helpStr += optionString.ToString().Substring(optionString.IndexOf("Options:"));
                helpStr  = helpStr.Replace("_inputs_", "<inputs>");

                helpStr += $"Example:\n  {Core.AssemblyInfo.Name}.exe input.yaml -o C:/foo/bar";

                Console.WriteLine(helpStr);
                cmd.Stop = true;
            }
        };