File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ const ANSI_CONTROL_SEQUENCE_REGEX = /(?:\x1B[@-Z\\-_]|[\x80-\x9A\x9C-\x9F]|(?:\x
15
15
/**
16
16
* Regular expression to match the start of an IPython cell, e.g. "In [5]:"
17
17
*/
18
- const IPYTHON_CELL_START_REGEX = / ^ \s * I n \[ \d + \] : / m ;
18
+ const IPYTHON_CELL_START_REGEX = / ^ \s * I n \[ \d + \] : / gm ;
19
19
20
20
/**
21
21
* Regular expression to match a KeyboardInterrupt.
@@ -529,11 +529,15 @@ export class ManimShell {
529
529
this . eventEmitter . emit ( ManimShellEvent . KEYBOARD_INTERRUPT ) ;
530
530
}
531
531
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` ) ;
537
541
this . eventEmitter . emit ( ManimShellEvent . IPYTHON_CELL_FINISHED ) ;
538
542
}
539
543
You can’t perform that action at this time.
0 commit comments