示例#1
0
        public async Task <string> ReadLineOnPositionAsync(Func <int> leftIndentResolver, int top)
        {
            var input = string.Empty;

            while (true)
            {
                _consoleAbstraction.SetCursorPosition(leftIndentResolver.Invoke() + input.Length, top);

                var key = await _consoleAbstraction.ReadKeyAsync();

                _consoleAbstraction.ClearLine(leftIndentResolver.Invoke(), top);

                if (key.Key == ConsoleKey.Enter)
                {
                    return(input);
                }

                if (key.Key == ConsoleKey.Backspace)
                {
                    if (input.Length > 0)
                    {
                        input = input.Remove(input.Length - 1);
                    }
                }
                else
                {
                    input += key.KeyChar;
                }

                _consoleAbstraction.WriteOnPosition(input, leftIndentResolver.Invoke(), top);
            }
        }
示例#2
0
 private void DisplayPrompt()
 {
     _consoleAbstraction.WriteOnPosition(Prompt, 0, _height, ConsoleColor.Green);
 }