@@ -307,26 +307,46 @@ export function initRepositoryActionView() {
307
307
view .mount (el);
308
308
}
309
309
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
+
310
323
export function ansiLogToHTML (line ) {
311
324
if (line .endsWith (' \r\n ' )) {
312
325
line = line .substring (0 , line .length - 2 );
313
326
} else if (line .endsWith (' \n ' )) {
314
327
line = line .substring (0 , line .length - 1 );
315
328
}
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
+
316
334
if (! line .includes (' \r ' )) {
317
335
return ansiLogRender .toHtml (line);
318
336
}
319
337
320
338
// handle "\rReading...1%\rReading...5%\rReading...100%",
321
339
// 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[".
323
340
const lines = [];
324
341
for (const part of line .split (' \r ' )) {
325
342
if (part === ' ' ) continue ;
326
- lines .push (part);
343
+ const partHtml = ansiLogRender .toHtml (part);
344
+ if (partHtml !== ' ' ) {
345
+ lines .push (partHtml);
346
+ }
327
347
}
328
348
// 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 ' );
330
350
}
331
351
332
352
< / script>
0 commit comments