@@ -757,18 +757,22 @@ private void DoOneRepl(CancellationToken cancellationToken)
757757
758758 // If the user input was empty it's because:
759759 // - 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)
762762 //
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.
765766 if ( string . IsNullOrEmpty ( userInput ) )
766767 {
767- if ( cancellationToken . IsCancellationRequested || LastKeyWasCtrlC ( ) )
768+ if ( LastKeyWasCtrlC ( ) )
768769 {
769770 UI . WriteLine ( ) ;
770771 }
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.
772776 }
773777
774778 InvokeInput ( userInput , cancellationToken ) ;
@@ -782,10 +786,8 @@ private void DoOneRepl(CancellationToken cancellationToken)
782786 {
783787 throw ;
784788 }
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 ) { }
789791 catch ( Exception e )
790792 {
791793 UI . WriteErrorLine ( $ "An error occurred while running the REPL loop:{ Environment . NewLine } { e } ") ;
@@ -829,25 +831,14 @@ private string GetPrompt(CancellationToken cancellationToken)
829831 return prompt ;
830832 }
831833
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-
845834 private string InvokeReadLine ( CancellationToken cancellationToken )
846835 {
847- cancellationToken . ThrowIfCancellationRequested ( ) ;
848836 try
849837 {
838+ // TODO: If we can pass the cancellation token to ReadKey directly in PSReadLine, we
839+ // can remove this logic.
850840 _readKeyCancellationToken = cancellationToken ;
841+ cancellationToken . ThrowIfCancellationRequested ( ) ;
851842 return _readLineProvider . ReadLine . ReadLine ( cancellationToken ) ;
852843 }
853844 finally
0 commit comments