41 lines
1.3 KiB
Fennel
41 lines
1.3 KiB
Fennel
(local util (require :plugins.fennel-xl.util))
|
|
(local fennel (require :plugins.fennel-xl.fennel))
|
|
(local style (require :core.style))
|
|
(local lume (require :plugins.fennel-xl.lume))
|
|
(local {: textbutton : under : group-wrapper} (util.require :plugins.fennel-xl.imgui))
|
|
(local {: inspect} (util.require :plugins.fennel-xl.inspector))
|
|
(local replsession (require :plugins.fennel-xl.replsession))
|
|
|
|
(local repl (util.hot-table ...))
|
|
|
|
(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)))
|
|
|
|
(fn repl.notify [listeners line]
|
|
(each [_ listener (ipairs listeners)]
|
|
(listener:append line)))
|
|
|
|
(fn repl.mk-result [vals]
|
|
{:draw repl.inspector : vals :states (icollect [_ (ipairs vals)] {})})
|
|
|
|
(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 ?repl ?opts]
|
|
{:listeners []
|
|
:listen #(repl.listen $...)
|
|
:unlisten #(repl.unlisten $...)
|
|
:submit #(repl.submit $...)
|
|
:session (replsession.session ?id ?repl ?opts)})
|
|
|
|
repl.hot
|