From 37205bf33a068aafa3d139d4d8629c920683283c Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Thu, 25 Sep 2025 22:16:05 +1000 Subject: [PATCH] Initial commit --- client/index.html | 16 ++++++++++++++++ client/index.js | 37 +++++++++++++++++++++++++++++++++++++ server/.gitignore | 1 + server/app.py | 19 +++++++++++++++++++ server/static | 1 + 5 files changed, 74 insertions(+) create mode 100644 client/index.html create mode 100644 client/index.js create mode 100644 server/.gitignore create mode 100644 server/app.py create mode 120000 server/static diff --git a/client/index.html b/client/index.html new file mode 100644 index 0000000..c3ef083 --- /dev/null +++ b/client/index.html @@ -0,0 +1,16 @@ + + + + gride + + + + + + + + diff --git a/client/index.js b/client/index.js new file mode 100644 index 0000000..b5aea78 --- /dev/null +++ b/client/index.js @@ -0,0 +1,37 @@ +let textbox; +let text = '

# welcome to gride!

\n

# start typing to code a program in Ground!

\n

'; + +// Wait for the window to load before doing anything +window.addEventListener("load", function() { + textbox = document.getElementById("editor"); + textbox.innerHTML = text + "

"; +}); + +// When we press a key, start doing stuff +onkeydown = (event) => { + if (event.key == "Enter") { + text += "

\n

"; + } else if (event.key == "Tab") { + text += " "; + } else if (event.key == "Backspace") { + if (text.slice(-8) == "

\n

") { + text = text.slice(0, -8) + } else { + text = text.slice(0, -1) + } + } else if (!(event.key == "Control" || event.key == "Alt" || event.key == "Meta" || event.key == "Shift" || event.key == "Escape")) { + text += event.key; + } + textbox.innerHTML = text + "

"; +} + +async function runCode() { + console.log(text.split("

").join("").split("

").join("")); + const result = await fetch("http://localhost:5000/runProgram", { + "method": "POST", + //"mode": "no-cors", + "body": text.split("

").join("").split("

").join("") + }); + const data = await result.json(); + console.log("Output: ", data); +} diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/server/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/server/app.py b/server/app.py new file mode 100644 index 0000000..94d3a3b --- /dev/null +++ b/server/app.py @@ -0,0 +1,19 @@ +from flask import Flask, request, jsonify, send_from_directory +import subprocess +import random + +app = Flask(__name__) + +@app.route("/") +def get_site(path): + return send_from_directory('static', path) + +@app.post('/runProgram') +def run_program(): + filename = "/tmp/program-" + str(random.randint(0,10000)) + ".grnd" + print(request.get_data(as_text=True)) + with open(filename, "wt") as file: + file.write(request.get_data(as_text=True).replace("\\n", "\n")) + result = subprocess.run(["ground", filename], capture_output = True, text = True) + return jsonify({"stdout": result.stdout, "stderr": result.stderr, "exitCode": result.returncode}) + diff --git a/server/static b/server/static new file mode 120000 index 0000000..5da93f4 --- /dev/null +++ b/server/static @@ -0,0 +1 @@ +../client \ No newline at end of file