Beispiel #1
0
        public async Task Run()
        {
            while (_loop.Continue())
            {
                try
                {
                    _console.Write($"{_consoleState.Prompt} ");
                    _consoleState.ColPosition = _console.CursorLeft;
                    _consoleState.RowPosition = _console.CursorTop;

                    var input = _consoleKeyHandler.Process(_consoleState);
                    _console.WriteLine();

                    var result = await _replEngine.Execute(input);

                    switch (result.State)
                    {
                    case OutputState.Continue:
                        _consoleState.Prompt = Prompt.Continue;
                        _consoleState.TextRowPosition++;
                        break;

                    case OutputState.Error:
                        _consoleWriter.WriteError(result.Output ?? "");
                        _consoleState.CompleteInput(result.Variables);
                        break;

                    default:
                        _consoleWriter.WriteOutput(result.Output ?? "");
                        _consoleState.CompleteInput(result.Variables);
                        break;
                    }
                }
                catch (Exception exception)
                {
                    _console.WriteLine();
                    _consoleWriter.WriteError(exception);
                }
            }
        }