cljs.pprint/print-table
(print-table ks rows)
(print-table rows)
Source docstring:
Prints a collection of maps in a textual table. Prints table headings
ks, and then a line of output for each row, corresponding to the keys
in ks. If ks are not specified, use the keys of the first item in rows.
(defn print-table
{:added "1.3"}
([ks rows]
(when (seq rows)
(let [widths (map
(fn [k]
(apply max (count (str k)) (map #(count (str (get % k))) rows)))
ks)
spacers (map #(apply str (repeat % "-")) widths)
fmt-row (fn [leader divider trailer row]
(str leader
(apply str (interpose divider
(for [[col width] (map vector (map #(get row %) ks) widths)]
(add-padding width (str col)))))
trailer))]
(cljs.core/println)
(cljs.core/println (fmt-row "| " " | " " |" (zipmap ks ks)))
(cljs.core/println (fmt-row "|-" "-+-" "-|" (zipmap ks spacers)))
(doseq [row rows]
(cljs.core/println (fmt-row "| " " | " " |" row))))))
([rows] (print-table (keys (first rows)) rows)))