Repository: microsoft/terminal (language: cpp)

Issue:
WPF Terminal Control crashes when set to a null Connection
### Windows Terminal version

n/a

### Windows build number

10.0.19044

### Other Software

WPF / .net control

### Steps to reproduce

The `Microsoft.Terminal.Wpf.TerminalControl` instance has a `ITerminalConnection Connection` interface that relates the backend connection.  While this starts as null, once it is set to not null setting it back to null throws an UE.  In fact probably just setting it to null when already null would do the same as the setter control tries to access the TerminalOutput function on the value.

### Expected Behavior

not to fault just to clear the old connection.

### Actual Behavior

unhandled exception

will submit PR to fix.


Discussion / hints:

Fix patch:
diff --git a/src/cascadia/WpfTerminalControl/TerminalContainer.cs b/src/cascadia/WpfTerminalControl/TerminalContainer.cs
index 5480f53fce3..c9bed99c5cb 100644
--- a/src/cascadia/WpfTerminalControl/TerminalContainer.cs
+++ b/src/cascadia/WpfTerminalControl/TerminalContainer.cs
@@ -113,10 +113,23 @@ private get
                 {
                     this.connection.TerminalOutput -= this.Connection_TerminalOutput;
                 }
-
+                this.Connection_TerminalOutput(this, new TerminalOutputEventArgs("\x001bc\x1b]104\x1b\\")); //reset console/clear screen - https://github.com/microsoft/terminal/pull/15062#issuecomment-1505654110
+                var wasNull = this.connection == null;
                 this.connection = value;
-                this.connection.TerminalOutput += this.Connection_TerminalOutput;
-                this.connection.Start();
+                if (this.connection != null)
+                {
+                    if (wasNull)
+                    {
+                         this.Connection_TerminalOutput(this, new TerminalOutputEventArgs("\x1b[?25h")); //show cursor
+                    }
+                    this.connection.TerminalOutput += this.Connection_TerminalOutput;
+                    this.connection.Start();
+                }
+                else
+                {
+                    this.Connection_TerminalOutput(this, new TerminalOutputEventArgs("\x1b[?25l")); //hide cursor
+                }
+                    
             }
         }
 


Test patch: