Commit 2e8e5a32 authored by Konrad Borowski's avatar Konrad Borowski

Support user provided STDIN

parent bb08c171
Pipeline #98072114 passed with stages
in 16 minutes and 36 seconds
......@@ -12,6 +12,8 @@ class Editor {
autodeleteText: HTMLSpanElement
autodeleteCheckbox: HTMLLabelElement
submit: HTMLInputElement
detailsElement: HTMLDetailsElement
stdinElement: HTMLTextAreaElement
editor: EditorType
currentLanguage: string | null = null
abortEval: AbortController | null = null
......@@ -28,6 +30,13 @@ class Editor {
this.autodeleteCheckbox = form.querySelector('#automatically-hidden-label')
this.submit = form.querySelector('[type=submit]')
this.submit.disabled = true
this.detailsElement = document.createElement('details')
const summary = document.createElement('summary')
summary.textContent = 'Standard input'
this.stdinElement = document.createElement('textarea')
this.detailsElement.append(summary, this.stdinElement)
this.detailsElement.style.display = 'none'
form.querySelector('#buttons').append(this.detailsElement)
if (this.autodeleteText) {
this.autodeleteCheckbox.style.display = 'none'
}
......@@ -79,6 +88,7 @@ class Editor {
const language = await getLanguage(identifier, isStillValid)
// This deals with user changing the language after asynchronous event
if (isStillValid()) {
this.detailsElement.style.display = language.implementations.length ? 'block' : 'none'
this.wrapperButtons.update(language.implementations)
}
}
......@@ -96,6 +106,7 @@ class Editor {
const body = new URLSearchParams
body.append('compilerOptions', compilerOptions)
body.append('code', this.editor.getValue())
body.append('stdin', this.stdinElement.value)
const parameters = {
method: 'POST',
body,
......
......@@ -20,12 +20,13 @@ lazy_static! {
pub struct Form {
code: String,
compiler_options: String,
stdin: String,
}
#[derive(Serialize)]
struct Request {
files: Vec<File>,
stdin: &'static str,
stdin: String,
code: String,
}
......@@ -48,6 +49,7 @@ pub fn run(
Form {
code,
compiler_options,
stdin,
}: Form,
) -> impl Future<Item = impl Reply, Error = Rejection> {
blocking::run(move || {
......@@ -68,7 +70,7 @@ pub fn run(
name: "code",
contents: code,
}],
stdin: "",
stdin,
code: language_code.replace("%s", &compiler_options),
})
.send()
......
......@@ -45,9 +45,10 @@ h1, h2, h3, h4, h5, h6 {
textarea {
width: 100%;
height: 372px;
resize: vertical;
}
#buttons {
text-align: right;
#right-buttons {
float: right;
}
table {
overflow: auto;
......
@()
<p id="buttons">
<span id="wrapper-buttons"></span>
<input type=submit value=Share>
<div id="buttons">
<div id="right-buttons">
<span id="wrapper-buttons"></span>
<input type=submit value=Share>
</div>
</div>
<div id="output"></div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment