Axiom.Demos.Browser.CommandLine.ConfigDialog.GetInput C# (CSharp) Method

GetInput() private method

private GetInput ( ) : int
return int
        private int GetInput()
        {
            _numericInput = -1;
            string stringInput = String.Empty;
            int keyCount = 2;

            while ( keyCount > 0 )
            {
                ConsoleKeyInfo key = Console.ReadKey();

                if ( key.Key == ConsoleKey.Escape )
                    return -1;

                if ( key.Key == ConsoleKey.Enter )
                {
                    if ( stringInput.Length > 0 )
                        _numericInput = Int32.Parse(stringInput);

                    return -2;
                }

                if ( key.KeyChar >= '0' && key.KeyChar <= '9' )
                {
                    stringInput += key.KeyChar.ToString();
                    keyCount--;
                }
                else if ( key.Key == ConsoleKey.Backspace )
                {
                    if ( stringInput.Length > 0 )
                    {
                        stringInput = stringInput.Substring(0, stringInput.Length - 1);
                        keyCount++;
                        Console.Write(" \b"); // clear last char
                    }
                    else
                        Console.Write(" "); // back to position
                }
                else
                {
                    Console.Write("\b \b"); // clear invalid char
                }
            }
            _numericInput = Int32.Parse(stringInput);

            return -2; // force ENTER
        }