예제 #1
0
        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);
        }
예제 #2
0
        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
            };
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
 public T WriteLine <T>(T value, ConsoleWriteOptions writeOptions)
 {
     WriteAction(writeOptions, () => Console.WriteLine(value));
     return(value);
 }