aboutsummaryrefslogtreecommitdiff
path: root/clojurescript/repl.html
blob: cae8a11932b13bc2550f81e020bd7b2c9d00d05d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<html>
  <body>
    <textarea rows="24" cols="80" id="ta"></textarea><br />
    <span style="font-family: monospace">user=&gt;</span>
    <textarea id="text" rows="6" cols="80"
      style="vertical-align: top"></textarea>
    <div id="status"></div>
    <!--
    <form onsubmit="jsrepl.runtest(); return false">
      <select id="t">
        <option>t01.js</option>
        <option>t02.js</option>
        <option>t03.js</option>
        <option>t04.js</option>
        <option>t05.js</option>
        <option>t06.js</option>
      </select>
      <input type="submit" value="Run test" />
    </form>
    -->
    <script type="text/javascript">
      jsrepl = {
        ta: document.getElementById( 'ta' ),
        t: document.getElementById( 't' ),
        text: document.getElementById( 'text' ),
        status: document.getElementById( 'status' ),
        runtest: function() {
          var s = document.createElement('script');
          s.src = jsrepl.t.value;
          document.body.appendChild( s );
        },
        posttext: function() {
          var text = jsrepl.text.value.replace(/\n$/,"");
          print( "user=> " + text.replace(/\n/g,"\n       "));
          jsrepl.text.value = "";
        },
        err: function(e) {
          print(e);
          clojure._var__STAR_e.set(e);
        },
        state: function(s,m) {
          jsrepl.status.innerHTML = s;
          switch( s ) {
            case 'error':
              jsrepl.posttext();
              print( m );
              break;
            case 'compiled':
              jsrepl.posttext();
              break;
          }
          jsrepl.ta.scrollTop = jsrepl.ta.scrollHeight;
        }
      };
      jsrepl.text.onkeypress = function(e) {
        e = e || event;
        if( e.keyCode == 13 ) {
          var s = document.createElement('script');
          s.src = "http://localhost:8081/" +
            escape(jsrepl.text.value).replace(/\+/,'%2b');
          document.body.appendChild( s );
        }
      };
      function print( x ) { jsrepl.ta.value += x + "\n"; }
    </script>
    <script type="text/javascript" src="clj.js"></script>
    <script type="text/javascript" src="boot.js"></script>
  </body>
</html>