@@ -79,6 +79,7 @@ public ConsoleService(
79
79
this . powerShellContext . ConsoleHost = this ;
80
80
this . powerShellContext . DebuggerStop += PowerShellContext_DebuggerStop ;
81
81
this . powerShellContext . DebuggerResumed += PowerShellContext_DebuggerResumed ;
82
+ this . powerShellContext . ExecutionStatusChanged += PowerShellContext_ExecutionStatusChanged ;
82
83
83
84
// Set the default prompt handler factory or create
84
85
// a default if one is not provided
@@ -140,31 +141,6 @@ public void CancelReadLoop()
140
141
}
141
142
}
142
143
143
- /// <summary>
144
- /// Called when a command string is received from the user.
145
- /// If a prompt is currently active, the prompt handler is
146
- /// asked to handle the string. Otherwise the string is
147
- /// executed in the PowerShellContext.
148
- /// </summary>
149
- /// <param name="inputString">The input string to evaluate.</param>
150
- /// <param name="echoToConsole">If true, the input will be echoed to the console.</param>
151
- public void ExecuteCommand ( string inputString , bool echoToConsole )
152
- {
153
- this . CancelReadLoop ( ) ;
154
-
155
- if ( this . activePromptHandler == null )
156
- {
157
- // Execute the script string but don't wait for completion
158
- var executeTask =
159
- this . powerShellContext
160
- . ExecuteScriptString (
161
- inputString ,
162
- echoToConsole ,
163
- true )
164
- . ConfigureAwait ( false ) ;
165
- }
166
- }
167
-
168
144
/// <summary>
169
145
/// Executes a script file at the specified path.
170
146
/// </summary>
@@ -338,11 +314,16 @@ await this.consoleReadLine.ReadCommandLine(
338
314
{
339
315
Console . Write ( Environment . NewLine ) ;
340
316
341
- await this . powerShellContext . ExecuteScriptString (
342
- commandString ,
343
- false ,
344
- true ,
345
- true ) ;
317
+ var unusedTask =
318
+ this . powerShellContext
319
+ . ExecuteScriptString (
320
+ commandString ,
321
+ false ,
322
+ true ,
323
+ true )
324
+ . ConfigureAwait ( false ) ;
325
+
326
+ break ;
346
327
}
347
328
}
348
329
while ( ! cancellationToken . IsCancellationRequested ) ;
@@ -459,6 +440,37 @@ private void PowerShellContext_DebuggerResumed(object sender, System.Management.
459
440
this . CancelReadLoop ( ) ;
460
441
}
461
442
443
+ private void PowerShellContext_ExecutionStatusChanged ( object sender , ExecutionStatusChangedEventArgs eventArgs )
444
+ {
445
+ if ( this . EnableConsoleRepl )
446
+ {
447
+ // Any command which writes output to the host will affect
448
+ // the display of the prompt
449
+ if ( eventArgs . ExecutionOptions . WriteOutputToHost ||
450
+ eventArgs . ExecutionOptions . InterruptCommandPrompt )
451
+ {
452
+ if ( eventArgs . ExecutionStatus != ExecutionStatus . Running )
453
+ {
454
+ // Execution has completed, start the input prompt
455
+ this . StartReadLoop ( ) ;
456
+ }
457
+ else
458
+ {
459
+ // A new command was started, cancel the input prompt
460
+ this . CancelReadLoop ( ) ;
461
+ }
462
+ }
463
+ else if (
464
+ eventArgs . ExecutionOptions . WriteErrorsToHost &&
465
+ ( eventArgs . ExecutionStatus == ExecutionStatus . Failed ||
466
+ eventArgs . HadErrors ) )
467
+ {
468
+ this . CancelReadLoop ( ) ;
469
+ this . StartReadLoop ( ) ;
470
+ }
471
+ }
472
+ }
473
+
462
474
#endregion
463
475
}
464
476
}
0 commit comments