@@ -218,29 +218,30 @@ async function runCodeInline() {
218218 }
219219 }
220220
221- // Capture stdout - filter tqdm and ensure newlines after progress bars
221+ // Capture stdout - filter tqdm intermediate updates
222222 let fullOutput = '' ;
223- let lastHadCarriageReturn = false ;
224223
225224 pyodide . setStdout ( {
226225 batched : ( text ) => {
227226 fullOutput += text ;
228227
229- // Check if we need to insert newline after previous tqdm line
230- let processedOutput = fullOutput ;
231-
232- // Replace any sequence of: stuff \r final_stuff (not followed by \n) with: final_stuff \n
233- // This ensures tqdm completion is followed by newline
234- processedOutput = processedOutput . replace ( / [ ^ \n ] * \r ( [ ^ \r \n ] + ) (? ! \n ) / g, '$1\n' ) ;
235-
236- // Now split by newlines and clean up
237- const lines = processedOutput . split ( '\n' ) ;
228+ // Split by \n first to preserve actual newlines
229+ const lines = fullOutput . split ( '\n' ) ;
238230 const cleanLines = [ ] ;
239231
240232 for ( let line of lines ) {
241- const trimmed = line . trim ( ) ;
242- if ( trimmed ) {
243- cleanLines . push ( trimmed ) ;
233+ // For each line, if it has \r, take only text after the LAST \r
234+ if ( line . includes ( '\r' ) ) {
235+ const parts = line . split ( '\r' ) ;
236+ const lastPart = parts [ parts . length - 1 ] . trim ( ) ;
237+ if ( lastPart ) {
238+ cleanLines . push ( lastPart ) ;
239+ }
240+ } else {
241+ const trimmed = line . trim ( ) ;
242+ if ( trimmed ) {
243+ cleanLines . push ( trimmed ) ;
244+ }
244245 }
245246 }
246247
0 commit comments