Esempio n. 1
0
 public override IEnumerable <String> AutocompletionCandidates(IEnumerable <String> arguments)
 {
     if (arguments.Count() != 1)
     {
         return(new List <String>());
     }
     return(Autocompletion.Candidates(arguments.ElementAt(0), Shell.GetCommandNames()));
 }
Esempio n. 2
0
 public override IEnumerable <String> AutocompletionCandidates(IEnumerable <String> arguments)
 {
     if (arguments.Count() != 1)
     {
         return(new List <String>());
     }
     return(Autocompletion.Candidates(arguments.ElementAt(0), Mod.AliveMods.Select(mod => mod.Name)));
 }
Esempio n. 3
0
        /// <summary>
        /// Returns the auto-completion candidates for a given command.
        /// Depending on what is entered, it will either return command verbs
        /// or command-provided auto-completion candidates
        /// </summary>
        /// <param name="command">The current command [verb, arg1, arg2,...]</param>
        /// <returns>The auto-completion candidates for the last argument</returns>
        internal static IEnumerable <String> GetAutocompletionCandidates(IEnumerable <String> command)
        {
            if (!command.Any())
            {
                return(new List <String>());
            }

            String verb = command.ElementAt(0);

            if (command.Count() == 1)
            {
                return(Autocompletion.Candidates(verb, Registry.Keys));
            }

            Command _command;

            if (Registry.TryGetValue(verb, out _command))
            {
                return(_command.AutocompletionCandidates(command.Skip(1)));
            }

            return(new List <String>());
        }
Esempio n. 4
0
        /// <summary>
        /// Attempts to auto-complete the current word
        /// </summary>
        private static void TriggerAutocompletion()
        {
            List <Token> tokens = new List <Token>(LexString(CurrentCmd));

            if (tokens.Last().Type == TokenType.WHITESPACE) // If ends in whitespace, consider the next argument present but empty
            {
                tokens.Add(new Token(TokenType.TEXT, ""));
            }
            List <String> candidates = new List <String>(
                Shell.GetAutocompletionCandidates(
                    ConstructArguments(tokens)));

            bool finish_string = true;

            if (candidates.Count == 0) // No candidate
            {
                return;
            }

            if (candidates.Count == 1) // 1 candidate, auto-complete
            {
                if (tokens.Last().Type != TokenType.WHITESPACE)
                {
                    Token token = tokens.Last();
                    tokens[tokens.Count - 1] = new Token(
                        ContainsSpaces(candidates[0]) ?  TokenType.QUOTE : token.Type,
                        candidates[0]);
                    tokens.Add(new Token(TokenType.WHITESPACE, " "));
                }
            }
            else
            {
                // More than 1 candidates, complete as much as possible and
                // display a list of candidates if necessary

                String common_prefix = Autocompletion.CommonPrefix(candidates);
                if (tokens.Last().Type != TokenType.WHITESPACE)
                {
                    Token token = tokens.Last();
                    tokens[tokens.Count - 1] = new Token(
                        ContainsSpaces(common_prefix) ?  TokenType.QUOTE : token.Type,
                        common_prefix);
                    if (tokens.Last().Type == TokenType.QUOTE)
                    {
                        finish_string = CurrentCmd.Last() == '\"';
                    }
                }

                if (PreviousCmd == CurrentCmd)
                {
                    String list = "";
                    foreach (String candidate in candidates)
                    {
                        list += candidate + "    ";
                    }
                    Log(list);
                }
                PreviousCmd = CurrentCmd;
            }

            String reconstruction = Reconstruct(tokens);

            if (!finish_string)
            {
                CurrentCmd = reconstruction.Remove(reconstruction.Length - 1);
            }
            else
            {
                CurrentCmd = reconstruction;
            }
            EditLocation = CurrentCmd.Length;
        }