/// <summary> /// Run on the statement execution thread. /// </summary> void ExecuteStatements(string scriptText) { UpdateVariables?.Invoke(commandLine.ScriptScope); lock (scriptText) { textEditor.Write("\r\n"); ScriptSource scriptSource = commandLine.ScriptScope.Engine.CreateScriptSourceFromString(scriptText, SourceCodeKind.Statements); string error = ""; try { Executing = true; scriptSource.Execute(commandLine.ScriptScope); } catch (ThreadAbortException tae) { if (tae.ExceptionState is Microsoft.Scripting.KeyboardInterruptException) { Thread.ResetAbort(); } error = "KeyboardInterrupt" + System.Environment.NewLine; } catch (Microsoft.Scripting.SyntaxErrorException exception) { ExceptionOperations eo; eo = commandLine.ScriptScope.Engine.GetService <ExceptionOperations>(); error = eo.FormatException(exception); } catch (Exception exception) { ExceptionOperations eo; eo = commandLine.ScriptScope.Engine.GetService <ExceptionOperations>(); error = eo.FormatException(exception) + System.Environment.NewLine; } Executing = false; if (error != "") { textEditor.Write(error); OnError(new TextEventArgs(error)); } textEditor.Write(prompt); } }
/// <summary> /// Processes characters entering into the text editor by the user. /// </summary> void textEditor_TextEntering(object sender, TextCompositionEventArgs e) { if (e.Text.Length > 0) { if (!char.IsLetterOrDigit(e.Text[0])) { // Whenever a non-letter is typed while the completion window is open, // insert the currently selected element. textEditor.RequestCompletioninsertion(e); } } if (IsInReadOnlyRegion) { e.Handled = true; } else { if (e.Text[0] == '\n') { UpdateVariables?.Invoke(commandLine.ScriptScope); OnEnterKeyPressed(); } if (e.Text[0] == '.' && allowFullAutocompletion) { textEditor.ShowCompletionWindow(); } if ((e.Text[0] == ' ') && (Keyboard.Modifiers == ModifierKeys.Control)) { e.Handled = true; if (allowCtrlSpaceAutocompletion) { textEditor.ShowCompletionWindow(); } } } }