@@ -19,6 +19,15 @@ const IPYTHON_CELL_START_REGEX = /^\s*In \[\d+\]:/gm;
19
19
*/
20
20
const LOG_INFO_MESSAGE_REGEX = / ^ \s * \[ .* \] I N F O / m;
21
21
22
+ /**
23
+ * Regular expression to match IPython multiline input "...:"
24
+ * Sometimes IPython does not execute code when entering a newline, but enters a
25
+ * multiline input mode, where it expects another line of code. We detect that
26
+ * this happens and send an extra newline to run the code
27
+ * See: https://github.com/Manim-Notebook/manim-notebook/issues/18
28
+ */
29
+ const IPYTHON_MULTILINE_START_REGEX = / ^ \s * \. { 3 } : \s + $ / m;
30
+
22
31
/**
23
32
* Regular expression to match a KeyboardInterrupt.
24
33
*/
@@ -568,8 +577,9 @@ export class ManimShell {
568
577
*
569
578
* @param shell The shell to execute the command in.
570
579
* @param command The command to execute in the shell.
580
+ * @param useShellIntegration Whether to use shell integration if available
571
581
*/
572
- private exec ( shell : Terminal , command : string ) {
582
+ private exec ( shell : Terminal , command : string , useShellIntegration = true ) {
573
583
if ( ! shell ) {
574
584
Window . showErrorMessage ( "No shell to execute command in. Internal extension error." ) ;
575
585
return ;
@@ -578,7 +588,7 @@ export class ManimShell {
578
588
this . detectShellExecutionEnd = false ;
579
589
Logger . debug ( "🔒 Shell execution end detection disabled" ) ;
580
590
581
- if ( shell . shellIntegration ) {
591
+ if ( useShellIntegration && shell . shellIntegration ) {
582
592
Logger . debug ( `💨 Sending command to terminal (with shell integration): ${ command } ` ) ;
583
593
shell . shellIntegration . executeCommand ( command ) ;
584
594
} else {
@@ -765,6 +775,14 @@ export class ManimShell {
765
775
}
766
776
}
767
777
778
+ if ( this . isExecutingCommand && data . match ( IPYTHON_MULTILINE_START_REGEX ) ) {
779
+ Logger . debug ( "💨 IPython multiline detected, sending extra newline" ) ;
780
+ // do not use shell integration here, as it might send a CTRL-C
781
+ // while the prompt is not finished yet
782
+ // \x7F deletes the extra line ("...:") from IPython
783
+ this . exec ( this . activeShell , "\x7F" , false ) ;
784
+ }
785
+
768
786
if ( data . match ( ERROR_REGEX ) ) {
769
787
Logger . debug ( "🚨 Error in IPython cell detected" ) ;
770
788
this . activeShell ?. show ( ) ;
0 commit comments