feat: support multiline console output and decode HTML entities
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+33
-8
@@ -76,12 +76,37 @@ export function detectWarning(logLines) {
|
||||
* @returns {string}
|
||||
*/
|
||||
export function safeDecode(text) {
|
||||
if (typeof text !== "string" || !text.includes("%")) return text;
|
||||
try {
|
||||
return decodeURIComponent(text);
|
||||
} catch (err) {
|
||||
return text;
|
||||
if (typeof text !== "string") return text;
|
||||
let result = text;
|
||||
if (result.includes("%")) {
|
||||
try {
|
||||
result = decodeURIComponent(result);
|
||||
} catch (err) {
|
||||
// Ignore decoding errors
|
||||
}
|
||||
}
|
||||
// Screeps console often contains HTML entities
|
||||
return result
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, '"')
|
||||
.replace(/&/g, "&");
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs text to the action log, splitting by newline to ensure proper display.
|
||||
*
|
||||
* @param {string} text
|
||||
* @param {"info"|"warning"|"error"} level
|
||||
*/
|
||||
export function outputMultiline(text, level = "info") {
|
||||
if (!text) return;
|
||||
const lines = text.split(/\r?\n/);
|
||||
lines.forEach((line) => {
|
||||
if (level === "error") core.error(line);
|
||||
else if (level === "warning") core.warning(line);
|
||||
else core.info(line);
|
||||
});
|
||||
}
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
@@ -185,7 +210,7 @@ export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
|
||||
const warnPattern = /<font\s+color=['"](?:orange|yellow)['"]/i;
|
||||
logLines
|
||||
.filter((l) => warnPattern.test(l))
|
||||
.forEach((l) => core.warning(safeDecode(l)));
|
||||
.forEach((l) => outputMultiline(safeDecode(l), "warning"));
|
||||
}
|
||||
|
||||
// ── Traceback detection in log lines (Screeps sometimes sends errors here) ─
|
||||
@@ -200,7 +225,7 @@ export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
|
||||
if (logToFile) {
|
||||
stdoutBuffer.push(...allStdout);
|
||||
} else {
|
||||
allStdout.forEach((l) => core.info(l));
|
||||
allStdout.forEach((l) => outputMultiline(l, "info"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +233,7 @@ export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
|
||||
if (errorText) {
|
||||
state.sawErrorLog = true;
|
||||
const decodedError = safeDecode(errorText);
|
||||
core.error(decodedError);
|
||||
outputMultiline(decodedError, "error");
|
||||
if (detectTraceback(decodedError)) {
|
||||
state.sawTraceback = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user