public CommandFeedback Execute(string[] args) { if (args.Length < 2) { return(CommandFeedback.WrongNumberOfArguments); } ConsoleCommand command = tasks[args[1]]; string[] newArgs = new string[args.Length - 1]; Array.Copy(args, 1, newArgs, 0, newArgs.Length); return(command.Execute(newArgs)); }
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); }
public void RegisterTask(string name, ConsoleCommand del) { tasks.Add(name, del); }