public TResult Prompt() { _displayQuestion.Render(); var value = _input.WaitForInput().InterruptKey.Value; _onKey.OnKey(value); if (_onKey.IsInterrupted) { return(default(TResult)); } if (value == ConsoleKey.Enter && _defaultValueComponent.HasDefault) { var defaultValueValidation = _validationResultComponent.Run(_defaultValueComponent.Value); if (defaultValueValidation.HasError) { _errorComponent.Render(defaultValueValidation.ErrorMessage); return(Prompt()); } if (_confirmComponent.Confirm(_defaultValueComponent.Value)) { return(Prompt()); } return(_defaultValueComponent.Value); } var validationResult = _validationValueComponent.Run(value); if (validationResult.HasError) { _errorComponent.Render(validationResult.ErrorMessage); return(Prompt()); } TResult answer = _parseComponent.Parse(value); validationResult = _validationResultComponent.Run(answer); if (validationResult.HasError) { _errorComponent.Render(validationResult.ErrorMessage); return(Prompt()); } if (_confirmComponent.Confirm(answer)) { return(Prompt()); } return(answer); }
public TResult Prompt() { _displayQuestion.Render(); var value = Reader.WaitForInput(); _onKey.OnKey(value.InterruptKey); if (_onKey.IsInterrupted) { return(default(TResult)); } if (string.IsNullOrWhiteSpace(value.Value) && _defaultValueComponent.HasDefault) { if (_confirmComponent.Confirm(_defaultValueComponent.Value)) { return(Prompt()); } var defaultValueValidation = _validationResultComponent.Run(_defaultValueComponent.Value); if (defaultValueValidation.HasError) { _errorComponent.Render(defaultValueValidation.ErrorMessage); return(Prompt()); } return(_defaultValueComponent.Value); } var validationResult = _validationValueComponent.Run(value.Value); if (validationResult.HasError) { _errorComponent.Render(validationResult.ErrorMessage); return(Prompt()); } TResult answer = _parseComponent.Parse(value.Value); validationResult = _validationResultComponent.Run(answer); if (validationResult.HasError) { _errorComponent.Render(validationResult.ErrorMessage); return(Prompt()); } if (_confirmComponent.Confirm(answer)) { return(Prompt()); } return(answer); }
public TResult Prompt() { _displayQuestion.Render(); if (_choices.Count == 0) { _errorComponent.Render("No choices"); var keyPressed = _inputComponent.WaitForInput().InterruptKey; _onKey.OnKey(keyPressed); return(default(TResult)); } _renderChoices.Render(); _console.WriteLine(); _console.Write("Answer: "); var value = _inputComponent.WaitForInput(); _onKey.OnKey(value.InterruptKey); if (_onKey.IsInterrupted) { return(default(TResult)); } var validationResult = _validationInputComponent.Run(value.Value); if (validationResult.HasError) { _errorComponent.Render(validationResult.ErrorMessage); return(Prompt()); } TResult result = _parseComponent.Parse(value.Value); validationResult = _validationResultComponent.Run(result); if (validationResult.HasError) { _errorComponent.Render(validationResult.ErrorMessage); return(Prompt()); } if (_confirmComponent.Confirm(result)) { return(Prompt()); } return(result); }
public TResult Prompt() { _displayQuestion.Render(); if (_pagingComponent.PagedChoices.Count == 0) { _errorComponent.Render("No choices"); var keyPressed = _input.WaitForInput().InterruptKey; _onKey.OnKey(keyPressed); return(default(TResult)); } _renderChoices.Render(); if (_cursorPosition < 0) { _cursorPosition = Consts.CURSOR_OFFSET; } _renderChoices.Select(_cursorPosition - Consts.CURSOR_OFFSET); int boundryTop = Consts.CURSOR_OFFSET; int boundryBottom = boundryTop + _pagingComponent.CurrentPage.Count() - 1; while (true) { var keyPressed = _input.WaitForInput().InterruptKey; _onKey.OnKey(keyPressed); if (_onKey.IsInterrupted) { return(default(TResult)); } switch (keyPressed) { case (ConsoleKey.LeftArrow): { _pagingComponent.Previous(); return(Prompt()); } case (ConsoleKey.RightArrow): { _pagingComponent.Next(); return(Prompt()); } case ConsoleKey.UpArrow: { if (_cursorPosition > boundryTop) { _cursorPosition -= 1; } else { if (_pagingComponent.Previous()) { _cursorPosition = _pagingComponent.CurrentPage.Count - 1 + Consts.CURSOR_OFFSET; return(Prompt()); } } break; } case ConsoleKey.DownArrow: { if (_cursorPosition < boundryBottom) { _cursorPosition += 1; } else { if (_pagingComponent.Next()) { _cursorPosition = Consts.CURSOR_OFFSET; return(Prompt()); } } break; } case ConsoleKey.Enter: { goto Escape; } } _renderChoices.Render(); _renderChoices.Select(_cursorPosition - Consts.CURSOR_OFFSET); } Escape: TResult result = _parseComponent.Parse(_cursorPosition - Consts.CURSOR_OFFSET); var validationResult = _validationComponent.Run(result); if (validationResult.HasError) { _errorComponent.Render(validationResult.ErrorMessage); return(Prompt()); } if (_confirmComponent.Confirm(result)) { return(Prompt()); } return(result); }
public TResult Prompt() { _displayQuestion.Render(); if (_choices.Count == 0) { _errorComponent.Render("No choices"); var keyPressed = _input.WaitForInput().InterruptKey; _onKey.OnKey(keyPressed); return default(TResult); } _renderChoices.Render(); var value = _input.WaitForInput().InterruptKey.Value; _onKey.OnKey(value); if (_onKey.IsInterrupted) { return default(TResult); } if (value == ConsoleKey.Enter && _defaultValueComponent.HasDefault) { if (_confirmComponent.Confirm(_defaultValueComponent.Value)) { return Prompt(); } var defaultValueValidation = _validationResultComponent.Run(_defaultValueComponent.Value); if (defaultValueValidation.HasError) { _errorComponent.Render(defaultValueValidation.ErrorMessage); return Prompt(); } return _defaultValueComponent.Value; } var validationResult = _validationInputComponent.Run(value); if (validationResult.HasError) { _errorComponent.Render(validationResult.ErrorMessage); return Prompt(); } TResult result = _parseComponent.Parse(value); validationResult = _validationResultComponent.Run(result); if (validationResult.HasError) { _errorComponent.Render(validationResult.ErrorMessage); return Prompt(); } if (_confirmComponent.Confirm(result)) { return Prompt(); } return result; }
public TList Prompt() { _displayQuestionComponent.Render(); if (_choices.Count == 0) { _errorComponent.Render("No choices"); var keyPressed = _input.WaitForInput().InterruptKey; _onKey.OnKey(keyPressed); return(default(TList)); } _renderchoices.Render(); _renderchoices.Select(0); int boundryTop = Consts.CURSOR_OFFSET; int boundryBottom = boundryTop + _choices.Count - 1; int cursorPosition = Consts.CURSOR_OFFSET; while (true) { var keyPressed = _input.WaitForInput().InterruptKey; _onKey.OnKey(keyPressed); if (_onKey.IsInterrupted) { return(default(TList)); } switch (keyPressed) { case ConsoleKey.Spacebar: { _choices[cursorPosition - Consts.CURSOR_OFFSET].IsSelected ^= true; _renderchoices.Select(cursorPosition - Consts.CURSOR_OFFSET); break; } case ConsoleKey.UpArrow: { if (cursorPosition > boundryTop) { _renderchoices.UnSelect(cursorPosition - Consts.CURSOR_OFFSET); cursorPosition -= 1; } _renderchoices.Select(cursorPosition - Consts.CURSOR_OFFSET); break; } case ConsoleKey.DownArrow: { if (cursorPosition < boundryBottom) { _renderchoices.UnSelect(cursorPosition - Consts.CURSOR_OFFSET); cursorPosition += 1; } _renderchoices.Select(cursorPosition - Consts.CURSOR_OFFSET); break; } case ConsoleKey.Enter: { goto Escape; } } } Escape: TList result = _parseComponent.Parse(_choices); var validationResult = _validationComponent.Run(result); if (validationResult.HasError) { _errorComponent.Render(validationResult.ErrorMessage); return(Prompt()); } if (_confirmComponent.Confirm(result)) { return(Prompt()); } return(result); }