/// <summary> /// Displays the menu, prompts the user for a response, and returns the response. /// </summary> /// <param name="type">The log type of the menu.</param> /// <param name="options">Log options to override default logging behavior.</param> public char Run(LogType type, LogOptions options) { var console = new FluentConsole(); options = options ?? new LogOptions(); options.IsEndOfLine = true; console.LogSeparator(type, options); if (!string.IsNullOrWhiteSpace(_title)) { console.Log($" {_title}", type, options).LogSeparator(type, options); } if (!string.IsNullOrWhiteSpace(_detail)) { console.Log(_detail, type, options).WriteLine(); } foreach (KeyValuePair <char, string> option in _options) { console.Log($" {option.Key} - {option.Value}", type, options); } console.LogSeparator(type, options).WriteLine(); var left = console.CursorLeft; var top = console.CursorTop; options.IsEndOfLine = false; var response = char.MinValue; do { console.SetCursorPosition(left, top).Log("Make your selection: \b", type, options); response = console.ReadKey().KeyChar; } while (!_options.ContainsKey(response)); console.WriteLine(); return(response); }
/// <summary> /// Prompts the user to answer a yes or no question. /// </summary> /// <param name="type">The log type of the message.</param> /// <param name="options">Log options to override default logging behavior.</param> public bool Run(LogType type, LogOptions options) { var console = new FluentConsole(); options = options ?? new LogOptions(); options.IsEndOfLine = false; ConsoleKey response; do { console.Log(_question, type, options); response = console.ReadKey(false).Key; console.WriteLine(); } while (!_allowedResponses.ContainsKey(response)); return(_allowedResponses[response]); }