branch: externals/srht
commit dfea7ce1bef7a52ba70e15438197b96641c269fd
Author: Aleksandr Vityazev <[email protected]>
Commit: Aleksandr Vityazev <[email protected]>
srht-git: srht-git-repos-list: New command.
* lisp/srht-git (srht-git-repos-list): New command.
* lisp/srht (srht--view): New function.
---
lisp/srht-git.el | 11 ++++++++++
lisp/srht.el | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+)
diff --git a/lisp/srht-git.el b/lisp/srht-git.el
index c3537634d0..5218c28258 100644
--- a/lisp/srht-git.el
+++ b/lisp/srht-git.el
@@ -325,5 +325,16 @@ Set VISIBILITY, NEW-NAME and DESCRIPTION."
instance (srht-git-repos instance))
))))
+;;;###autoload
+(defun srht-git-repos-list (instance)
+ "Display a list of Sourcehut INSTANCE git repositories."
+ (interactive
+ (list (srht-read-instance "Instance: ")))
+ (unless (fboundp 'make-vtable)
+ (error "Vtable required"))
+ (srht--view instance srht-git-repositories
+ `("d" (lambda (obj)
+ (srht-git-repo-delete ,instance (plist-get obj :name))))))
+
(provide 'srht-git)
;;; srht-git.el ends here
diff --git a/lisp/srht.el b/lisp/srht.el
index 5991f739cb..5b8e712029 100644
--- a/lisp/srht.el
+++ b/lisp/srht.el
@@ -283,5 +283,69 @@ For the existing PLIST for the INSTANCE instance name."
(concat blank visibility (make-string (- 12 (length visibility)) ws-char)
created)))
+(declare-function iso8601-parse "iso8601" (string &optional form))
+
+(defun srht--format-date (str)
+ "PARSE an ISO 8601 STR.
+Return string in format DAY.MONTH.YEAR."
+ (pcase-let (((seq _sec _min _hour day month year)
+ (iso8601-parse str)))
+ (format "%02d.%02d.%02d" day month year)))
+
+(defalias 'srht--make-vtable
+ (if (and (require 'vtable nil t)
+ (fboundp 'make-vtable))
+ #'make-vtable
+ (lambda (&rest _args)
+ (error "Require vtable"))))
+
+(defalias 'srht--vtable-colum
+ (if (and (require 'vtable nil t)
+ (fboundp 'vtable-column))
+ #'vtable-column
+ (lambda (&rest _args)
+ (error "Require vtable"))))
+
+(defalias 'srht--define-keymap
+ (if (and (require 'keymap nil t)
+ (fboundp 'define-keymap))
+ #'define-keymap
+ (lambda (&rest _args)
+ (error "Require define-keymap"))))
+
+(defun srht--view (instance repositories &optional actions)
+ "Display a list of Sourcehut INSTANCE REPOSITORIES.
+ACTIONS are simple commands that will be called with the
+object under point."
+ (declare (indent 2))
+ (let ((buffer (get-buffer-create "*Sourcehut repositories*")))
+ (with-current-buffer buffer
+ (srht--make-vtable
+ :columns '("Name"
+ (:name "Visibility"
+ :formatter (lambda (val) (when val (downcase val))))
+ (:name "Created"
+ :formatter srht-git--format-date
+ :width 10)
+ (:name "Updated"
+ :formatter srht-git--format-date
+ :width 10))
+ :objects (plist-get repositories (intern instance))
+ :getter (lambda (object column vtable)
+ (pcase (srht--vtable-colum vtable column)
+ ("Name" (plist-get object :name))
+ ("Visibility" (plist-get object :visibility))
+ ("Created" (plist-get object :created))
+ ("Updated" (plist-get object :updated))))
+ :separator-width 5
+ :actions actions
+ :keymap (srht--define-keymap
+ "q" #'kill-current-buffer
+ "n" #'next-line
+ "p" #'previous-line))
+ (read-only-mode)
+ (hl-line-mode))
+ (switch-to-buffer buffer)))
+
(provide 'srht)
;;; srht.el ends here