Esempio n. 1
0
        public string ReadLine()
        {
            Console.SetCursorPosition(1, Console.WindowHeight - 3);
            Console.Write("> ");

            string line = "";

            string         word = "";
            ConsoleCommand cmd  = null;

            for (; ;)
            {
                ConsoleKeyInfo consoleKeyInfo = Console.ReadKey();
                ConsoleKey     consoleKey     = consoleKeyInfo.Key;
                char           character      = consoleKeyInfo.KeyChar;

                if (consoleKey == ConsoleKey.Enter)
                {
                    break;
                }
                else if (consoleKey == ConsoleKey.Spacebar)
                {
                    // new word, check if last word is a command
                    if (cmd == null)
                    {
                        cmd = this.GetCommand(word);
                    }
                    else
                    {
                        // check if subtasks exist
                        cmd = cmd.SubTasks?.GetCommand(word);
                    }

                    if (cmd != null)
                    {
                        // change colors
                        Console.SetCursorPosition(Console.CursorLeft - word.Length - 1, Console.CursorTop);
                        ConsoleU.Write(word + character, cmd.CommandColor);
                    }

                    word = "";
                }
                else if (consoleKey == ConsoleKey.Backspace)
                {
                    return(ReadLine());

                    //Console.Write(" ");
                    //Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);

                    //line = line.Substring(line.Length - 1, 1);
                    //word = word.Substring(line.Length - 1, 1);
                }

                line += character;

                if (consoleKey != ConsoleKey.Spacebar)
                {
                    word += character;
                }
            }

            Console.WriteLine();
            return(line);
        }