コード例 #1
0
        internal string AutoComplete(string str, string cmd = "")
        {
            List <string> autoList = new List <string>();

            if (cmd.Equals(string.Empty))
            {
                autoList.AddRange(handlerCommands);
                var scriptCommands = ScriptCompiler.GetCommands();
                if (scriptCommands != null)
                {
                    autoList.AddRange(scriptCommands);
                }
            }
            else
            {
                switch (cmd)
                {
                case "load-script":
                    var e = Directory.EnumerateFiles("scripts", str + "*.cs", SearchOption.AllDirectories).GetEnumerator();
                    while (e.MoveNext())
                    {
                        autoList.Add(e.Current.Substring(8));
                    }
                    e = Directory.EnumerateFiles("scripts", str + "*.dll", SearchOption.AllDirectories).GetEnumerator();
                    while (e.MoveNext())
                    {
                        autoList.Add(e.Current.Substring(8));
                    }
                    break;
                }
            }

            int num = 0;

            foreach (var command in autoList)
            {
                if (command.StartsWith(str))
                {
                    num++;
                }
            }
            if (num == 0)
            {
                return(str);
            }
            if (num == 1)
            {
                return(autoList.Find(item => item.StartsWith(str)) + " ");
            }
            else
            {
                var i = WriteLine("Available: ");
                foreach (var command in autoList)
                {
                    if (command.StartsWith(str))
                    {
                        if (num > 1)
                        {
                            Write(i, command + " ");
                        }
                    }
                }
            }
            return(str);
        }