aboutsummaryrefslogtreecommitdiff
path: root/mal.html
blob: 45e6dc336da509c2f3e6a99a4f840f6bba8c0aaa (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
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <link rel="stylesheet" href="js/web/ansi.css" type="text/css" media="all" />
    <link rel="stylesheet" href="js/web/console.css" type="text/css" media="all" />
  </head>
  <body>
    <div id="console"></div>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/web/jqconsole.min.js"></script>
    <script src="js/web/mal.js"></script>
    <script>
      $(function() {
        // Creating the console.
        window.jqconsole = $('#console').jqconsole(null, 'user> ');

        printer.println = function () {
          var str = Array.prototype.join.call(arguments, " ")
          jqconsole.Write(str + "\n");
        }

        rep("(println (str \"Mal [\" *host-language* \"]\"))");

        // Abort prompt on Ctrl+C.
        jqconsole.RegisterShortcut('C', function() {
          jqconsole.AbortPrompt();
          handler();
        });
        // Move to line start Ctrl+A.
        jqconsole.RegisterShortcut('A', function() {
          jqconsole.MoveToStart();
          handler();
        });
        // Move to line end Ctrl+E.
        jqconsole.RegisterShortcut('E', function() {
          jqconsole.MoveToEnd();
          handler();
        });
        jqconsole.RegisterMatching('{', '}', 'brace');
        jqconsole.RegisterMatching('(', ')', 'paren');
        jqconsole.RegisterMatching('[', ']', 'bracket');
        jqconsole.RegisterMatching('"', '"', 'dquote');
        // Handle a command.
        var handler = function(line) {
          if (line) {
            try {
              jqconsole.Write(rep(line) + '\n');
            } catch (exc) {
              if (exc instanceof reader.BlankException) { return; }
              if (exc.stack) {
                jqconsole.Write(exc.stack + '\n');
              } else {
                jqconsole.Write(exc + '\n');
              }
            }
          }
          jqconsole.Prompt(true, handler);
          /*
          jqconsole.Prompt(true, handler, function(command) {
            // Continue line if can't compile the command.
            try {
              Function(command);
            } catch (e) {
              if (/[\[\{\(]$/.test(command)) {
                return 1;
              } else {
                return 0;
              }
            }
            return false;
          });
        */
        };

        // Initiate the first prompt.
        handler();
      });
    </script>
  </body>
</html>