edtris/inspector/debug.fnl

37 lines
1.2 KiB
Fennel

(local core (require :core))
(local style (require :core.style))
(local util (require :lib.util))
(local repl (require :editor.repl))
(local ReplView (require :editor.replview))
(local replsession (require :editor.replsession))
(local module (util.hot-table ...))
(fn find-existing-inspector-window [name]
(var result nil)
(each [_ view (ipairs (core.root_view.root_node:get_children)) :until result]
(when (= view.inspector-name name)
(set result view)))
result)
(fn create-inspector-window [name ?value]
(let [node (core.root_view:get_active_node)
conn (repl.new name)
view (ReplView conn)]
(set view.inspector-name name)
(set view.title name)
(view:append {:draw (fn [_ _ x y] (renderer.draw_text style.font name x y style.text) (+ (style.font:get_height) style.padding.y))})
(when ?value
(view:append (repl.mk-result [?value])))
(node:split :right view)
view))
(lambda module.show [?value ?name]
(let [name (replsession.session-id ?name)]
(or (find-existing-inspector-window name) (create-inspector-window name ?value))))
(lambda module.submit [chunk ?name]
(: (module.show ?name) :submit chunk))
module.hot