Esempio n. 1
0
 private static void PrintWelcomeMessage()
 {
     Console.WriteLine(AnsiUtils.Color(@"  _____  ____    ___  _______  __ ", 202));
     Console.WriteLine(AnsiUtils.Color(@" / ___/_/ / /_  / _ \/ __/ _ \/ / ", 167));
     Console.WriteLine(AnsiUtils.Color(@"/ /__/_  . __/ / , _/ _// ___/ /__", 132));
     Console.WriteLine(AnsiUtils.Color(@"\___/_    __/ /_/|_/___/_/  /____/", 97));
     Console.WriteLine(AnsiUtils.Color(@"     /_/_/", 62) + AnsiUtils.Color(@"    read-eval-print-loop", 240));
     Console.WriteLine("\nType /help for help\n");
 }
Esempio n. 2
0
 private static void PrintCommands(IEnumerable <KeyValuePair <string, Tuple <string, Action> > > commands)
 {
     if (commands.Any())
     {
         Console.WriteLine();
         foreach (var cmd in commands.OrderBy(c => c.Key))
         {
             Console.WriteLine(AnsiUtils.Color($"/{cmd.Key} -- {cmd.Value.Item1}", AnsiColor.Gray));
         }
         Console.WriteLine();
     }
 }
Esempio n. 3
0
            public string[] GetSuggestions(string text, int index)
            {
                string[] autocomplete = null;

                if (!string.IsNullOrWhiteSpace(text))
                {
                    Console.WriteLine();

                    if (text.StartsWith("/"))
                    {
                        string partialCommand = text.Substring(1);
                        var    matches        = Commands.Where(c => c.Key.StartsWith(partialCommand));
                        if (matches.Any())
                        {
                            PrintCommands(matches);
                            string longestCommonPrefix = Utils.GetLongestCommonPrefix(matches.Select(kv => kv.Key));
                            autocomplete = new [] { longestCommonPrefix.Substring(partialCommand.Length) };
                        }
                    }

                    if (autocomplete == null)
                    {
                        var options = scripting.CodeComplete(text);
                        autocomplete = new [] { options.Item2 };
                        if (options.Item1.Any())
                        {
                            Console.WriteLine();
                            foreach (string option in options.Item1)
                            {
                                Console.WriteLine(AnsiUtils.Color(option, AnsiColor.Gray));
                            }
                            Console.WriteLine();
                        }
                    }

                    Console.Write(Prompt + text);
                }

                return(autocomplete);
            }
Esempio n. 4
0
        static void Main(string[] args)
        {
            // Command window on Windows has ANSI disabled by default
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                ConsoleUtils.EnableANSI();
            }

            PrintWelcomeMessage();

            ReadLine.AutoCompletionHandler = new AutoCompletionHandler();

            while (true)
            {
                string command = ReadLine.Read(Prompt);
                if (command.StartsWith("/") && Commands.TryGetValue(command.Substring(1), out var cmd))
                {
                    cmd.Item2();
                }
                else
                {
                    ReadLine.AddHistory(command);
                    var result = scripting.Eval(command);
                    if (result.Result != null)
                    {
                        Console.WriteLine();
                        if (result.Status == ScriptingExecutionStatus.Error)
                        {
                            Console.WriteLine(AnsiUtils.Color(result.Result, AnsiColor.Red));
                        }
                        else
                        {
                            Console.WriteLine(AnsiUtils.Color(result.Result, AnsiColor.Green));
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
Esempio n. 5
0
 private static void PrintHelp()
 {
     PrintCommands(Commands);
     Console.WriteLine(AnsiUtils.Color("Use Tab for code completion, and up-arrow to access previous commands", AnsiColor.Gray));
 }