Skip to content

Commit 3abcb34

Browse files
committed
Fixing tqdm
1 parent a0dd8c1 commit 3abcb34

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

script.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -230,39 +230,33 @@ async function runCodeInline() {
230230

231231
console.log('Full output so far:', JSON.stringify(fullOutput));
232232

233-
// First, add \n after any \r that isn't already followed by \n
234-
let fixed = fullOutput.replace(/\r(?!\n)/g, '\r\n');
235-
236-
// Special fix: detect end of tqdm (pattern like "it/s]") and add newline if not present
237-
// This ensures content after tqdm appears on new line
238-
fixed = fixed.replace(/(\d+\.\d+it\/s\])(?!\n)/g, '$1\n');
239-
240-
console.log('After fixing \\r and tqdm:', JSON.stringify(fixed));
241-
242-
// Now split by \n and process
243-
const lines = fixed.split('\n');
233+
// Split output into segments by \n (real newlines)
234+
const segments = fullOutput.split('\n');
244235
const cleanLines = [];
245236

246-
for (let line of lines) {
247-
// For each line, if it has \r, take only text after the LAST \r
248-
if (line.includes('\r')) {
249-
const parts = line.split('\r');
237+
for (let segment of segments) {
238+
// For each segment, if it contains \r, it's a tqdm progress line being updated
239+
// We only want the LAST update (after the last \r)
240+
if (segment.includes('\r')) {
241+
const parts = segment.split('\r');
250242
const lastPart = parts[parts.length - 1].trim();
243+
251244
if (lastPart) {
252-
// Only add tqdm lines that are at 100% (final state)
253-
// Check if line contains "it/s]" (tqdm pattern)
245+
// Check if this is a tqdm line (contains "it/s]")
254246
if (lastPart.includes('it/s]')) {
255-
// Only include if it starts with "100%"
247+
// Only include if it's the final 100% line
256248
if (lastPart.startsWith('100%')) {
257249
cleanLines.push(lastPart);
258250
}
251+
// Otherwise skip intermediate tqdm updates
259252
} else {
260253
// Not a tqdm line, include it
261254
cleanLines.push(lastPart);
262255
}
263256
}
264257
} else {
265-
const trimmed = line.trim();
258+
// No \r, just a regular line
259+
const trimmed = segment.trim();
266260
if (trimmed) {
267261
cleanLines.push(trimmed);
268262
}

0 commit comments

Comments
 (0)