skulpttest

Online python editor/interpretor tests
git clone git://git.vgx.fr/skulpttest
Log | Files | Refs

linetest.html (2317B)


      1 <head>
      2     <meta charset="UTF-8">
      3     <script src="lib/codemirror.js"></script>
      4     <link rel="stylesheet" href="lib/codemirror.css">
      5     <script src="lib/mode/python/python.js"></script>
      6     <script src="lib/skulpt.min.js"></script>
      7     <script src="lib/skulpt-stdlib.js"></script>
      8 
      9     <style>
     10         .debug {
     11             width: .8em;
     12         }
     13     </style>
     14     
     15 </head>
     16 <body>
     17 <textarea id="yourcode" cols="40" rows="10">print("Hello World")
     18 </textarea><br /> 
     19 <button type="button" onclick="runit()">Run</button>
     20 <button type="button" onclick="cont()">Continue</button>
     21 <button type="button" onclick="stop()">Stop</button>
     22 
     23 <script type="text/javascript"> 
     24 Sk.configure({
     25   debugging: true
     26 });
     27 
     28 myCodeMirror = CodeMirror.fromTextArea(
     29     document.getElementById("yourcode"),
     30     {
     31       mode: "python",
     32       lineNumbers: true,
     33       gutters: ["CodeMirror-linenumbers", "debug"]
     34     });
     35 
     36 cont = function(){};
     37 stop = function(){};
     38 
     39 dbgLine = -1;
     40 
     41 function handler(susp) {
     42   return new Promise(function(resolve, reject) {
     43 
     44     console.log("File:" +  susp.child.$filename + ", line: " + susp.child.$lineno);
     45     console.log(susp.child.$gbl)
     46 
     47     var line = susp.child.$lineno-1;
     48 
     49     if (susp.child.$filename == "<stdin>.py" && line != dbgLine) {
     50       if (dbgLine != -1) myCodeMirror.setGutterMarker(dbgLine, "debug", null);
     51       dbgLine = line;
     52       myCodeMirror.setGutterMarker(dbgLine, "debug", document.createTextNode("⮞"));
     53     }
     54     cont = function () { 
     55         try {
     56           //cont = function () {resolve(susp.resume());};
     57           resolve(susp.resume());
     58         } catch(e) {
     59           console.log(e);
     60           reject(e);
     61         }
     62     }
     63   });
     64 }
     65 
     66 function runit() {
     67 
     68 //   Sk.importMainWithBody("<stdin>", false, myCodeMirror.getValue(), true);
     69 //   var prog = document.getElementById("yourcode").value;
     70    var prog = myCodeMirror.getValue();
     71    var myPromise = Sk.misceval.asyncToPromise(function() {
     72        return Sk.importMainWithBody("<stdin>", false, prog, true);
     73    },
     74    {"Sk.debug": handler }
     75    );
     76    
     77    myPromise.then(function(mod) {
     78        console.log('success');
     79        reset();
     80    },
     81        function(err) {
     82        console.log(err.toString());
     83        reset();
     84    });
     85 }
     86 
     87 function reset() {
     88   myCodeMirror.setGutterMarker(dbgLine, "debug", null);
     89   dbgLine = -1;
     90 }
     91 
     92 </script> 
     93 
     94 </body>