public string ReadLine() { if (_defaultInputs.Any()) { var defaultInput = _defaultInputs.First(); _defaultInputs.RemoveFirst(); return(this.WriteLine(defaultInput, Options.PromptColor)); } var input = string.Empty; var promptOptions = new ConsoleWriteOptions { Foreground = Options.PromptColor }; WriteAction(_promptOptions, () => input = Console.ReadLine()); return(input); }
public void Initialise(ConsoleOptions options) { Options = options ?? throw new ArgumentNullException(nameof(options)); if (!string.IsNullOrWhiteSpace(options.Title)) { Console.Title = options.Title; } Dimensions = new Size { Height = Console.WindowHeight, Width = Console.WindowWidth, }; _promptOptions = new ConsoleWriteOptions { Foreground = options.PromptColor }; }
private void WriteAction(ConsoleWriteOptions writeOptions, Action action) { if (writeOptions != null) { if (writeOptions.Foreground != null) { Console.ForegroundColor = writeOptions.Foreground.Value; } if (writeOptions.Background != null) { Console.BackgroundColor = writeOptions.Background.Value; } action(); Console.ResetColor(); } else { action(); } }
public T WriteLine <T>(T value, ConsoleWriteOptions writeOptions) { WriteAction(writeOptions, () => Console.WriteLine(value)); return(value); }