package main import ( "log" "net/http" "html/template" //"time" ) type Python struct { Program string } func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { log.Printf("new request") t := template.New("page") t, _ = t.Parse(webpage) p := Python{Program: pythonProgram} t.Execute(w, p) }) log.Printf("Running on port 9000") http.ListenAndServe(":9000", nil) } var pythonProgram = `for i in range(1,4): print "hello world", i print [i*i for i in range(30)] foo = "a horse is a horse, of course, of course" print foo.split() print [x*x for x in range(10)]` var webpage = `<!doctype html><html> <style> body { background-color: #000011; margin: 0px; overflow: hidden; color: white; } footer { width: 175px; height: 1.5em; position: fixed; bottom: 0; right: 0; padding: 3px 5px 5px 5px; text-align: left; z-index: 200; background-repeat: no-repeat; background-image: url("https://ds604.neocities.org/DavidSarmaDotOrg_h12.png");} #editor { position: absolute; top: 2.5em; right: 0; bottom: 0; left: 0;} .dont-break-out { overflow: hidden; text-overflow: ellipsis; } /*canvas { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 100vw; height: 100vh }*/ </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.5/ace.js" type="text/javascript" charset="utf-8"></script> <script src="http://www.skulpt.org/static/skulpt.min.js" type="text/javascript"></script> <script src="http://www.skulpt.org/static/skulpt-stdlib.js" type="text/javascript"></script> <body onload="runit()" onkeyup="runit()"> <footer></footer> <div id="editor"> {{.Program}} </div> <button type="button" onclick="runit()" style="visibility: visible; position: fixed; top: 0.5em; left: 1em; z-index:200">Run</button> <pre id="output" class="dont-break-out" style="visibility: visible; position: fixed; z-index: 100; right: 5em; top: 2em; width: auto; max-width: 500px; padding: 1em; background-color: #222222; opacity: 0.75; border-radius: 1em"></pre> <script> //setup editor var editor = ace.edit("editor"); editor.setTheme("ace/theme/monokai"); editor.setShowPrintMargin(false); editor.getSession().setMode("ace/mode/python"); //Add in the Python interpreter function outf(text) { var mypre = document.getElementById("output"); //var mypre = myCodeMirror.getValue(); mypre.innerText = mypre.innerText + text; console.log(text); } function builtinRead(x) { if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined) throw "File not found: '" + x + "'"; return Sk.builtinFiles["files"][x]; } function runit() { var prog = editor.getValue(); var mypre = document.getElementById("output"); mypre.innerHTML = ''; Sk.pre = "output"; Sk.configure({output:outf, read:builtinRead}); (Sk.TurtleGraphics || (Sk.TurtleGraphics = {})).target = 'mycanvas'; var myPromise = Sk.misceval.asyncToPromise(function() { return Sk.importMainWithBody("<stdin>", false, prog, true); }); myPromise.then(function(mod) { //console.log('success'); }, function(err) { console.log(err.toString()); }); } </script> </body></html>`