/// <summary>
        /// Wires up a PowerShell runspace created via <see cref="RunspaceFactory.CreateRunspace()"/> to the terminal to display the PowerShell to the user.
        /// </summary>
        public override void Connect()
        {
            GEnv.Options.Font = Connection.Font;

            _progressBar.Value  = 0;
            _progressLabel.Text = "";

            // This is not strictly a network connection:  we're relaying information that we receive from the runspace to the terminal over a local stream
            // (a StreamConnection in this case)
            TerminalParam terminalParam = TCPTerminalParam.Fake;

            terminalParam.TerminalType  = TerminalType.XTerm;
            terminalParam.RenderProfile = new RenderProfile();
            terminalParam.Encoding      = EncodingType.UTF8;

            StreamConnection connection = new StreamConnection(terminalParam)
            {
                Capture = false
            };

            ConnectionTag connectionTag = new ConnectionTag(connection);

            connectionTag.Receiver.Listen();

            // Attach the new "connection" to the terminal control
            _terminal.TerminalPane.FakeVisible = true;
            _terminal.TerminalPane.Attach(connectionTag);
            _terminal.TerminalPane.Focus();
            _terminal.TerminalPane.SendShiftTab = true;
            _terminal.SetPaneColors(Connection.TextColor, Connection.BackgroundColor);

            try
            {
                _powerShellHost = new PowerShellHost(this, _terminal, ExecuteQuiet, _progressBar, _progressLabel);

                // Create the host and runspace instances for this interpreter.  If we're connecting to the local host, don't bother with the connection info.
                // ReSharper disable StringCompareIsCultureSpecific.3
                if (String.Compare(Connection.Host, "localhost", true) != 0 && Connection.Host != "127.0.0.1" &&
                    String.Compare(Connection.Host, Environment.MachineName, true) != 0)
                // ReSharper restore StringCompareIsCultureSpecific.3
                {
                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo
                    {
                        ComputerName = Connection.Host
                    };

                    if (!String.IsNullOrEmpty(Connection.InheritedUsername))
                    {
                        connectionInfo.Credential = new PSCredential(Connection.InheritedUsername, Connection.InheritedPassword);
                    }

                    Runspace = RunspaceFactory.CreateRunspace(_powerShellHost, connectionInfo);
                }

                else
                {
                    Runspace = RunspaceFactory.CreateRunspace(_powerShellHost);
                }

                Runspace.Open();
            }

            catch (Exception e)
            {
                OnConnectionLost(this, new ErrorEventArgs(e));
                return;
            }

            // Start capturing input from the prompt via the input loop
            _inputThread = new Thread(InputLoop)
            {
                Name = "PowerShellConnectionForm Input Thread"
            };
            _inputThread.Start();

            ParentForm.Closing += ParentForm_Closing;

            OnConnected(this, null);
        }
        /// <summary>
        /// Wires up a PowerShell runspace created via <see cref="RunspaceFactory.CreateRunspace()"/> to the terminal to display the PowerShell to the user.
        /// </summary>
        public override void Connect()
        {
            _progressBar.Value  = 0;
            _progressLabel.Text = "";

            // This is not strictly a network connection:  we're relaying information that we receive from the runspace to the terminal over a local stream
            // (a StreamConnection in this case)
            ITerminalParameter terminalParam = new EmptyTerminalParameter();
            StreamConnection   connection    = new StreamConnection(terminalParam)
            {
                Capture = false
            };

            // Attach the new "connection" to the terminal control
            try
            {
                ITerminalSettings terminalSettings = PoderosaTerminalEmulatorService.CreateDefaultTerminalSettings(Connection.DisplayName, null);
                TerminalSession   session          = new TerminalSession(connection, terminalSettings);
                SessionHost       sessionHost      = new SessionHost(PoderosaSessionManagerPlugin, session);
                TerminalView      terminalView     = new TerminalView(null, _terminal);
                RenderProfile     renderProfile    = new RenderProfile(_terminal.GetRenderProfile());

                renderProfile.BackColor = Connection.BackgroundColor;
                renderProfile.ForeColor = Connection.TextColor;
                renderProfile.FontName  = Connection.FontFamily;
                renderProfile.FontSize  = Connection.FontSize;

                session.TerminalSettings.BeginUpdate();
                session.TerminalSettings.RenderProfile = renderProfile;
                session.TerminalSettings.EndUpdate();

                _terminal.Attach(session);

                session.InternalStart(sessionHost);
                session.InternalAttachView(sessionHost.DocumentAt(0), terminalView);

                _powerShellHost = new PowerShellHost(this, _terminal, connection, ExecuteQuiet, _progressBar, _progressLabel);

                // Create the host and runspace instances for this interpreter.  If we're connecting to the local host, don't bother with the connection info.
                // ReSharper disable StringCompareIsCultureSpecific.3
                if (String.Compare(Connection.Host, "localhost", true) != 0 && Connection.Host != "127.0.0.1" &&
                    String.Compare(Connection.Host, Environment.MachineName, true) != 0)
                // ReSharper restore StringCompareIsCultureSpecific.3
                {
                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo
                    {
                        ComputerName = Connection.Host
                    };

                    if (!String.IsNullOrEmpty(Connection.InheritedUsername))
                    {
                        connectionInfo.Credential = new PSCredential(Connection.InheritedUsername, Connection.InheritedPassword);
                    }

                    Runspace = RunspaceFactory.CreateRunspace(_powerShellHost, connectionInfo);
                }

                else
                {
                    Runspace = RunspaceFactory.CreateRunspace(_powerShellHost);
                }

                Runspace.Open();
            }

            catch (Exception e)
            {
                OnConnectionLost(this, new ErrorEventArgs(e));
                return;
            }

            // Start capturing input from the prompt via the input loop
            _inputThread = new Thread(InputLoop)
            {
                Name = "PowerShellConnectionForm Input Thread"
            };
            _inputThread.Start();

            ParentForm.Closing += ParentForm_Closing;

            OnConnected(this, null);
        }