Initial commit
This commit is contained in:
		
							
								
								
									
										16
									
								
								client/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								client/index.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| <!DOCTYPE html> | ||||
| <html> | ||||
|   <head> | ||||
|     <title>gride</title> | ||||
|     <script src="index.js"></script> | ||||
|     <style> | ||||
|       p { | ||||
|         line-height: 0.3; | ||||
|       } | ||||
|     </style> | ||||
|   </head> | ||||
|   <body> | ||||
|     <button onclick="runCode()">Run</button> | ||||
|     <code id="editor"></code> | ||||
|   </body> | ||||
| </html> | ||||
							
								
								
									
										37
									
								
								client/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								client/index.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| let textbox; | ||||
| let text = '<p># welcome to gride!</p>\n<p># start typing to code a program in Ground!</p>\n<p>'; | ||||
|  | ||||
| // Wait for the window to load before doing anything | ||||
| window.addEventListener("load", function() { | ||||
|   textbox = document.getElementById("editor"); | ||||
|   textbox.innerHTML = text + "</p>"; | ||||
| }); | ||||
|  | ||||
| // When we press a key, start doing stuff | ||||
| onkeydown = (event) => { | ||||
|   if (event.key == "Enter") { | ||||
|     text += "</p>\n<p>"; | ||||
|   } else if (event.key == "Tab") { | ||||
|     text += "    "; | ||||
|   } else if (event.key == "Backspace") { | ||||
|     if (text.slice(-8) == "</p>\n<p>") { | ||||
|       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 + "</p>"; | ||||
| } | ||||
|  | ||||
| async function runCode() { | ||||
|   console.log(text.split("<p>").join("").split("</p>").join("")); | ||||
|   const result = await fetch("http://localhost:5000/runProgram", { | ||||
|     "method": "POST", | ||||
|     //"mode": "no-cors", | ||||
|     "body": text.split("<p>").join("").split("</p>").join("") | ||||
|   }); | ||||
|   const data = await result.json(); | ||||
|   console.log("Output: ", data); | ||||
| } | ||||
							
								
								
									
										1
									
								
								server/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								server/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| __pycache__ | ||||
							
								
								
									
										19
									
								
								server/app.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								server/app.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| from flask import Flask, request, jsonify, send_from_directory | ||||
| import subprocess | ||||
| import random | ||||
|  | ||||
| app = Flask(__name__) | ||||
|  | ||||
| @app.route("/<path:path>") | ||||
| 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}) | ||||
|      | ||||
							
								
								
									
										1
									
								
								server/static
									
									
									
									
									
										Symbolic link
									
								
							
							
						
						
									
										1
									
								
								server/static
									
									
									
									
									
										Symbolic link
									
								
							| @@ -0,0 +1 @@ | ||||
| ../client | ||||
		Reference in New Issue
	
	Block a user