Exemplo n.º 1
0
 static void Main(string[] args)
 {
     Core.init();
     KeyState.run();
     cli((args.Length > 0 ? "#run " + args[0] : ""), args.Length > 0);
 }
Exemplo n.º 2
0
        static void cli(string startCommand = "", bool hideHeader = false)
        {
            Log.setLoggingLevel(Log.Level.DEBUG);
            if (!hideHeader)
            {
                Log.write("\n" + SQRIPT.asciiLogo + "", ConsoleColor.Green, "\n", "    ");
                Log.info("  available cli commands:");
                Log.info("   - #help");
                Log.info("   - #run <filename>");
                Log.info("   - #clr (clears global context)");
                Log.info("   - #diag (process diagnose)");
                Log.info("   - #dbg (toggle debug mode)");
                Log.debug("\n  use qonfig:('log', '5'); for verbose output\n");
            }

            string content = "";

            GlobalContext.resetInstance();
            do
            {
                reader.file = "stdin";
                content     = "";
                Log.write(" <~ ", ConsoleColor.White, "");
                ConsoleKeyInfo c;
                do
                {
                    string line;
                    if (startCommand != "")
                    {
                        line         = startCommand;
                        startCommand = "";
                    }
                    else
                    {
                        line = Console.ReadLine();
                    }
                    if (line == "" && content == "")
                    {
                        Console.SetCursorPosition(4, Console.CursorTop - 1);
                    }
                    else
                    {
                        content += line;
                        if (!KeyState.keyDown((int)KeyState.Keys.ShiftKey))
                        {
                            break;
                        }
                        content += "\n";
                        Log.write("    ", ConsoleColor.White, "");
                    }
                } while (true);  //c.Key != ConsoleKey.Escape);
                if (content.StartsWith("#run"))
                {
                    content = File.ReadAllText(content.Substring(5) + (content.EndsWith(".sq") ? "" : ".sq"));
                    Log.info("executing:\n" + content);
                }
                else if (content == "#clr")
                {
                    GlobalContext.resetInstance();
                    continue;
                }
                else if (content == "#dbg")
                {
                    Log.setLoggingLevel((int)Log.loggingLevel > 4 ? Log.Level.INFO : Log.Level.VERBOSE);
                    continue;
                }
                else if (content == "#diag")
                {
                    Watcher.diagnose();
                    Log.info(Watcher.getDiagString(), ConsoleColor.Cyan);
                }
                else if (content == "#help")
                {
                    Log.debug("~ HELP ~\n");
                    Log.debug("~ Keywords:");
                    foreach (var keyword in Keywords.get())
                    {
                        Log.debug("  > " + keyword.name + ":\n    aliases:");
                        foreach (var alias in keyword.aliases)
                        {
                            Log.debug("    - " + alias);
                        }
                        Log.debug(" ----- ");
                    }
                    Log.debug("\n~ Tip: type 'global' to print out the global context");
                }
                else if (content == "#exit")
                {
                    break;
                }
                StackTrace st = new StackTrace();
                execute(content);
                if (Log.loggingLevel == Log.Level.VERBOSE)
                {
                    List <string> stf = new List <string>();
                    for (int i = 0; i < st.FrameCount; i++)
                    {
                        var f = st.GetFrame(i);
                    }
                }
            } while (content != "exit");
        }