@@ -307,26 +307,46 @@ export function initRepositoryActionView() {
307307 view .mount (el);
308308}
309309
310+ // some unhandled control sequences by AnsiToHTML
311+ // https://man7.org/linux/man-pages/man4/console_codes.4.html
312+ const ansiRegexpRemove = / \x1b \[ \d [A-H ] / g ; // Move cursor, treat them as a no-op.
313+ const ansiRegexpNewLine = / \x1b \[ \d [JK] / g ; // Erase display/line, treat them as a Carrige Return
314+
315+ function ansiCleanControlSequences (line ) {
316+ if (line .includes (' \x1b ' )) {
317+ line = line .replace (ansiRegexpRemove, ' ' );
318+ line = line .replace (ansiRegexpNewLine, ' \r ' );
319+ }
320+ return line;
321+ }
322+
310323export function ansiLogToHTML (line ) {
311324 if (line .endsWith (' \r\n ' )) {
312325 line = line .substring (0 , line .length - 2 );
313326 } else if (line .endsWith (' \n ' )) {
314327 line = line .substring (0 , line .length - 1 );
315328 }
329+
330+ // usually we do not need to process control chars like "\033[", let AnsiToHTML do it
331+ // but AnsiToHTML has bugs, so we need to clean some control sequences first
332+ line = ansiCleanControlSequences (line);
333+
316334 if (! line .includes (' \r ' )) {
317335 return ansiLogRender .toHtml (line);
318336 }
319337
320338 // handle "\rReading...1%\rReading...5%\rReading...100%",
321339 // convert it into a multiple-line string: "Reading...1%\nReading...5%\nReading...100%"
322- // then we do not need to process control chars like "\033[".
323340 const lines = [];
324341 for (const part of line .split (' \r ' )) {
325342 if (part === ' ' ) continue ;
326- lines .push (part);
343+ const partHtml = ansiLogRender .toHtml (part);
344+ if (partHtml !== ' ' ) {
345+ lines .push (partHtml);
346+ }
327347 }
328348 // the log message element is with "white-space: break-spaces;", so use "\n" to break lines
329- return ansiLogRender . toHtml ( lines .join (' \n ' ) );
349+ return lines .join (' \n ' );
330350}
331351
332352< / script>
0 commit comments