/// <summary>Gets the user interaction result.</summary> /// <param name="runtimeStory"></param> /// <param name="parsedFiction"></param> /// <param name="options">The options.</param> /// <returns></returns> public virtual UserInteractionResult GetUserInteractionResult(Runtime.IStory runtimeStory, Parsed.IFiction parsedFiction, ConsoleUserInterfaceOptions options) { var uiResult = new UserInteractionResult(); OutputManager.RequestInput(options); var userInput = OutputManager.GetUserInput(); // If we have null user input, it means that we're // "at the end of the stream", or in other words, the input // stream has closed, so there's nothing more we can do. // We return immediately, since otherwise we get into a busy // loop waiting for user input. if (userInput == null) { OutputManager.ShowStreamError(options); uiResult.IsInputStreamClosed = true; } else { var result = Interpreter.InterpretCommandLineInput(userInput, parsedFiction, runtimeStory); if (result == null) { return(null); } ProcessCommandLineInputResult(uiResult, result, runtimeStory); if (uiResult.Output != null) { OutputManager.ShowOutputResult(result, options); } if (!uiResult.IsValidChoice) { // The choice is only valid if it's a valid index. OutputManager.ShowChoiceOutOffRange(options); } } return(uiResult); }