public void ClearView() { if (_window._stdInputStart != null) { CancelStandardInput(); } _window._adornmentToMinimize = false; InlineAdornmentProvider.RemoveAllAdornments(_window._textView); // remove all the spans except our initial span from the projection buffer _window._promptLineMapping.Clear(); UncommittedInput = null; // Clear the projection and buffers last as this might trigger events that might access other state of the REPL window: RemoveProtection(_window._outputBuffer, _outputProtection); RemoveProtection(_window._standardInputBuffer, StandardInputProtection); using (var edit = _window._outputBuffer.CreateEdit(EditOptions.None, null, s_suppressPromptInjectionTag)) { edit.Delete(0, _window._outputBuffer.CurrentSnapshot.Length); edit.Apply(); } _window._buffer.Reset(); OutputClassifierProvider.ClearSpans(_window._outputBuffer); _outputTrackingCaretPosition = 0; using (var edit = _window._standardInputBuffer.CreateEdit(EditOptions.None, null, s_suppressPromptInjectionTag)) { edit.Delete(0, _window._standardInputBuffer.CurrentSnapshot.Length); edit.Apply(); } RemoveProjectionSpans(0, _window._projectionSpans.Count); // Insert an empty output buffer. // We do it for two reasons: // 1) When output is written to asynchronously we need a buffer to store it. // This may happen when clearing screen while background thread is writing to the console. // 2) We need at least one non-inert span due to bugs in projection buffer. AppendNewOutputProjectionBuffer(); _window._history.ForgetOriginalBuffers(); // If we were waiting for input, we need to restore the prompt that we just cleared. // If we are in any other state, then we'll let normal transitions trigger the next prompt. if (State == State.WaitingForInput) { PrepareForInput(); } }
public InteractiveWindow( IInteractiveWindowEditorFactoryService host, IContentTypeRegistryService contentTypeRegistry, ITextBufferFactoryService bufferFactory, IProjectionBufferFactoryService projectionBufferFactory, IEditorOperationsFactoryService editorOperationsFactory, ITextEditorFactoryService editorFactory, IRtfBuilderService rtfBuilderService, IIntellisenseSessionStackMapService intellisenseSessionStackMap, ISmartIndentationService smartIndenterService, IInteractiveEvaluator evaluator) { if (evaluator == null) { throw new ArgumentNullException(nameof(evaluator)); } _dangerous_uiOnly = new UIThreadOnly(this, host); this.Properties = new PropertyCollection(); _history = new History(); _intellisenseSessionStackMap = intellisenseSessionStackMap; _smartIndenterService = smartIndenterService; var replContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveContentTypeName); var replOutputContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveOutputContentTypeName); _outputBuffer = bufferFactory.CreateTextBuffer(replOutputContentType); _standardInputBuffer = bufferFactory.CreateTextBuffer(); _promptBuffer = bufferFactory.CreateTextBuffer(); _secondaryPromptBuffer = bufferFactory.CreateTextBuffer(); _standardInputPromptBuffer = bufferFactory.CreateTextBuffer(); _outputLineBreakBuffer = bufferFactory.CreateTextBuffer(); var projBuffer = projectionBufferFactory.CreateProjectionBuffer( new EditResolver(this), Array.Empty <object>(), ProjectionBufferOptions.None, replContentType); projBuffer.Properties.AddProperty(typeof(InteractiveWindow), this); _projectionBuffer = projBuffer; _dangerous_uiOnly.AppendNewOutputProjectionBuffer(); // Constructor runs on UI thread. projBuffer.Changed += new EventHandler <TextContentChangedEventArgs>(ProjectionBufferChanged); var roleSet = editorFactory.CreateTextViewRoleSet( PredefinedTextViewRoles.Analyzable, PredefinedTextViewRoles.Editable, PredefinedTextViewRoles.Interactive, PredefinedTextViewRoles.Zoomable, PredefinedInteractiveTextViewRoles.InteractiveTextViewRole); _textView = host.CreateTextView(this, projBuffer, roleSet); _textView.Caret.PositionChanged += CaretPositionChanged; _textView.Options.SetOptionValue(DefaultTextViewHostOptions.HorizontalScrollBarId, false); _textView.Options.SetOptionValue(DefaultTextViewHostOptions.LineNumberMarginId, false); _textView.Options.SetOptionValue(DefaultTextViewHostOptions.OutliningMarginId, false); _textView.Options.SetOptionValue(DefaultTextViewHostOptions.GlyphMarginId, false); _textView.Options.SetOptionValue(DefaultTextViewOptions.WordWrapStyleId, WordWrapStyles.WordWrap); _lineBreakString = _textView.Options.GetNewLineCharacter(); _dangerous_uiOnly.EditorOperations = editorOperationsFactory.GetEditorOperations(_textView); // Constructor runs on UI thread. _buffer = new OutputBuffer(this); _outputWriter = new InteractiveWindowWriter(this, spans: null); SortedSpans errorSpans = new SortedSpans(); _errorOutputWriter = new InteractiveWindowWriter(this, errorSpans); OutputClassifierProvider.AttachToBuffer(_outputBuffer, errorSpans); _rtfBuilderService = rtfBuilderService; RequiresUIThread(); evaluator.CurrentWindow = this; _evaluator = evaluator; }