Skip to content

Commit 5a17ef1

Browse files
committed
parse new comfy log color outputs
1 parent afb6987 commit 5a17ef1

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/wwwroot/js/genpage/server/logs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ServerLogsHelper {
7979
}
8080

8181
htmlMessage(msg, type, bounceId) {
82-
return `<div class="log_message log_message_${bounceId}"><span class="log_message_prefix">${msg.time} [<span style="color:${type.color}">${type.name}</span>]</span> ${escapeHtmlNoBr(msg.message)}</div>`;
82+
return `<div class="log_message log_message_${bounceId}"><span class="log_message_prefix">${msg.time} [<span style="color:${type.color}">${type.name}</span>]</span> ${ansiHtml(escapeHtmlNoBr(msg.message))}</div>`;
8383
}
8484

8585
getVisibleTypes() {

src/wwwroot/js/util.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,3 +1224,48 @@ function trimEndSpaces(text) {
12241224
function trimSpaces(text) {
12251225
return trimStartSpaces(trimEndSpaces(text));
12261226
}
1227+
1228+
/** Converts basic ANSI foreground color codes in already HTML-escaped text to colored spans. */
1229+
function ansiHtml(text) {
1230+
let colors = { '30': '#000000', '31': '#cd3131', '32': '#0dbc79', '33': '#e5e510', '34': '#2472c8', '35': '#bc3fbc', '36': '#11a8cd', '37': '#e5e5e5', '90': '#666666', '91': '#f14c4c', '92': '#23d18b', '93': '#f5f543', '94': '#3b8eea', '95': '#d670d6', '96': '#29b8db', '97': '#ffffff' };
1231+
let result = '';
1232+
let currentColor = null;
1233+
let i = 0;
1234+
while (i < text.length) {
1235+
if (text.charCodeAt(i) == 27 && text[i + 1] == '[') {
1236+
let j = i + 2;
1237+
while (j < text.length && text[j] != 'm') {
1238+
j++;
1239+
}
1240+
if (j < text.length) {
1241+
let codes = text.substring(i + 2, j).split(';');
1242+
let newColor = currentColor;
1243+
for (let code of codes) {
1244+
if (code == '' || code == '0') {
1245+
newColor = null;
1246+
}
1247+
else if (colors[code]) {
1248+
newColor = colors[code];
1249+
}
1250+
}
1251+
if (newColor != currentColor) {
1252+
if (currentColor != null) {
1253+
result += '</span>';
1254+
}
1255+
if (newColor != null) {
1256+
result += `<span style="color:${newColor}">`;
1257+
}
1258+
currentColor = newColor;
1259+
}
1260+
i = j + 1;
1261+
continue;
1262+
}
1263+
}
1264+
result += text[i];
1265+
i++;
1266+
}
1267+
if (currentColor != null) {
1268+
result += '</span>';
1269+
}
1270+
return result;
1271+
}

0 commit comments

Comments
 (0)