Example #1
0
        public static string Read(string prompt = "", string @default = "")
        {
            Console.Write(prompt);
            KeyHandler keyHandler = new KeyHandler(new Console2(), _history, AutoCompletionHandler);
            string     text       = GetText(keyHandler);

            if (String.IsNullOrWhiteSpace(text) && !String.IsNullOrWhiteSpace(@default))
            {
                text = @default;
            }
            else if (HistoryEnabled)
            {
                _history.Add(text);
            }

            return(text);
        }
Example #2
0
        public static string Read(string prompt = "")
        {
            Console.Write(prompt);

            _keyHandler = new KeyHandler(new Console2(), _history, AutoCompletionHandler);
            ConsoleKeyInfo keyInfo = Console.ReadKey(true);

            while (keyInfo.Key != ConsoleKey.Enter)
            {
                _keyHandler.Handle(keyInfo);
                keyInfo = Console.ReadKey(true);
            }

            Console.WriteLine();

            _history.Add(_keyHandler.Text);
            return(_keyHandler.Text);
        }
Example #3
0
        public static async Task <string> ReadAsync(string prompt = "", string @default = "")
        {
            Console.Write(prompt);
            var keyHandler = new KeyHandler(new Console2(), _history, AutoCompletionHandler);
            var text       = await GetTextAsync(keyHandler).ConfigureAwait(false);

            if (string.IsNullOrWhiteSpace(text) && !string.IsNullOrWhiteSpace(@default))
            {
                text = @default;
            }
            else
            {
                if (HistoryEnabled)
                {
                    _history.Add(text);
                }
            }

            return(text);
        }
Example #4
0
        public static string Read(CancellationToken?cancellationToken = null, string prompt = "", string @default = "")
        {
            Console.Write(prompt);
            var keyHandler = new KeyHandler(new Console2(), _history, AutoCompletionHandler);
            var text       = cancellationToken.HasValue ?
                             GetText(cancellationToken.Value, keyHandler) : GetText(keyHandler);

            if (String.IsNullOrWhiteSpace(text) && !String.IsNullOrWhiteSpace(@default))
            {
                text = @default;
            }
            else
            {
                if (HistoryEnabled)
                {
                    _history.Add(text);
                }
            }

            return(text);
        }
Example #5
0
        public static string Read(string prompt = "", string @default = "")
        {
            Console.Write(prompt);
            KeyHandler keyHandler = new KeyHandler(new Console2(), _history, AutoCompletionHandler, prompt.Length);
            string     text       = GetText(keyHandler);

            if (String.IsNullOrWhiteSpace(text) && !String.IsNullOrWhiteSpace(@default))
            {
                text = @default;
            }
            else
            {
                if (HistoryEnabled && !string.IsNullOrWhiteSpace(text))
                {
                    if ((_history.Count == 0) || (_history[_history.Count - 1] != text))
                    {
                        _history.Add(text);
                    }
                }
            }
            return(text);
        }