示例#1
0
        public static string Read(string prompt = "", string defaultInput = "")
        {
            Console.Write(prompt);

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

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

            Console.WriteLine();

            string text = _keyHandler.Text;

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

            return(text);
        }
示例#2
0
        private static string GetText(KeyHandler keyHandler)
        {
            ConsoleKeyInfo keyInfo = Console.ReadKey(true);

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

            Console.WriteLine();
            return(keyHandler.Text);
        }
示例#3
0
        private static string GetText(KeyHandler keyHandler, CancellationToken cancellationToken)
        {
            ConsoleKeyInfo keyInfo = ReadKeyInternal(cancellationToken);

            while (keyInfo.Key != ConsoleKey.Enter)
            {
                keyHandler.Handle(keyInfo);
                keyInfo = ReadKeyInternal(cancellationToken);
            }

            Console.WriteLine();
            return(keyHandler.Text);
        }
示例#4
0
        private static async Task <string> GetTextAsync(KeyHandler keyHandler)
        {
            var keyInfo = Console.ReadKey(true);

            while (keyInfo.Key != ConsoleKey.Enter)
            {
                await keyHandler.Handle(keyInfo).ConfigureAwait(false);

                keyInfo = Console.ReadKey(true);
            }

            Console.WriteLine();
            return(keyHandler.Text);
        }
示例#5
0
        private static string GetText(KeyHandler keyHandler)
        {
            ConsoleKeyInfo keyInfo = Console.ReadKey(true);

            while (keyInfo.Key != ConsoleKey.Enter)
            {
                Console.Title = $"W: {Console.BufferWidth} H: {Console.BufferHeight}";

                keyHandler.Handle(keyInfo);
                keyInfo = Console.ReadKey(true);
            }

            Console.WriteLine();
            return(keyHandler.Text);
        }
示例#6
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);
        }