Skip to content

Commit 0de567b

Browse files
authored
Let users cancel Manim starting (#123)
* Let users cancel Manim starting * Reset lockDuringStartup during shell reset
1 parent c5a17e7 commit 0de567b

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/manimShell.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ export class ManimShell {
352352
};
353353
this.eventEmitter.on(ManimShellEvent.RESET, resetListener);
354354

355+
let stopEarly = false;
356+
this.eventEmitter.once(ManimShellEvent.MANIM_NOT_STARTED, () => stopEarly = true);
357+
355358
let shell: Terminal;
356359
if (errorOnNoActiveShell) {
357360
shell = this.activeShell as Terminal;
@@ -368,7 +371,18 @@ export class ManimShell {
368371

369372
let currentExecutionCount = this.iPythonCellCount;
370373

374+
if (stopEarly) {
375+
Logger.debug("🔆 Manim not started, won't exec IPython command (1)");
376+
return;
377+
}
378+
371379
await handler?.beforeCommandIssued?.();
380+
381+
if (stopEarly) {
382+
Logger.debug("🔆 Manim not started, won't exec IPython command (2)");
383+
return;
384+
}
385+
372386
this.exec(shell, command);
373387
handler?.onCommandIssued?.(this.activeShell !== null);
374388

@@ -447,8 +461,17 @@ export class ManimShell {
447461
title: shouldPreviewWholeScene
448462
? "Previewing whole scene..."
449463
: "Starting Manim...",
450-
cancellable: false,
451-
}, async (_progress, _token) => {
464+
cancellable: true,
465+
}, async (_progress, token) => {
466+
token.onCancellationRequested(() => {
467+
Logger.trace("🔆 Start command cancelled by user");
468+
this.forceQuitActiveShell();
469+
this.resetActiveShell();
470+
});
471+
if (token.isCancellationRequested) {
472+
return;
473+
}
474+
452475
// We are sure that the active shell is set since it is invoked
453476
// in `retrieveOrInitActiveShell()` or in the line above.
454477
this.shellWeTryToSpawnIn = this.activeShell;
@@ -479,6 +502,7 @@ export class ManimShell {
479502
public resetActiveShell() {
480503
Logger.debug("💫 Reset active shell");
481504
this.isExecutingCommand = false;
505+
this.lockDuringStartup = false;
482506
this.iPythonCellCount = 0;
483507
this.activeShell = null;
484508
this.shellWeTryToSpawnIn = null;

0 commit comments

Comments
 (0)