Skip to content

Commit

Permalink
Revert "Revert sending extra newline (PR #81 as first fix for #18)"
Browse files Browse the repository at this point in the history
This reverts commit dfd453a.
  • Loading branch information
Splines committed Jan 17, 2025
1 parent 981017e commit 9a5fa0f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/manimShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ const IPYTHON_CELL_START_REGEX = /^\s*In \[\d+\]:/gm;
*/
const LOG_INFO_MESSAGE_REGEX = /^\s*\[.*\] INFO/m;

/**
* Regular expression to match IPython multiline input "...:"
* Sometimes IPython does not execute code when entering a newline, but enters a
* multiline input mode, where it expects another line of code. We detect that
* this happens and send an extra newline to run the code
* See: https://github.com/Manim-Notebook/manim-notebook/issues/18
*/
const IPYTHON_MULTILINE_START_REGEX = /^\s*\.{3}:\s+$/m;

/**
* Regular expression to match a KeyboardInterrupt.
*/
Expand Down Expand Up @@ -568,8 +577,9 @@ export class ManimShell {
*
* @param shell The shell to execute the command in.
* @param command The command to execute in the shell.
* @param useShellIntegration Whether to use shell integration if available
*/
private exec(shell: Terminal, command: string) {
private exec(shell: Terminal, command: string, useShellIntegration = true) {
if (!shell) {
Window.showErrorMessage("No shell to execute command in. Internal extension error.");
return;
Expand All @@ -578,7 +588,7 @@ export class ManimShell {
this.detectShellExecutionEnd = false;
Logger.debug("🔒 Shell execution end detection disabled");

if (shell.shellIntegration) {
if (useShellIntegration && shell.shellIntegration) {
Logger.debug(`💨 Sending command to terminal (with shell integration): ${command}`);
shell.shellIntegration.executeCommand(command);
} else {
Expand Down Expand Up @@ -765,6 +775,14 @@ export class ManimShell {
}
}

if (this.isExecutingCommand && data.match(IPYTHON_MULTILINE_START_REGEX)) {
Logger.debug("💨 IPython multiline detected, sending extra newline");
// do not use shell integration here, as it might send a CTRL-C
// while the prompt is not finished yet
// \x7F deletes the extra line ("...:") from IPython
this.exec(this.activeShell, "\x7F", false);
}

if (data.match(ERROR_REGEX)) {
Logger.debug("🚨 Error in IPython cell detected");
this.activeShell?.show();
Expand Down

0 comments on commit 9a5fa0f

Please sign in to comment.