Templates, and C works now
This commit is contained in:
parent
869816c6ab
commit
2b8e0fd217
|
@ -24,6 +24,14 @@ export class Session {
|
||||||
monacoLanguage: this.config.monacoLang,
|
monacoLanguage: this.config.monacoLang,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
if (this.config.template) {
|
||||||
|
this.ws.send(
|
||||||
|
JSON.stringify({
|
||||||
|
event: "insertTemplate",
|
||||||
|
template: this.config.template,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
this.run().catch(console.error);
|
this.run().catch(console.error);
|
||||||
ws.on("message", this.handleClientMessage);
|
ws.on("message", this.handleClientMessage);
|
||||||
}
|
}
|
||||||
|
@ -58,15 +66,8 @@ export class Session {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
parseCmdline = (cmdline: string[] | string) => {
|
|
||||||
if (typeof cmdline === "string") {
|
|
||||||
return ["bash", "-c", cmdline];
|
|
||||||
} else {
|
|
||||||
return cmdline;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
run = async () => {
|
run = async () => {
|
||||||
const { repl, file, suffix, run } = this.config;
|
const { repl, file, suffix, compile, run } = this.config;
|
||||||
if (this.term.pty) {
|
if (this.term.pty) {
|
||||||
this.term.pty.kill();
|
this.term.pty.kill();
|
||||||
this.term.live = false;
|
this.term.live = false;
|
||||||
|
@ -81,8 +82,10 @@ export class Session {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
let cmdline: string[];
|
let cmdline: string;
|
||||||
if (this.code || !repl) {
|
if (!run) {
|
||||||
|
cmdline = `echo 'Support for ${this.config.name} is not yet implemented.`;
|
||||||
|
} else if (this.code) {
|
||||||
let code = this.code;
|
let code = this.code;
|
||||||
if (suffix) {
|
if (suffix) {
|
||||||
code += suffix;
|
code += suffix;
|
||||||
|
@ -96,12 +99,17 @@ export class Session {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
cmdline = this.parseCmdline(run);
|
cmdline = run;
|
||||||
|
if (compile) {
|
||||||
|
cmdline = compile + " && " + run;
|
||||||
|
}
|
||||||
|
} else if (repl) {
|
||||||
|
cmdline = repl;
|
||||||
} else {
|
} else {
|
||||||
cmdline = this.parseCmdline(repl);
|
return;
|
||||||
}
|
}
|
||||||
const term = {
|
const term = {
|
||||||
pty: pty.spawn(cmdline[0], cmdline.slice(1), {
|
pty: pty.spawn("bash", ["-c", cmdline], {
|
||||||
name: "xterm-color",
|
name: "xterm-color",
|
||||||
cwd: tmpdir,
|
cwd: tmpdir,
|
||||||
env: process.env,
|
env: process.env,
|
||||||
|
|
|
@ -1,103 +1,116 @@
|
||||||
export interface LangConfig {
|
export interface LangConfig {
|
||||||
repl?: string[];
|
name: string;
|
||||||
|
monacoLang: string;
|
||||||
|
repl?: string;
|
||||||
file?: string;
|
file?: string;
|
||||||
prefix?: string;
|
prefix?: string;
|
||||||
suffix?: string;
|
suffix?: string;
|
||||||
run?: string[] | string;
|
compile?: string;
|
||||||
monacoLang: string;
|
run?: string;
|
||||||
name: string;
|
template?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const langs = {
|
export const langs: { [key: string]: LangConfig } = {
|
||||||
bash: {
|
bash: {
|
||||||
repl: ["bash"],
|
|
||||||
file: "main.bash",
|
|
||||||
run: ["bash", "--rcfile", "main.bash"],
|
|
||||||
name: "Bash",
|
name: "Bash",
|
||||||
monacoLang: "shell",
|
monacoLang: "shell",
|
||||||
|
repl: "bash",
|
||||||
|
file: "main.bash",
|
||||||
|
run: "bash --rcfile main.bash",
|
||||||
|
template: 'echo "Hello, world!"',
|
||||||
},
|
},
|
||||||
c: {
|
c: {
|
||||||
name: "C",
|
name: "C",
|
||||||
monacoLang: "c",
|
monacoLang: "c",
|
||||||
|
file: "main.c",
|
||||||
|
compile: "clang -Wall -Wextra main.c -o main",
|
||||||
|
run: "./main",
|
||||||
|
template: `#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
printf("Hello, world!\\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
`,
|
||||||
},
|
},
|
||||||
"c++": {
|
"c++": {
|
||||||
name: "C++",
|
name: "C++",
|
||||||
monacoLang: "cpp",
|
monacoLang: "cpp",
|
||||||
},
|
},
|
||||||
clojure: {
|
clojure: {
|
||||||
repl: ["clojure"],
|
|
||||||
name: "Clojure",
|
name: "Clojure",
|
||||||
monacoLang: "clojure",
|
monacoLang: "clojure",
|
||||||
|
repl: "clojure",
|
||||||
},
|
},
|
||||||
emacs: {
|
emacs: {
|
||||||
repl: ["emacs"],
|
|
||||||
name: "Emacs Lisp",
|
name: "Emacs Lisp",
|
||||||
monacoLang: "plaintext",
|
monacoLang: "plaintext",
|
||||||
|
repl: "emacs",
|
||||||
},
|
},
|
||||||
fish: {
|
fish: {
|
||||||
repl: ["env", "SHELL=/usr/bin/fish", "fish"],
|
|
||||||
name: "Fish",
|
name: "Fish",
|
||||||
monacoLang: "plaintext",
|
monacoLang: "plaintext",
|
||||||
|
repl: "SHELL=/usr/bin/fish fish",
|
||||||
},
|
},
|
||||||
go: {
|
go: {
|
||||||
name: "Go",
|
name: "Go",
|
||||||
monacoLang: "go",
|
monacoLang: "go",
|
||||||
},
|
},
|
||||||
haskell: {
|
haskell: {
|
||||||
repl: ["ghci"],
|
|
||||||
file: "Main.hs",
|
|
||||||
run: ["ghci", "Main.hs"],
|
|
||||||
name: "Haskell",
|
name: "Haskell",
|
||||||
monacoLang: "plaintext",
|
monacoLang: "plaintext",
|
||||||
|
repl: "ghci",
|
||||||
|
file: "Main.hs",
|
||||||
|
run: "ghci Main.hs",
|
||||||
},
|
},
|
||||||
java: {
|
java: {
|
||||||
name: "Java",
|
name: "Java",
|
||||||
monacoLang: "java",
|
monacoLang: "java",
|
||||||
},
|
},
|
||||||
julia: {
|
julia: {
|
||||||
repl: ["julia"],
|
|
||||||
name: "Julia",
|
name: "Julia",
|
||||||
monacoLang: "plaintext",
|
monacoLang: "plaintext",
|
||||||
|
repl: "julia",
|
||||||
},
|
},
|
||||||
lua: {
|
lua: {
|
||||||
repl: ["lua"],
|
|
||||||
name: "Lua",
|
name: "Lua",
|
||||||
monacoLang: "lua",
|
monacoLang: "lua",
|
||||||
|
repl: "lua",
|
||||||
},
|
},
|
||||||
nodejs: {
|
nodejs: {
|
||||||
repl: ["node"],
|
name: "Node.js",
|
||||||
|
monacoLang: "javascript",
|
||||||
|
repl: "node",
|
||||||
file: "main.js",
|
file: "main.js",
|
||||||
suffix: '\n;require("repl").start();',
|
suffix: '\n;require("repl").start();',
|
||||||
run: "node main.js",
|
run: "node main.js",
|
||||||
name: "Node.js",
|
|
||||||
monacoLang: "javascript",
|
|
||||||
},
|
},
|
||||||
python: {
|
python: {
|
||||||
repl: ["python3", "-u"],
|
|
||||||
file: "main.py",
|
|
||||||
run: ["python3", "-u", "-i", "main.py"],
|
|
||||||
name: "Python",
|
name: "Python",
|
||||||
monacoLang: "python",
|
monacoLang: "python",
|
||||||
|
repl: "python3 -u",
|
||||||
|
file: "main.py",
|
||||||
|
run: "python3 -u -i main.py",
|
||||||
},
|
},
|
||||||
ruby: {
|
ruby: {
|
||||||
repl: ["irb"],
|
|
||||||
name: "Ruby",
|
name: "Ruby",
|
||||||
monacoLang: "ruby",
|
monacoLang: "ruby",
|
||||||
|
repl: "irb",
|
||||||
},
|
},
|
||||||
rust: {
|
rust: {
|
||||||
name: "Rust",
|
name: "Rust",
|
||||||
monacoLang: "rust",
|
monacoLang: "rust",
|
||||||
},
|
},
|
||||||
vim: {
|
vim: {
|
||||||
repl: ["vim"],
|
|
||||||
name: "Vimscript",
|
name: "Vimscript",
|
||||||
monacoLang: "plaintext",
|
monacoLang: "plaintext",
|
||||||
|
repl: "vim",
|
||||||
},
|
},
|
||||||
zsh: {
|
zsh: {
|
||||||
repl: ["env", "SHELL=/usr/bin/zsh", "zsh"],
|
|
||||||
file: ".zshrc",
|
|
||||||
run: ["env", "ZDOTDIR=.", "zsh"],
|
|
||||||
name: "Zsh",
|
name: "Zsh",
|
||||||
monacoLang: "shell",
|
monacoLang: "shell",
|
||||||
|
repl: "SHELL=/usr/bin/zsh zsh",
|
||||||
|
file: ".zshrc",
|
||||||
|
run: "ZDOTDIR=. zsh",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,6 +17,8 @@ window.addEventListener("resize", () => fitAddon.fit());
|
||||||
const initialRetryDelayMs = 200;
|
const initialRetryDelayMs = 200;
|
||||||
let retryDelayMs = initialRetryDelayMs;
|
let retryDelayMs = initialRetryDelayMs;
|
||||||
|
|
||||||
|
let allowInsertingTemplate = true;
|
||||||
|
|
||||||
function tryConnect() {
|
function tryConnect() {
|
||||||
console.log("Connecting to server...");
|
console.log("Connecting to server...");
|
||||||
socket = new WebSocket(
|
socket = new WebSocket(
|
||||||
|
@ -57,6 +59,15 @@ function tryConnect() {
|
||||||
message.monacoLanguage
|
message.monacoLanguage
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
case "insertTemplate":
|
||||||
|
if (typeof message.template !== "string") {
|
||||||
|
console.error("Unexpected message from server:", message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (allowInsertingTemplate) {
|
||||||
|
editor.getModel().setValue(message.template);
|
||||||
|
}
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
console.error("Unexpected message from server:", message);
|
console.error("Unexpected message from server:", message);
|
||||||
return;
|
return;
|
||||||
|
@ -91,6 +102,9 @@ const editor = monaco.editor.create(document.getElementById("editor"), {
|
||||||
scrollbar: { verticalScrollbarSize: 0 },
|
scrollbar: { verticalScrollbarSize: 0 },
|
||||||
});
|
});
|
||||||
window.addEventListener("resize", () => editor.layout());
|
window.addEventListener("resize", () => editor.layout());
|
||||||
|
editor.onDidChangeModelContent(() => {
|
||||||
|
allowInsertingTemplate = false;
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("runButton").addEventListener("click", () => {
|
document.getElementById("runButton").addEventListener("click", () => {
|
||||||
socket.send(JSON.stringify({ event: "runCode", code: editor.getValue() }));
|
socket.send(JSON.stringify({ event: "runCode", code: editor.getValue() }));
|
||||||
|
|
|
@ -38,6 +38,7 @@ bsdmainutils
|
||||||
curl
|
curl
|
||||||
emacs-nox
|
emacs-nox
|
||||||
git
|
git
|
||||||
|
lsof
|
||||||
make
|
make
|
||||||
man-db
|
man-db
|
||||||
nano
|
nano
|
||||||
|
|
Loading…
Reference in New Issue