Ejemplo n.º 1
0
        /// <summary>
        /// Called when auto complete is running. That's fired by LineEditor.
        /// </summary>
        /// <param name="line">The line.</param>
        /// <param name="position">The position.</param>
        /// <returns></returns>
        private Completion OnAutoComplete(String line, int position)
        {
            var completion = new Completion(String.Empty, new string[0]);
            // Searching command nodes by draft line.
            var nodes = CurrentSession.CommandNode.Search(line);

            if (nodes.Count != 0)
            {
                var content = new List <String>();
                if (nodes.Count == 1)
                {
                    String postfix = nodes.First().FullName.Replace(line.Trim(), String.Empty);
                    // we try to autocomplete current typed command.
                    if (!String.IsNullOrEmpty(postfix))
                    {
                        completion = new Completion(String.Empty, new[] { postfix });
                    }
                    else
                    {
                        // Our command already ok, now we have to show another commands for user.
                        var node = nodes.First();
                        // We found command with nodes, it mean we can have another params for command or
                        // sub commands to run.
                        if (node.Nodes.Count != 0)
                        {
                            nodes.ForEach(p => content.AddRange(p.Keys));
                            completion = new Completion(String.Empty, content.ToArray());
                        }
                        else
                        {
                            // Now we have to show params for the current command.
                            var ps = node.Command.Params;
                            if (ps != null)
                            {
                                // Show parameters help.
                                var    parameters = new List <Param>(ps);
                                String paramsHelp = String.Empty;
                                parameters.ForEach(p => paramsHelp += p.Name + "-" + p.Help + "\n");
                                Console.WriteLine();
                                Console.WriteLine(paramsHelp.Trim());
                                LineEditor.Render();
                            }
                        }
                    }
                }
                else
                {
                    // If we found multiple results we have to show it and that's nothing to do.
                    nodes.ForEach(p => content.Add(p.Name));
                    completion = new Completion(String.Empty, content.ToArray());
                }
            }
            return(completion);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Called when auto complete is running. That's fired by LineEditor.
 /// </summary>
 /// <param name="line">The line.</param>
 /// <param name="position">The position.</param>
 /// <returns></returns>
 private Completion OnAutoComplete(String line, int position)
 {
     var completion = new Completion(String.Empty, new string[0]);
     // Searching command nodes by draft line.
     var nodes = CurrentSession.CommandNode.Search(line);
     if (nodes.Count != 0)
     {
         var content = new List<String>();
         if (nodes.Count == 1)
         {
             String postfix = nodes.First().FullName.Replace(line.Trim(), String.Empty);
             // we try to autocomplete current typed command.
             if (!String.IsNullOrEmpty(postfix))
             {
                 completion = new Completion(String.Empty, new[] {postfix});
             }
             else
             {
                 // Our command already ok, now we have to show another commands for user.
                 var node = nodes.First();
                 // We found command with nodes, it mean we can have another params for command or
                 // sub commands to run.
                 if (node.Nodes.Count != 0)
                 {
                     nodes.ForEach(p => content.AddRange(p.Keys));
                     completion = new Completion(String.Empty, content.ToArray());
                 }
                 else
                 {
                     // Now we have to show params for the current command.
                     var ps = node.Command.Params;
                     if (ps != null)
                     {
                         // Show parameters help.
                         var parameters = new List<Param>(ps);
                         String paramsHelp = String.Empty;
                         parameters.ForEach(p => paramsHelp += p.Name + "-" + p.Help + "\n");
                         Console.WriteLine();
                         Console.WriteLine(paramsHelp.Trim());
                         LineEditor.Render();
                     }
                 }
             }
         }
         else
         {
             // If we found multiple results we have to show it and that's nothing to do.
             nodes.ForEach(p => content.Add(p.Name));
             completion = new Completion(String.Empty, content.ToArray());
         }
     }
     return completion;
 }