From e4393504176dc4da117fde95fc10181a2ea6f929 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Sat, 26 Apr 2014 14:19:49 -0500 Subject: JS: switch from josh.js console to jqconsole. js/web/jqconsole.min.js and web/ansi.css are from https://github.com/replit/jq-console and licensed MIT. --- mal.html | 121 +++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 46 deletions(-) (limited to 'mal.html') diff --git a/mal.html b/mal.html index b8b3dd0..45e6dc3 100644 --- a/mal.html +++ b/mal.html @@ -1,52 +1,81 @@ - + - - - - Make a Lisp - - - - - - - - - - - - - - - -
+ printer.println = function () { + var str = Array.prototype.join.call(arguments, " ") + jqconsole.Write(str + "\n"); + } -
-

Make a Lisp

+ rep("(println (str \"Mal [\" *host-language* \"]\"))"); -
-
Lisp REPL
-
-
-
-
+ // 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(); + }); + + -- cgit v1.2.3