bomberpac/editor/repl.fnl

41 lines
1.2 KiB
Plaintext
Raw Normal View History

2021-03-29 05:03:43 +00:00
(local util (require :lib.util))
(local fennel (require :lib.fennel))
(local style (require :core.style))
(local lume (require :lib.lume))
(local {: textbutton : under : group-wrapper} (util.require :editor.imgui))
(local {: inspect} (util.require :inspector))
(local replsession (require :editor.replsession))
(local repl (util.hot-table ...))
2021-03-29 05:03:43 +00:00
(fn repl.inspector [{: w &as form} {: vals : states}]
(let [g (group-wrapper form)]
(each [i v (ipairs vals)]
(g #(inspect $...) (under (g) {: w}) (. states i) v))
(g)))
2021-03-29 05:03:43 +00:00
(fn repl.notify [listeners line]
(each [_ listener (ipairs listeners)]
(listener:append line)))
2021-04-04 02:35:50 +00:00
(fn repl.mk-result [vals]
{:draw repl.inspector : vals :states (icollect [_ (ipairs vals)] {})})
2021-04-04 02:35:50 +00:00
2021-03-29 05:03:43 +00:00
(fn repl.listen [{: listeners} listener]
(table.insert listeners listener))
(fn repl.unlisten [{: listeners} listener]
(lume.remove listeners listener))
(fn repl.submit [{: session : listeners} chunk]
(session:submit chunk (fn [{: vals : err : traceback}] (repl.notify listeners (repl.mk-result (or vals [err traceback]))))))
(fn repl.new [?id]
{:listeners []
:listen #(repl.listen $...)
:unlisten #(repl.unlisten $...)
:submit #(repl.submit $...)
:session (replsession.session ?id)})
2021-03-29 05:03:43 +00:00
repl.hot