From d5430812bc117005a4467ecdc6ce4820daf1ca9a Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Sun, 7 Jun 2020 15:36:07 -0600 Subject: [PATCH] You can run many languages now --- backend/src/api.ts | 11 +++++++++-- backend/src/langs.ts | 10 +++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/backend/src/api.ts b/backend/src/api.ts index c4e4baf..a527732 100644 --- a/backend/src/api.ts +++ b/backend/src/api.ts @@ -58,6 +58,13 @@ export class Session { break; } }; + parseCmdline = (cmdline: string[] | string) => { + if (typeof cmdline === "string") { + return ["bash", "-c", cmdline]; + } else { + return cmdline; + } + }; run = async () => { const { repl, file, run } = this.config; if (this.term) { @@ -84,9 +91,9 @@ export class Session { } }) ); - cmdline = run; + cmdline = this.parseCmdline(run); } else { - cmdline = repl; + cmdline = this.parseCmdline(repl); } this.term = pty.spawn(cmdline[0], cmdline.slice(1), { name: "xterm-color", diff --git a/backend/src/langs.ts b/backend/src/langs.ts index 812ae57..856dc5b 100644 --- a/backend/src/langs.ts +++ b/backend/src/langs.ts @@ -1,7 +1,7 @@ export interface LangConfig { repl?: string[]; file?: string; - run?: string[]; + run?: string[] | string; monacoLang: string; name: string; } @@ -9,6 +9,8 @@ export interface LangConfig { export const langs = { bash: { repl: ["bash"], + file: "main.bash", + run: ["bash", "--rcfile", "main.bash"], name: "Bash", monacoLang: "shell", }, @@ -41,6 +43,8 @@ export const langs = { }, haskell: { repl: ["ghci"], + file: "Main.hs", + run: ["ghci", "Main.hs"], name: "Haskell", monacoLang: "plaintext", }, @@ -60,6 +64,8 @@ export const langs = { }, nodejs: { repl: ["node"], + file: "main.js", + run: 'node -i -e "$(< main.js)"', name: "Node.js", monacoLang: "javascript", }, @@ -86,6 +92,8 @@ export const langs = { }, zsh: { repl: ["env", "SHELL=/usr/bin/zsh", "zsh"], + file: ".zshrc", + run: ["env", "ZDOTDIR=.", "zsh"], name: "Zsh", monacoLang: "shell", },