@@ -218,48 +218,37 @@ async function runCodeInline() {
218218 }
219219 }
220220
221- // Capture stdout - only show final state ( filter tqdm intermediate updates)
221+ // Capture stdout - filter tqdm and ensure newlines
222222 let fullOutput = '' ;
223223
224224 pyodide . setStdout ( {
225225 batched : ( text ) => {
226226 fullOutput += text ;
227227
228- // Process the output: split by \n to get actual lines
228+ // Split by actual newlines
229229 const lines = fullOutput . split ( '\n' ) ;
230- const processedLines = [ ] ;
230+ const cleanLines = [ ] ;
231231
232- // For each line except the last (incomplete one)
233- for ( let i = 0 ; i < lines . length - 1 ; i ++ ) {
232+ for ( let i = 0 ; i < lines . length ; i ++ ) {
234233 const line = lines [ i ] ;
235- // If line contains \r, only take the text after the last \r
236- // This gives us the final state of tqdm progress bars
234+
235+ // If this line has \r (tqdm), take only the last part after final \r
237236 if ( line . includes ( '\r' ) ) {
238237 const parts = line . split ( '\r' ) ;
239- const lastPart = parts [ parts . length - 1 ] ;
240- if ( lastPart . trim ( ) ) {
241- processedLines . push ( lastPart ) ;
238+ const lastPart = parts [ parts . length - 1 ] . trim ( ) ;
239+ if ( lastPart ) {
240+ cleanLines . push ( lastPart ) ;
242241 }
243- } else if ( line . trim ( ) ) {
244- processedLines . push ( line ) ;
245- }
246- }
247-
248- // Handle the last incomplete line
249- const lastLine = lines [ lines . length - 1 ] ;
250- if ( lastLine ) {
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 ) ;
242+ } else {
243+ const trimmed = line . trim ( ) ;
244+ if ( trimmed ) {
245+ cleanLines . push ( trimmed ) ;
256246 }
257- } else if ( lastLine . trim ( ) ) {
258- processedLines . push ( lastLine ) ;
259247 }
260248 }
261249
262- output . innerHTML = `<pre style="margin: 0; color: #d4d4d4; white-space: pre-wrap;">${ escapeHtml ( processedLines . join ( '\n' ) ) } </pre>` ;
250+ // Display with explicit newlines between everything
251+ output . innerHTML = `<pre style="margin: 0; color: #d4d4d4; white-space: pre-wrap;">${ escapeHtml ( cleanLines . join ( '\n' ) ) } </pre>` ;
263252 }
264253 } ) ;
265254
0 commit comments