branch: externals/taxy
commit 8757b529025eb0eee876889620da36214c61b6b0
Author: Adam Porter <a...@alphapapa.net>
Commit: Adam Porter <a...@alphapapa.net>

    Add: (taxy-magit-section-format-header)
---
 taxy-magit-section.el | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/taxy-magit-section.el b/taxy-magit-section.el
index 85af4d3..3e7c57a 100644
--- a/taxy-magit-section.el
+++ b/taxy-magit-section.el
@@ -291,6 +291,27 @@ the items' values for each column."
                  table)
         (cons table column-sizes)))))
 
+(defun taxy-magit-section-format-header (column-sizes formatters)
+  "Return header string for COLUMN-SIZES and FORMATTERS.
+COLUMN-SIZES should be the CDR of the cell returned by
+`taxy-magit-section-format-items'.  FORMATTERS should be the
+variable passed to that function, which see."
+  (let* ((first-column-name (caar column-sizes))
+        (first-column-alist (alist-get first-column-name formatters nil nil 
#'equal))
+        (first-column-align (pcase-exhaustive (alist-get 'align 
first-column-alist)
+                              ((or `nil 'left) "-")
+                              ('right ""))))
+    (concat (format (format " %%%s%ss"
+                           first-column-align (cdar column-sizes))
+                   (caar column-sizes))
+           (cl-loop for (name . size) in (cdr column-sizes)
+                    for column-alist = (alist-get name formatters nil nil 
#'equal)
+                    for align = (pcase-exhaustive (alist-get 'align 
column-alist)
+                                  ((or `nil 'left) "-")
+                                  ('right ""))
+                    for spec = (format " %%%s%ss" align size)
+                    concat (format spec name)))))
+
 ;;;; Footer
 
 (provide 'taxy-magit-section)

Reply via email to