@@ -77,6 +77,8 @@ import AnsiToHTML from 'ansi-to-html';
77
77
78
78
const {csrfToken } = window .config ;
79
79
80
+ const ansiLogRender = new AnsiToHTML ({escapeXML: true });
81
+
80
82
const sfc = {
81
83
name: ' RepoActionView' ,
82
84
components: {
@@ -91,8 +93,6 @@ const sfc = {
91
93
92
94
data () {
93
95
return {
94
- ansiToHTML: new AnsiToHTML ({escapeXML: true }),
95
-
96
96
// internal state
97
97
loading: false ,
98
98
intervalID: null ,
@@ -214,7 +214,7 @@ const sfc = {
214
214
215
215
const logMessage = document .createElement (' div' );
216
216
logMessage .className = ' log-msg' ;
217
- logMessage .innerHTML = this . ansiToHTML . toHtml ( processConsoleLine ( line .message ) );
217
+ logMessage .innerHTML = ansiLogToHTML ( line .message );
218
218
div .appendChild (logMessage);
219
219
220
220
return div;
@@ -307,27 +307,28 @@ export function initRepositoryActionView() {
307
307
view .mount (el);
308
308
}
309
309
310
- export function processConsoleLine (line ) {
310
+ export function ansiLogToHTML (line ) {
311
311
if (line .endsWith (' \r\n ' )) {
312
312
line = line .substring (0 , line .length - 2 );
313
313
} else if (line .endsWith (' \n ' )) {
314
314
line = line .substring (0 , line .length - 1 );
315
315
}
316
- if (! line .includes (' \r ' )) return line;
317
-
318
- // handle "\rReading...1%\rReading...5%\rReading...100%", only show the final message
319
- // TODO: control chars like "\033[" ?
320
- const parts = line .split (' \r ' );
321
- let result = ' ' ;
322
- for (const part of parts) {
323
- if (part .length >= result .length ) {
324
- result = part;
325
- } else {
326
- result = part + result .substring (part .length );
327
- }
316
+ if (! line .includes (' \r ' )) {
317
+ return ansiLogRender .toHtml (line);
328
318
}
329
- return result;
319
+
320
+ // handle "\rReading...1%\rReading...5%\rReading...100%",
321
+ // 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
+ const lines = [];
324
+ for (const part of line .split (' \r ' )) {
325
+ if (part === ' ' ) continue ;
326
+ lines .push (part);
327
+ }
328
+ // the log message element is with "white-space: break-spaces;", so use "\n" to break lines
329
+ return ansiLogRender .toHtml (lines .join (' \n ' ));
330
330
}
331
+
331
332
< / script>
332
333
333
334
< style scoped>
0 commit comments