1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 01:57:09 +03:00
mal/mal.html

82 lines
2.6 KiB
HTML
Raw Normal View History

<!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>