Exemplo n.º 1
0
        /// <summary>
        /// Invokes the given command.
        /// </summary>
        /// <param name="command">The command to invoke.</param>
        /// <returns>The return value, if any, of the invoked command.</returns>
        public object InvokeCommand(string command)
        {
            object commandResult = null;

            if (!string.IsNullOrWhiteSpace(command))
            {
                string commandLog = $"> {command}";
                if (_theme)
                {
                    commandLog = commandLog.ColorText(_theme.CommandLogColor);
                }
                LogToConsole(commandLog);

                string logTrace = string.Empty;
                try
                {
                    commandResult = QuantumConsoleProcessor.InvokeCommand(command);

                    switch (commandResult)
                    {
                    case Task task: _currentTasks.Add(task); break;

                    case IEnumerator <ICommandAction> action: StartAction(action); break;

                    case IEnumerable <ICommandAction> action: StartAction(action.GetEnumerator()); break;

                    default: logTrace = Serialize(commandResult); break;
                    }
                }
                catch (System.Reflection.TargetInvocationException e) { logTrace = GetInvocationErrorMessage(e.InnerException); }
                catch (Exception e) { logTrace = GetErrorMessage(e); }

                LogToConsole(logTrace);
                OnInvoke?.Invoke(command);

                if (_autoScroll == AutoScrollOptions.OnInvoke)
                {
                    ScrollConsoleToLatest();
                }
                if (_closeOnSubmit)
                {
                    Deactivate();
                }
            }
            else
            {
                OverrideConsoleInput(string.Empty);
            }

            return(commandResult);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Invokes the given command.
        /// </summary>
        /// <param name="command">The command to invoke.</param>
        /// <returns>The return value, if any, of the invoked command.</returns>
        public object InvokeCommand(string command)
        {
            object commandResult = null;

            if (!string.IsNullOrWhiteSpace(command))
            {
                string commandLog = $"> {command}";
                if (_theme)
                {
                    commandLog = commandLog.ColorText(_theme.CommandLogColor);
                }
                LogToConsole(commandLog);

                string logTrace = string.Empty;
                try
                {
                    commandResult = QuantumConsoleProcessor.InvokeCommand(command);

                    if (commandResult is Task task)
                    {
                        _currentTasks.Add(task);
                    }
                    else
                    {
                        logTrace = _serializer.SerializeFormatted(commandResult, _theme);
                    }
                }
                catch (System.Reflection.TargetInvocationException e) { logTrace = GetInvocationErrorMessage(e.InnerException); }
                catch (Exception e) { logTrace = GetErrorMessage(e); }

                LogToConsole(logTrace);
                OnInvoke?.Invoke(command);

                if (_autoScroll == AutoScrollOptions.OnInvoke)
                {
                    ScrollConsoleToLatest();
                }
                if (_closeOnSubmit)
                {
                    Deactivate();
                }
            }
            else
            {
                OverrideConsoleInput(string.Empty);
            }

            return(commandResult);
        }
Exemplo n.º 3
0
        private void Initialize()
        {
            if (!QuantumConsoleProcessor.TableGenerated)
            {
                QuantumConsoleProcessor.GenerateCommandTable(true);
                _consoleInput.interactable = false;
                _isGeneratingTable         = true;
            }

            _consoleLogText.richText        = true;
            _consoleSuggestionText.richText = true;

            ApplyTheme(_theme);
            if (!_keyConfig)
            {
                _keyConfig = ScriptableObject.CreateInstance <QuantumKeyConfig>();
            }
        }
Exemplo n.º 4
0
 private void GetCommandSuggestions()
 {
     _suggestedCommands.Clear();
     _suggestedCommands.AddRange(QuantumConsoleProcessor.GetCommandSuggestions(_currentText, _useFuzzySearch, _caseSensitiveSearch, true));
 }