Exemplo n.º 1
0
        public static void HandleQuery(string query)
        {
            string[] splittedQuery = query.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (splittedQuery.Length == 0)
            {
                return;
            }
            string command = splittedQuery[0].ToLower();

            Command.Command deleg = CommandRegistry.GetCommandByAlias(command);
            if (deleg != null)
            {
#if !DEBUG_COMMANDS
                try
                {
#endif
                deleg.Delegate(query, splittedQuery.Skip(1).ToArray());
#if !DEBUG_COMMANDS
            }
            catch (Exception e)
            {
                CLIOutput.WriteLine("Error - {0}: {1}", ConsoleColor.DarkRed, e.GetType().Name, e.Message);
            }
#endif
            }
            else
            {
                CLIOutput.Write("No such command!", ConsoleColor.DarkRed);

                int    dist = int.MaxValue;
                string min  = null;

                foreach (string alias in CommandRegistry.EnumerateAliases())
                {
                    int dd = StringUtils.EditDistance(command, alias);
                    if (dd < dist)
                    {
                        dist = dd;
                        min  = alias;
                    }
                }

                if (dist <= 3 && min != null)
                {
                    CLIOutput.WriteLine(" Did you mean '{0}'?", ConsoleColor.DarkRed, min);
                }
                else
                {
                    CLIOutput.WriteLine();
                }
            }
        }
Exemplo n.º 2
0
 private static void HandleKey(ConsoleKeyInfo keyInfo)
 {
     if (keyInfo.Key != ConsoleKey.Enter)
     {
         handler.Handle(keyInfo);
     }
     else
     {
         CLIOutput.WriteLine();
         CLI.HandleQuery(handler.Text);
         ReadLine.AddHistory(handler.Text);
         CreateHandler();
     }
 }
Exemplo n.º 3
0
        public static void Welcome()
        {
            CLIOutput.WriteLine("Welcome to {0}", Info.FullName);
            CLIOutput.WriteLine(RandomSplash(), ConsoleColor.Gray);

            CLIOutput.WriteLine(@"Write 'help' to list all supported commands.");
            if (!Info.Autostart)
            {
                CLIOutput.WriteLine("Autostart disabled! You can enable it using 'autostart enable' command, if you want.", ConsoleColor.DarkYellow);
            }
            if (!VoteLoop.Enabled)
            {
                CLIOutput.WriteLine("Autovote disabled! You can enable it using 'autovote enable' command, if you want.", ConsoleColor.DarkYellow);
            }
        }
Exemplo n.º 4
0
 private static void CreateHandler()
 {
     handler = ReadLine.CreateHandler();
     CLIOutput.Write("> ", ConsoleColor.Green);
 }