示例#1
0
 private string GetRecommendedInfo(string v)
 {
     if (GetCommandAndArgsFromText(v, out string nameCommand, out string[] args))
     {
         List <AbstractCommand> commands = SearchRecommendations.Search(nameCommand, (t) => t.Name, this.commands);
         if (commands.Count == 0)
         {
             return("not found.");
         }
         else if (commands.Count == 1)
         {
             return(commands[0].Name + " - " + commands[0].Info);
         }
         else
         {
             return(string.Join(", ", commands));
         }
     }
示例#2
0
        private string GetterText()
        {
            StringBuilder  sb = new StringBuilder();
            ConsoleKeyInfo info;
            var            posStart = new { X = Console.CursorLeft, Y = Console.CursorTop };
            StringBuilder  buffer   = null;

            do
            {
                info = Console.ReadKey(true);
                if (ConsoleKey.Backspace == info.Key)
                {
                    if (sb.Length > 0)
                    {
                        sb.Length--;
                    }
                }
                else if (ConsoleKey.Enter == info.Key)
                {
                    break;
                }
                else if (info.Key == ConsoleKey.UpArrow || info.Key == ConsoleKey.DownArrow || info.Key == ConsoleKey.LeftArrow || info.Key == ConsoleKey.RightArrow)
                {
                    sb = new StringBuilder(history.Move(info).Value);
                }
                else
                {
                    sb.Append(info.KeyChar);
                }
                buffer = ShowUserCommandText(sb, posStart, buffer);
            } while (info.Key != ConsoleKey.Enter);
            if (GetCommandAndArgsFromText(sb.ToString(), out string commandName, out string[] args))
            {
                List <AbstractCommand> recommendCommands = SearchRecommendations.Search(commandName, (t) => t.Name, commands);
                if (recommendCommands.Count == 1)
                {
                    return(recommendCommands[0].Name + " " + string.Join(" ", args));
                }
            }
            return(sb.ToString());
        }