/// <summary> /// Executes the REPL (Read-Eval-Print-Loop) until terminated. /// </summary> public static void REPL() { EvalPrint("restart", out var dummy1); CommandLineReader reader = GetCommandLineReader(); while (eval != null) { Console.WriteLine(); string line = reader.ReadCommand("> ", "").Trim(); if (line == null || exitCommands.Contains(line)) { break; } EvalPrint(line, out var dummy2); } }
private static CommandLineReader GetCommandLineReader() { string historyPath = Utils.GetBoSSSUserSettingsPath(); if (!Directory.Exists(historyPath)) { historyPath = null; } CommandLineReader reader = new CommandLineReader( "BoSSSpad", historyPath, 500); int timeout = 1000; // Get completions from the evaluator knows about reader.AutoCompleteEvent += (sender, eventArgs) => { string[] completions; string prefix; bool completed = eval.TryGetCompletions( eventArgs.Text, out completions, out prefix, timeout); if (completed && completions != null) { eventArgs.Completions.Add( new CommandLineReader.CompletionList(prefix, completions)); } }; // Rudimentary handler for completions of InteractiveShell (better // than nothing) reader.AutoCompleteEvent += (sender, eventArgs) => { string text = eventArgs.Text.Trim(); if (text.IndexOf('.') >= 0) { return; } string[] completions; string prefix; bool completed = eval.TryGetCompletions( "InteractiveShell." + text, out completions, out prefix, timeout); if (completed && completions != null) { eventArgs.Completions.Add( new CommandLineReader.CompletionList(prefix, completions)); } }; // Same for InteractiveBase reader.AutoCompleteEvent += (sender, eventArgs) => { string text = eventArgs.Text.Trim(); if (text.IndexOf('.') >= 0) { return; } string[] completions; string prefix; bool completed = eval.TryGetCompletions( "InteractiveBase." + text, out completions, out prefix, timeout); if (completed && completions != null) { eventArgs.Completions.Add( new CommandLineReader.CompletionList(prefix, completions)); } }; // Standard exit (e.g., user typed quit on the console) AppDomain.CurrentDomain.ProcessExit += delegate(object sender, EventArgs e) { reader.SaveHistory(); }; return(reader); }