Example #1
0
        private static void Run()
        {
            while (true)
            {
                string userInput;
                do
                {
                    CFormat.JumpLine();
                    userInput = CInput.ReadFromConsole("", ConsoleInputType.String, false, -1, char.MinValue).ToString();
                }while (string.IsNullOrWhiteSpace(userInput));

                Execute(userInput);
            }
        }
Example #2
0
        public static int UserPickInt(int maxNumber)
        {
            object obj = CInput.ReadFromConsole("Enter a number between 0 and " + maxNumber + ": ", ConsoleInputType.Int, true, maxNumber.ToString().Length, char.MinValue);

            if (obj == null)
            {
                CFormat.WriteLine("[Canceled]", ConsoleColor.DarkYellow);
                return(-1);
            }
            if ((int)obj >= 0 && (int)obj <= maxNumber)
            {
                return((int)obj);
            }
            CInput.UserPickInt(maxNumber);
            return(-1);
        }
Example #3
0
        public static ConsoleAnswer UserChoice(ConsoleAnswerType type, bool canEscape = false)
        {
            switch (type)
            {
            case ConsoleAnswerType.YesNo:
                object object1 = CInput.ReadFromConsole("(YES / NO): ", ConsoleInputType.String, canEscape, 3, char.MinValue);
                if (object1 == null)
                {
                    CFormat.WriteLine("[Canceled]", ConsoleColor.DarkYellow);
                    return(ConsoleAnswer.Escaped);
                }
                string str1 = object1.ToString().ToLower();
                if (str1 == "y" || str1 == "yes")
                {
                    return(ConsoleAnswer.Yes);
                }
                if (str1 == "n" || str1 == "no")
                {
                    return(ConsoleAnswer.No);
                }
                return(CInput.UserChoice(type));


            case ConsoleAnswerType.YesNoCancel:
                object object2 = CInput.ReadFromConsole("(YES / NO / CANCEL): ", ConsoleInputType.String, canEscape, 6, char.MinValue);
                if (object2 == null)
                {
                    CFormat.WriteLine("[Canceled]", ConsoleColor.DarkYellow);
                    return(ConsoleAnswer.Escaped);
                }
                string str2 = object2.ToString().ToLower();
                if (str2 == "y" || str2 == "yes")
                {
                    return(ConsoleAnswer.Yes);
                }
                if (str2 == "n" || str2 == "no")
                {
                    return(ConsoleAnswer.No);
                }
                if (str2 == "c" || str2 == "cancel")
                {
                    return(ConsoleAnswer.Cancel);
                }
                return(CInput.UserChoice(type));

            case ConsoleAnswerType.TrueFalse:
                object object3 = CInput.ReadFromConsole("(TRUE / FALSE): ", ConsoleInputType.String, canEscape, 5, char.MinValue);
                if (object3 == null)
                {
                    CFormat.WriteLine("[Canceled]", ConsoleColor.DarkYellow);
                    return(ConsoleAnswer.Escaped);
                }
                string str3 = object3.ToString().ToLower();
                if (str3 == "t" || str3 == "true")
                {
                    return(ConsoleAnswer.Yes);
                }
                if (str3 == "f" || str3 == "false")
                {
                    return(ConsoleAnswer.No);
                }
                return(CInput.UserChoice(type));

            default:
                CFormat.WriteLine("[CInput] ERROR: Could not get user choice, specifed answer type does not exist.", ConsoleColor.Red);
                return(ConsoleAnswer.Undefined);
            }
        }