Skip to content

Commit cad2aa7

Browse files
Finish redirection of $Host.PrivateData (#1734)
We missed the middle layer: public host redirected to internal host, but then internal host needed to redirect to `_hostInfo.PSHost`. Now that it does, `$Host.PrivateData` actually shows the correct console color values, and so `Write-Error 'something'` shows up in the correct color. Also applied Roslynator suggestions to clean some things up.
1 parent f0b5b2e commit cad2aa7

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

+12-25
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ internal class PsesInternalHost : PSHost, IHostSupportsInteractiveSession, IRuns
6363

6464
private EngineIntrinsics _mainRunspaceEngineIntrinsics;
6565

66-
private bool _shouldExit = false;
66+
private bool _shouldExit;
6767

68-
private int _shuttingDown = 0;
68+
private int _shuttingDown;
6969

7070
private string _localComputerName;
7171

7272
private ConsoleKeyInfo? _lastKey;
7373

74-
private bool _skipNextPrompt = false;
74+
private bool _skipNextPrompt;
7575

76-
private bool _resettingRunspace = false;
76+
private bool _resettingRunspace;
7777

7878
public PsesInternalHost(
7979
ILoggerFactory loggerFactory,
@@ -126,6 +126,8 @@ public PsesInternalHost(
126126

127127
public override string Name { get; }
128128

129+
public override PSObject PrivateData => _hostInfo.PSHost.PrivateData;
130+
129131
public override PSHostUserInterface UI { get; }
130132

131133
public override Version Version { get; }
@@ -156,25 +158,13 @@ public PsesInternalHost(
156158

157159
private bool ShouldExitExecutionLoop => _shouldExit || _shuttingDown != 0;
158160

159-
public override void EnterNestedPrompt()
160-
{
161-
PushPowerShellAndRunLoop(CreateNestedPowerShell(CurrentRunspace), PowerShellFrameType.Nested);
162-
}
161+
public override void EnterNestedPrompt() => PushPowerShellAndRunLoop(CreateNestedPowerShell(CurrentRunspace), PowerShellFrameType.Nested);
163162

164-
public override void ExitNestedPrompt()
165-
{
166-
SetExit();
167-
}
163+
public override void ExitNestedPrompt() => SetExit();
168164

169-
public override void NotifyBeginApplication()
170-
{
171-
_hostInfo.PSHost.NotifyBeginApplication();
172-
}
165+
public override void NotifyBeginApplication() => _hostInfo.PSHost.NotifyBeginApplication();
173166

174-
public override void NotifyEndApplication()
175-
{
176-
_hostInfo.PSHost.NotifyEndApplication();
177-
}
167+
public override void NotifyEndApplication() => _hostInfo.PSHost.NotifyEndApplication();
178168

179169
public void PopRunspace()
180170
{
@@ -188,11 +178,8 @@ public void PushRunspace(Runspace runspace)
188178
PushPowerShellAndRunLoop(CreatePowerShellForRunspace(runspace), PowerShellFrameType.Remote);
189179
}
190180

191-
public override void SetShouldExit(int exitCode)
192-
{
193-
// TODO: Handle exit code if needed
194-
SetExit();
195-
}
181+
// TODO: Handle exit code if needed
182+
public override void SetShouldExit(int exitCode) => SetExit();
196183

197184
/// <summary>
198185
/// Try to start the PowerShell loop in the host.

0 commit comments

Comments
 (0)