@@ -757,18 +757,22 @@ private void DoOneRepl(CancellationToken cancellationToken)
757
757
758
758
// If the user input was empty it's because:
759
759
// - the user provided no input
760
- // - the readline task was canceled
761
- // - CtrlC was sent to readline (which does not propagate a cancellation)
760
+ // - the ReadLine task was canceled
761
+ // - CtrlC was sent to ReadLine (which does not propagate a cancellation)
762
762
//
763
- // In any event there's nothing to run in PowerShell, so we just loop back to the prompt again.
764
- // However, we must distinguish the last two scenarios, since PSRL will not print a new line in those cases.
763
+ // In any event there's nothing to run in PowerShell, so we just loop back to the
764
+ // prompt again. However, PSReadLine will not print a newline for CtrlC, so we print
765
+ // one, but we do not want to print one if the ReadLine task was canceled.
765
766
if ( string . IsNullOrEmpty ( userInput ) )
766
767
{
767
- if ( cancellationToken . IsCancellationRequested || LastKeyWasCtrlC ( ) )
768
+ if ( LastKeyWasCtrlC ( ) )
768
769
{
769
770
UI . WriteLine ( ) ;
770
771
}
771
- return ;
772
+ // Propogate cancellation if that's what happened, since ReadLine won't.
773
+ // TODO: We may not need to do this at all.
774
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
775
+ return ; // Task wasn't canceled but there was no input.
772
776
}
773
777
774
778
InvokeInput ( userInput , cancellationToken ) ;
@@ -782,10 +786,8 @@ private void DoOneRepl(CancellationToken cancellationToken)
782
786
{
783
787
throw ;
784
788
}
785
- catch ( FlowControlException )
786
- {
787
- // Do nothing, a break or continue statement was used outside of a loop.
788
- }
789
+ // Do nothing, a break or continue statement was used outside of a loop.
790
+ catch ( FlowControlException ) { }
789
791
catch ( Exception e )
790
792
{
791
793
UI . WriteErrorLine ( $ "An error occurred while running the REPL loop:{ Environment . NewLine } { e } ") ;
@@ -829,25 +831,16 @@ private string GetPrompt(CancellationToken cancellationToken)
829
831
return prompt ;
830
832
}
831
833
832
- /// <summary>
833
- /// This is used to write the invocation text of a command with the user's prompt so that,
834
- /// for example, F8 (evaluate selection) appears as if the user typed it. Used when
835
- /// 'WriteInputToHost' is true.
836
- /// </summary>
837
- /// <param name="command">The PSCommand we'll print after the prompt.</param>
838
- /// <param name="cancellationToken"></param>
839
- public void WriteWithPrompt ( PSCommand command , CancellationToken cancellationToken )
840
- {
841
- UI . Write ( GetPrompt ( cancellationToken ) ) ;
842
- UI . WriteLine ( command . GetInvocationText ( ) ) ;
843
- }
844
-
845
834
private string InvokeReadLine ( CancellationToken cancellationToken )
846
835
{
847
836
cancellationToken . ThrowIfCancellationRequested ( ) ;
848
837
try
849
838
{
839
+ // TODO: If we can pass the cancellation token to ReadKey directly in PSReadLine, we
840
+ // can remove this logic.
841
+ _logger . LogDebug ( "Saving ReadKey cancellation token and invoking ReadLine" ) ;
850
842
_readKeyCancellationToken = cancellationToken ;
843
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
851
844
return _readLineProvider . ReadLine . ReadLine ( cancellationToken ) ;
852
845
}
853
846
finally
0 commit comments