eg/tryhy: add error handling
This commit is contained in:
parent
0aae750068
commit
a090b86b5e
@ -6,8 +6,9 @@ $(document).ready(function(){
|
||||
else return true;
|
||||
},
|
||||
commandHandle:function(line, report){
|
||||
$.get("/eval", {code: line}, function(data) {
|
||||
report([{msg : data, className:"jquery-console-message-value"}]);
|
||||
$.getJSON("/eval", {code: line}, function(data) {
|
||||
report([{msg : data.stdout, className:"jquery-console-message-value"},
|
||||
{msg : data.stderr, className:"jquery-console-message-error"}]);
|
||||
});
|
||||
},
|
||||
animateScroll:true,
|
||||
|
@ -2,20 +2,25 @@
|
||||
(import [hy.cmdline [HyREPL]]
|
||||
[sys]
|
||||
[StringIO [StringIO]]
|
||||
[flask [Flask redirect request]])
|
||||
[flask [Flask redirect request]]
|
||||
[json])
|
||||
|
||||
(defclass MyHyREPL [HyREPL]
|
||||
[[eval (fn [self code]
|
||||
(setv old-stdout sys.stdout)
|
||||
(setv old-stderr sys.stderr)
|
||||
(setv fake-stdout (StringIO))
|
||||
(setv sys.stdout fake-stdout)
|
||||
(setv fake-stderr (StringIO))
|
||||
(setv sys.stderr fake-stderr)
|
||||
(HyREPL.runsource self code "<input>" "single")
|
||||
(setv sys.stdout old-stdout)
|
||||
(fake-stdout.getvalue))]])
|
||||
(setv sys.stderr old-stderr)
|
||||
{"stdout" (fake-stdout.getvalue) "stderr" (fake-stderr.getvalue)})]])
|
||||
|
||||
|
||||
(def repl (MyHyREPL))
|
||||
|
||||
(def app (Flask __name__))
|
||||
(route hello "/<name>" [name] (.format "(hello \"{0}!\")" name))
|
||||
(route eval-get "/eval" [] (repl.eval (get request.args "code")))
|
||||
(route eval-get "/eval" [] (json.dumps (repl.eval (get request.args "code"))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user