Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let users cancel Manim starting #123

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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