@@ -242,27 +242,32 @@ async function runCodeInline() {
242242 // We only want the LAST update (after the last \r)
243243 if ( segment . includes ( '\r' ) ) {
244244 const parts = segment . split ( '\r' ) ;
245- const lastPart = parts [ parts . length - 1 ] . trim ( ) ;
246245
247- if ( lastPart ) {
246+ // Process each part after splitting by \r
247+ for ( let j = 0 ; j < parts . length ; j ++ ) {
248+ const part = parts [ j ] . trim ( ) ;
249+ const isLastPart = j === parts . length - 1 ;
250+
251+ if ( ! part ) continue ;
252+
248253 // Check if this is a tqdm line (contains "it/s]")
249- if ( lastPart . includes ( 'it/s]' ) ) {
250- // Only include if it's the final 100% line
251- if ( lastPart . startsWith ( '100%' ) ) {
252- cleanLines . push ( lastPart ) ;
254+ if ( part . includes ( 'it/s]' ) ) {
255+ // Only include if it's the final 100% line and it's the last part
256+ if ( part . startsWith ( '100%' ) && isLastPart ) {
257+ cleanLines . push ( part ) ;
253258 lastWasTqdm = true ;
254- } else {
259+ } else if ( ! isLastPart ) {
260+ // Intermediate tqdm update, skip but mark as tqdm
255261 lastWasTqdm = true ;
256262 }
257- // Otherwise skip intermediate tqdm updates
258263 } else {
259- // Not a tqdm line, include it
264+ // Not a tqdm line, it's regular content
260265 // If previous was tqdm 100%, add empty line for separation
261266 if ( lastWasTqdm ) {
262267 cleanLines . push ( '' ) ;
263268 lastWasTqdm = false ;
264269 }
265- cleanLines . push ( lastPart ) ;
270+ cleanLines . push ( part ) ;
266271 }
267272 }
268273 } else {
0 commit comments