@@ -225,31 +225,41 @@ async function runCodeInline() {
225225 batched : ( text ) => {
226226 fullOutput += text ;
227227
228- // Split into lines, keeping track of line endings
228+ // Process the output: split by \n to get actual lines
229229 const lines = fullOutput . split ( '\n' ) ;
230- const finalLines = [ ] ;
230+ const processedLines = [ ] ;
231231
232+ // For each line except the last (incomplete one)
232233 for ( let i = 0 ; i < lines . length - 1 ; i ++ ) {
233234 const line = lines [ i ] ;
234- // Split by \r to get only the last update of lines that had \r
235- const parts = line . split ( '\r' ) ;
236- const finalPart = parts [ parts . length - 1 ] ;
237- if ( finalPart . trim ( ) ) {
238- finalLines . push ( finalPart ) ;
235+ // If line contains \r, only take the text after the last \r
236+ // This gives us the final state of tqdm progress bars
237+ if ( line . includes ( '\r' ) ) {
238+ const parts = line . split ( '\r' ) ;
239+ const lastPart = parts [ parts . length - 1 ] ;
240+ if ( lastPart . trim ( ) ) {
241+ processedLines . push ( lastPart ) ;
242+ }
243+ } else if ( line . trim ( ) ) {
244+ processedLines . push ( line ) ;
239245 }
240246 }
241247
242- // Add last line if it exists and isn't empty
248+ // Handle the last incomplete line
243249 const lastLine = lines [ lines . length - 1 ] ;
244250 if ( lastLine ) {
245- const parts = lastLine . split ( '\r' ) ;
246- const finalPart = parts [ parts . length - 1 ] ;
247- if ( finalPart . trim ( ) ) {
248- finalLines . push ( finalPart ) ;
251+ if ( lastLine . includes ( '\r' ) ) {
252+ const parts = lastLine . split ( '\r' ) ;
253+ const lastPart = parts [ parts . length - 1 ] ;
254+ if ( lastPart . trim ( ) ) {
255+ processedLines . push ( lastPart ) ;
256+ }
257+ } else if ( lastLine . trim ( ) ) {
258+ processedLines . push ( lastLine ) ;
249259 }
250260 }
251261
252- output . innerHTML = `<pre style="margin: 0; color: #d4d4d4; white-space: pre-wrap;">${ escapeHtml ( finalLines . join ( '\n' ) ) } </pre>` ;
262+ output . innerHTML = `<pre style="margin: 0; color: #d4d4d4; white-space: pre-wrap;">${ escapeHtml ( processedLines . join ( '\n' ) ) } </pre>` ;
253263 }
254264 } ) ;
255265
0 commit comments