Skip to content

Commit

Permalink
Let users cancel Manim starting (#123)
Browse files Browse the repository at this point in the history
* Let users cancel Manim starting

* Reset lockDuringStartup during shell reset
  • Loading branch information
Splines authored Feb 4, 2025
1 parent c5a17e7 commit 0de567b
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/manimShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ export class ManimShell {
};
this.eventEmitter.on(ManimShellEvent.RESET, resetListener);

let stopEarly = false;
this.eventEmitter.once(ManimShellEvent.MANIM_NOT_STARTED, () => stopEarly = true);

let shell: Terminal;
if (errorOnNoActiveShell) {
shell = this.activeShell as Terminal;
Expand All @@ -368,7 +371,18 @@ export class ManimShell {

let currentExecutionCount = this.iPythonCellCount;

if (stopEarly) {
Logger.debug("🔆 Manim not started, won't exec IPython command (1)");
return;
}

await handler?.beforeCommandIssued?.();

if (stopEarly) {
Logger.debug("🔆 Manim not started, won't exec IPython command (2)");
return;
}

this.exec(shell, command);
handler?.onCommandIssued?.(this.activeShell !== null);

Expand Down Expand Up @@ -447,8 +461,17 @@ export class ManimShell {
title: shouldPreviewWholeScene
? "Previewing whole scene..."
: "Starting Manim...",
cancellable: false,
}, async (_progress, _token) => {
cancellable: true,
}, async (_progress, token) => {
token.onCancellationRequested(() => {
Logger.trace("🔆 Start command cancelled by user");
this.forceQuitActiveShell();
this.resetActiveShell();
});
if (token.isCancellationRequested) {
return;
}

// We are sure that the active shell is set since it is invoked
// in `retrieveOrInitActiveShell()` or in the line above.
this.shellWeTryToSpawnIn = this.activeShell;
Expand Down Expand Up @@ -479,6 +502,7 @@ export class ManimShell {
public resetActiveShell() {
Logger.debug("💫 Reset active shell");
this.isExecutingCommand = false;
this.lockDuringStartup = false;
this.iPythonCellCount = 0;
this.activeShell = null;
this.shellWeTryToSpawnIn = null;
Expand Down

0 comments on commit 0de567b

Please sign in to comment.