SaveHistory() public method

public SaveHistory ( ) : void
return void
Beispiel #1
0
    public int ReadEvalPrintLoop()
    {
        if (startup_files != null && startup_files.Length == 0)
        {
            InitTerminal(startup_files.Length == 0 && Driver.StartupEvalExpression == null);
        }

        InitializeUsing();

        LoadStartupFiles();

        if (startup_files != null && startup_files.Length != 0)
        {
            ExecuteSources(startup_files, false);
        }
        else
        {
            if (Driver.StartupEvalExpression != null)
            {
                ReadEvalPrintLoopWith(p => {
                    var ret = Driver.StartupEvalExpression;
                    Driver.StartupEvalExpression = null;
                    return(ret);
                });
            }
            else
            {
                ReadEvalPrintLoopWith(GetLine);
            }

            editor.SaveHistory();
        }

        Console.CancelKeyPress -= ConsoleInterrupt;

        return(0);
    }
Beispiel #2
0
        public static int Main(string[] args)
        {
            var show_help = false;
            var use_precompiled = true;
            var options = new OptionSet {
                {"p|no-precomp", "do not use precompiled libraries", v => use_precompiled = v == null},
                {"h|help", "show this message and exit", v => show_help = v != null}
            };

            List<string> files;
            try {
                files = options.Parse(args);
            } catch (OptionException e) {
                Console.Error.Write(AppDomain.CurrentDomain.FriendlyName + ": ");
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine("Try “" + AppDomain.CurrentDomain.FriendlyName + " --help” for more information.");
                return 1;
            }

            if (show_help) {
                Console.WriteLine("Usage: " + AppDomain.CurrentDomain.FriendlyName + " input.flbgst");
                Console.WriteLine("Run Flabbergast interactively.");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return 1;
            }

            if (files.Count > 1) {
                Console.Error.WriteLine("No more than one Flabbergast script may be given.");
                return 1;
            }

            Frame original = null;

            var assembly_builder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Repl"), AssemblyBuilderAccess.Run);
            var module_builder = assembly_builder.DefineDynamicModule("ReplModule");
            var unit = new CompilationUnit(module_builder, false);
            var collector = new ConsoleCollector();
            var task_master = new ConsoleTaskMaster();
            task_master.AddUriHandler(BuiltInLibraries.INSTANCE);
            if (use_precompiled) {
                task_master.AddUriHandler(new LoadPrecompiledLibraries());
            }
            task_master.AddUriHandler(new DynamicallyCompiledLibraries(collector));

            if (files.Count == 1) {
                var parser = Parser.Open(files[0]);
                var root_type = parser.ParseFile(collector, unit, "REPLRoot");
                if (root_type != null) {
                    var computation = (Computation) Activator.CreateInstance(root_type, task_master);
                    computation.Notify(r => original = r as Frame);
                    task_master.Slot(computation);
                    task_master.Run();
                    task_master.ReportCircularEvaluation();
                }
            }
            if (original == null) {
                original = new Frame(task_master, task_master.NextId(), new SourceReference("<repl>", "<native>", 0, 0, 0, 0, null), null, null);
            }

            var id = 0;
            Frame current = original;
            bool run = true;
            ConsumeResult update_current = (x) => current = (x as Frame) ?? current;

            var line_editor = new LineEditor("flabbergast");
            var completables = new Completables();
            line_editor.AutoCompleteEvent = completables.Handler;
            string s;

            while (run && (s = line_editor.Edit(id + "‽ ", "")) != null) {
                var parser = new Parser("line" + id, s);
                var run_type = parser.ParseRepl(collector, unit, "REPL" + id++);
                if (run_type != null) {
                    object result = null;
                    var computation = (Computation) Activator.CreateInstance(run_type, new object[] { task_master, original, current, update_current, (ConsumeResult) (output => result = output), (ConsumeResult) Console.WriteLine });
                    computation.Notify(r => run = (r as bool?) ?? true);
                    task_master.Slot(computation);
                    task_master.Run();
                    if (result != null) {
                        HandleResult(result);
                    }
                    task_master.ReportCircularEvaluation();
                }
            }
            line_editor.SaveHistory();
            return 0;
        }
        public void Run()
        {
            var le = new LineEditor(
                Config.ConsoleMode.AppName,
                Config.ConsoleMode.HistorySize.GetValueOrDefault(10))
                     	{
                     		AutoCompleteEvent = (text, pos) => GetEntries(text)
                     	};

            using (CommandsOptions.HideCommandOfType<ConsoleCommand>())
            {
                Writer.WriteLines(
                    "Type ctrl+c to exit.",
                    "Type \"cls\" to clear the console window.",
                    "Type \"> filename\" to redirect output to a file.");

                do
                {
                    string[] args;
                    do
                    {
                        args = le.Edit(Config.ConsoleMode.CommandPromptText +  "> ", string.Empty).SplitCmdLineArgs();
                    } while (args.IsNullOrEmpty());

                    if (args[0].Equals("cls", StringComparison.OrdinalIgnoreCase))
                    {
                        Console.Clear();
                    }
                    else if (args[0].Equals(CommandName, StringComparison.OrdinalIgnoreCase))
                    {
                        //already in console mode
                    }
                    else
                    {
                        le.SaveHistory();
                        RunCommand(args);
                    }

                } while (true);
            }
        }