| | export function processLogs(logs: string): string { |
| | if (!logs) return ''; |
| |
|
| | |
| | const rawLines = logs.split('\n'); |
| | const processedLines: string[] = []; |
| | |
| | for (const rawLine of rawLines) { |
| | |
| | let line = rawLine; |
| | if (line.endsWith('\r')) { |
| | line = line.slice(0, -1); |
| | } |
| |
|
| | if (line.includes('\r')) { |
| | const segments = line.split('\r'); |
| | |
| | |
| | let found = false; |
| | for (let i = segments.length - 1; i >= 0; i--) { |
| | if (segments[i].length > 0) { |
| | processedLines.push(segments[i]); |
| | found = true; |
| | break; |
| | } |
| | } |
| | if (!found) { |
| | |
| | processedLines.push(""); |
| | } |
| | } else { |
| | processedLines.push(line); |
| | } |
| | } |
| |
|
| | |
| | const finalLines: string[] = []; |
| | |
| | |
| | const downloadPattern = /^(Downloading|Downloaded)\s+/; |
| | |
| | |
| | |
| | |
| | |
| | |
| | const tqdmPattern = /^\s*\d+%\|.*\||^\s*\d+%\s+/; |
| |
|
| | for (let i = 0; i < processedLines.length; i++) { |
| | const line = processedLines[i]; |
| | |
| | |
| | if (downloadPattern.test(line)) { |
| | |
| | let nextIsDownload = false; |
| | if (i + 1 < processedLines.length) { |
| | nextIsDownload = downloadPattern.test(processedLines[i + 1]); |
| | } |
| | |
| | if (nextIsDownload) { |
| | continue; |
| | } |
| | } |
| | |
| | else if (tqdmPattern.test(line)) { |
| | |
| | let nextIsTqdm = false; |
| | if (i + 1 < processedLines.length) { |
| | nextIsTqdm = tqdmPattern.test(processedLines[i + 1]); |
| | } |
| | |
| | if (nextIsTqdm) { |
| | continue; |
| | } |
| | } |
| | |
| | finalLines.push(line); |
| | } |
| |
|
| | return finalLines.join('\n'); |
| | } |