Пример #1
0
 void CSI.IConsole.ReadLineAsync(CSI.Interpreter.InputHandler callback)
 {
     CSI.Interpreter.InputHandler inputHandler = this.inputHandler;
     this.inputHandler = callback;  // Register new callback
     if (inputHandler != null)
     {
         inputHandler(null);  // Cancel previous handler
     }
 }
Пример #2
0
    /// <summary>
    /// Called when the input text need to be executed (e.g., when Enter is pressed).
    /// </summary>
    private void OnExecuteInput()
    {
        string inputText = this.inputText.Trim();
        this.inputText = string.Empty;
        if (inputText == string.Empty)
        {
            // Repeat the previous command, if any
            for (int index = this.inputTextHistory.Count - 1; index >= 0; index--)
            {
                if (!string.IsNullOrEmpty(this.inputTextHistory[index]))
                {
                    this.ExecuteCode(this.inputTextHistory[index]);
                    this.outputScrollPosition.y = Mathf.Infinity;
                    break;
                }
            }

            return;
        }

        // Move the text from the input to output console
        CSI.Interpreter.Console.Write(
            this.promptText + "  " + inputText + Environment.NewLine);
        this.inputScrollPosition = Vector2.zero;
        this.outputScrollPosition.y = Mathf.Infinity;

        // Update the input history
        this.inputTextCache.Clear();
        if ((this.inputTextHistory.Count > 0) ||
            (this.inputTextHistory[this.inputTextHistory.Count - 1] == string.Empty))
        {
            this.inputTextHistory[this.inputTextHistory.Count - 1] = inputText;
        }
        else
        {
            this.inputTextHistory.Add(inputText);
        }

        if (this.inputTextHistory.Count > this.maxHistorySize)
        {
            this.inputTextHistory.RemoveRange(
                0, (this.inputTextHistory.Count - this.maxHistorySize));
        }
        else if ((this.inputTextHistory.Count > 0) &&
            (this.inputTextHistory[0] == string.Empty))
        {
            this.inputTextHistory.RemoveAt(0);
        }

        this.currentHistoryIndex = this.inputTextHistory.Count;

        // Notify the async-handler of the keyboard input
        CSI.Interpreter.InputHandler inputHandler = this.inputHandler;
        this.inputHandler = null;
        inputHandler(inputText);
    }