Streamline tree printing code.

This commit is contained in:
Calvin Rose 2020-04-20 19:50:32 -05:00
parent 9b5c6112e5
commit da88dd8cfa
1 changed files with 5 additions and 11 deletions

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