1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-24 15:30:27 +00:00

Streamline tree printing code.

This commit is contained in:
Calvin Rose 2020-04-20 19:50:32 -05:00
parent 9b5c6112e5
commit da88dd8cfa

View File

@ -873,24 +873,18 @@ int main(int argc, const char **argv) {
(add-body "install"
(spit newname bat))))
(def- tree-l " └─")
(def- tree-t " ├─")
(def- tree-i " │ ")
(def- tree-s " ")
(defn- print-rule-tree
"Show dependencies for a given rule recursively in a nice tree."
[root depth prefix prefix-part]
(printf "%s%s" prefix root)
(def rules (getrules))
(when-let [[root-deps] (rules root)]
(def l (-> root-deps length dec))
(print prefix root)
(when-let [[root-deps] ((getrules) root)]
(when (pos? depth)
(def l (-> root-deps length dec))
(eachp [i d] (sorted root-deps)
(def is-last (= i l))
(print-rule-tree
d (dec depth)
(string prefix-part (if is-last tree-l tree-t))
(string prefix-part (if is-last tree-s tree-i)))))))
(string prefix-part (if (= i l) " └─" " ├─"))
(string prefix-part (if (= i l) " " " │ ")))))))
(defn declare-archive
"Build a janet archive. This is a file that bundles together many janet