ex/tryhy: per request repl instance
This commit is contained in:
parent
a090b86b5e
commit
079e3002a7
@ -1,15 +1,24 @@
|
|||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
var backlog = [];
|
||||||
$('#hy-console').console({
|
$('#hy-console').console({
|
||||||
promptLabel: 'hy=> ',
|
promptLabel: 'hy=> ',
|
||||||
commandValidate:function(line){
|
commandValidate:function(line){
|
||||||
if (line == "") return false;
|
if (line == '') return false;
|
||||||
else return true;
|
else return true;
|
||||||
},
|
},
|
||||||
commandHandle:function(line, report){
|
commandHandle:function(line, report){
|
||||||
$.getJSON("/eval", {code: line}, function(data) {
|
$.ajax({
|
||||||
report([{msg : data.stdout, className:"jquery-console-message-value"},
|
type: 'POST',
|
||||||
{msg : data.stderr, className:"jquery-console-message-error"}]);
|
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'}]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
backlog.push(line);
|
||||||
},
|
},
|
||||||
animateScroll:true,
|
animateScroll:true,
|
||||||
promptHistory:true,
|
promptHistory:true,
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
(require hy.contrib.meth)
|
|
||||||
(import [hy.cmdline [HyREPL]]
|
(import [hy.cmdline [HyREPL]]
|
||||||
[sys]
|
[sys]
|
||||||
[StringIO [StringIO]]
|
[StringIO [StringIO]]
|
||||||
@ -18,9 +17,13 @@
|
|||||||
(setv sys.stderr old-stderr)
|
(setv sys.stderr old-stderr)
|
||||||
{"stdout" (fake-stdout.getvalue) "stderr" (fake-stderr.getvalue)})]])
|
{"stdout" (fake-stdout.getvalue) "stderr" (fake-stderr.getvalue)})]])
|
||||||
|
|
||||||
|
|
||||||
(def repl (MyHyREPL))
|
|
||||||
|
|
||||||
(def app (Flask __name__))
|
(def app (Flask __name__))
|
||||||
(route hello "/<name>" [name] (.format "(hello \"{0}!\")" name))
|
|
||||||
(route eval-get "/eval" [] (json.dumps (repl.eval (get request.args "code"))))
|
(with-decorator (kwapply (app.route "/eval") {"methods" ["POST"]})
|
||||||
|
(fn []
|
||||||
|
(let [[repl (MyHyREPL)] [input (request.get_json)]]
|
||||||
|
(foreach [expr (get input "env")]
|
||||||
|
(repl.eval expr))
|
||||||
|
(json.dumps (repl.eval (get input "code")))
|
||||||
|
)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user