1
0
mirror of https://github.com/janet-lang/janet synced 2025-01-11 16:10: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" (add-body "install"
(spit newname bat)))) (spit newname bat))))
(def- tree-l " └─")
(def- tree-t " ├─")
(def- tree-i " │ ")
(def- tree-s " ")
(defn- print-rule-tree (defn- print-rule-tree
"Show dependencies for a given rule recursively in a nice tree." "Show dependencies for a given rule recursively in a nice tree."
[root depth prefix prefix-part] [root depth prefix prefix-part]
(printf "%s%s" prefix root) (print prefix root)
(def rules (getrules)) (when-let [[root-deps] ((getrules) root)]
(when-let [[root-deps] (rules root)]
(def l (-> root-deps length dec))
(when (pos? depth) (when (pos? depth)
(def l (-> root-deps length dec))
(eachp [i d] (sorted root-deps) (eachp [i d] (sorted root-deps)
(def is-last (= i l))
(print-rule-tree (print-rule-tree
d (dec depth) d (dec depth)
(string prefix-part (if is-last tree-l tree-t)) (string prefix-part (if (= i l) " └─" " ├─"))
(string prefix-part (if is-last tree-s tree-i))))))) (string prefix-part (if (= i l) " " " │ ")))))))
(defn declare-archive (defn declare-archive
"Build a janet archive. This is a file that bundles together many janet "Build a janet archive. This is a file that bundles together many janet