Handle errors in the REPL
authorDavid Vazquez <davazp@gmail.com>
Sun, 23 Dec 2012 22:05:24 +0000 (22:05 +0000)
committerDavid Vazquez <davazp@gmail.com>
Sun, 23 Dec 2012 22:05:24 +0000 (22:05 +0000)
test.html

index ec43a81..0fcd669 100644 (file)
--- a/test.html
+++ b/test.html
     .jqconsole-output {
         color: gray;
     }
-    </style>
+    .jqconsole-error {
+        color: red;
+    }
+</style>
   </head>
 
   <body>
     <script src="jqconsole.min.js" type="text/javascript" charset="utf-8"></script>
     <script>
       $(function () {
-        var jqconsole = $('#console').jqconsole('Hi\n', '> ');
+        var jqconsole = $('#console').jqconsole('Welcome to Lisptrack!\n', '> ');
+        jqconsole.RegisterMatching('(', ')', 'parents');
+
         var startPrompt = function () {
           // Start the prompt with history enabled.
           jqconsole.Prompt(true, function (input) {
             // Output input with the class jqconsole-output.
             if (input[0] != ','){
-                jqconsole.Write(JSON.stringify(lisp.evalString(input)) + '\n', 'jqconsole-output');
+                try {
+                    jqconsole.Write(JSON.stringify(lisp.evalString(input)) + '\n', 'jqconsole-output');
+                } catch(error) {
+                    jqconsole.Write('ERROR: ' + error + '\n', 'jqconsole-error');
+                }
             } else {
                 jqconsole.Write(JSON.stringify(lisp.compileString(input.slice(1))) + '\n', 'jqconsole-output');
             }