Skip to content

Commit 9a5fa0f

Browse files
committed
Revert "Revert sending extra newline (PR #81 as first fix for #18)"
This reverts commit dfd453a.
1 parent 981017e commit 9a5fa0f

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/manimShell.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ const IPYTHON_CELL_START_REGEX = /^\s*In \[\d+\]:/gm;
1919
*/
2020
const LOG_INFO_MESSAGE_REGEX = /^\s*\[.*\] INFO/m;
2121

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+
2231
/**
2332
* Regular expression to match a KeyboardInterrupt.
2433
*/
@@ -568,8 +577,9 @@ export class ManimShell {
568577
*
569578
* @param shell The shell to execute the command in.
570579
* @param command The command to execute in the shell.
580+
* @param useShellIntegration Whether to use shell integration if available
571581
*/
572-
private exec(shell: Terminal, command: string) {
582+
private exec(shell: Terminal, command: string, useShellIntegration = true) {
573583
if (!shell) {
574584
Window.showErrorMessage("No shell to execute command in. Internal extension error.");
575585
return;
@@ -578,7 +588,7 @@ export class ManimShell {
578588
this.detectShellExecutionEnd = false;
579589
Logger.debug("🔒 Shell execution end detection disabled");
580590

581-
if (shell.shellIntegration) {
591+
if (useShellIntegration && shell.shellIntegration) {
582592
Logger.debug(`💨 Sending command to terminal (with shell integration): ${command}`);
583593
shell.shellIntegration.executeCommand(command);
584594
} else {
@@ -765,6 +775,14 @@ export class ManimShell {
765775
}
766776
}
767777

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+
768786
if (data.match(ERROR_REGEX)) {
769787
Logger.debug("🚨 Error in IPython cell detected");
770788
this.activeShell?.show();

0 commit comments

Comments
 (0)