(feat) make the "Command exited with code X" red if the code is not 0

This commit is contained in:
b1ek 2024-02-18 01:00:01 +10:00
parent 2521075aef
commit b390f74431
Signed by: blek
GPG Key ID: 14546221E3595D0C
3 changed files with 11 additions and 4 deletions

View File

@ -39,13 +39,20 @@ async fn executor(_state: SharedState, data: ExecutorData) -> Result<Box<dyn Rep
.spawn()
.unwrap();
let exit_status = out.wait().unwrap();
let exit_status = out.wait().unwrap().code().unwrap();
let mut buf = vec![];
out.stdout.unwrap().read_to_end(&mut buf).unwrap();
let mut stdout = String::from_utf8(buf).unwrap();
stdout += format!("\n---\nCommand exited with code {}", exit_status.code().unwrap()).as_str();
stdout += "\n---\n";
if exit_status != 0 {
stdout += format!("<span style='color:red;font-weight:bolder'>Command exited with code {}</span>", exit_status).as_str();
} else {
stdout += "Command exited with code 0";
}
let stdout = stdout.replace('\n', "<br>");
Ok(Box::new(warp::reply::json(&stdout)))
}

View File

@ -13,5 +13,5 @@ async function executeCode(code, lang) {
}
)
const out = await data.json();
document.getElementById('output').value = out;
document.getElementById('output').innerHTML = out;
}

View File

@ -34,7 +34,7 @@
</button>
</div>
<div id='container'></div>
<textarea id="output" readonly></textarea>
<pre id="output" readonly></pre>
{% endblock %}
{% block script %}