hy/eg/tryhy/js/repl.js

28 lines
786 B
JavaScript
Raw Normal View History

2013-10-31 22:30:00 +01:00
$(document).ready(function(){
2013-11-02 00:21:54 +01:00
var backlog = [];
2013-10-31 22:30:00 +01:00
$('#hy-console').console({
promptLabel: 'hy=> ',
commandValidate:function(line){
2013-11-02 00:21:54 +01:00
if (line == '') return false;
2013-10-31 22:30:00 +01:00
else return true;
},
commandHandle:function(line, report){
2013-11-02 00:21:54 +01:00
$.ajax({
type: 'POST',
url: '/eval',
data: JSON.stringify({code: line, env: backlog}),
contentType: 'application/json',
dataType: 'json',
success: function(data) {
report([{msg : data.stdout, className:'jquery-console-message-value'},
{msg : data.stderr, className:'jquery-console-message-error'}]);
}
2013-10-31 22:30:00 +01:00
});
2013-11-02 00:21:54 +01:00
backlog.push(line);
2013-10-31 22:30:00 +01:00
},
animateScroll:true,
promptHistory:true,
autofocus:true,
}).promptText('(+ 41 1)');
});