Skip to content

Commit b278ded

Browse files
authored
Fix IPython cell detection (multiple ones in one datastream) (#64)
* Fix multiple possible IPython cells in one terminal data * Fix forgotten variable rename
1 parent 853e6c7 commit b278ded

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/manimShell.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const ANSI_CONTROL_SEQUENCE_REGEX = /(?:\x1B[@-Z\\-_]|[\x80-\x9A\x9C-\x9F]|(?:\x
1515
/**
1616
* Regular expression to match the start of an IPython cell, e.g. "In [5]:"
1717
*/
18-
const IPYTHON_CELL_START_REGEX = /^\s*In \[\d+\]:/m;
18+
const IPYTHON_CELL_START_REGEX = /^\s*In \[\d+\]:/gm;
1919

2020
/**
2121
* Regular expression to match a KeyboardInterrupt.
@@ -529,11 +529,15 @@ export class ManimShell {
529529
this.eventEmitter.emit(ManimShellEvent.KEYBOARD_INTERRUPT);
530530
}
531531

532-
let ipythonMatch = data.match(IPYTHON_CELL_START_REGEX);
533-
if (ipythonMatch) {
534-
const cellNumber = parseInt(ipythonMatch[0].match(/\d+/)![0]);
535-
this.iPythonCellCount = cellNumber;
536-
Logger.debug(`📦 IPython cell ${cellNumber} detected`);
532+
let ipythonMatches = data.match(IPYTHON_CELL_START_REGEX);
533+
if (ipythonMatches) {
534+
// Terminal data might include multiple IPython statements,
535+
// so take the highest cell number found.
536+
const cellNumbers = ipythonMatches.map(
537+
match => parseInt(match.match(/\d+/)![0]));
538+
const maxCellNumber = Math.max(...cellNumbers);
539+
this.iPythonCellCount = maxCellNumber;
540+
Logger.debug(`📦 IPython cell ${maxCellNumber} detected`);
537541
this.eventEmitter.emit(ManimShellEvent.IPYTHON_CELL_FINISHED);
538542
}
539543

0 commit comments

Comments
 (0)