summaryrefslogtreecommitdiff
path: root/tissue/issue.scm
diff options
context:
space:
mode:
authorArun Isaac2022-06-27 00:03:41 +0530
committerArun Isaac2022-06-27 00:19:51 +0530
commit1a0e0e89a8cefb0016767cf8fb940f64274a40ea (patch)
tree5ae0a0926914376613f18c47a528aa2f684fc272 /tissue/issue.scm
parent76991c195740d2edee0a1887b4850e438d8e83d2 (diff)
downloadtissue-1a0e0e89a8cefb0016767cf8fb940f64274a40ea.tar.gz
tissue-1a0e0e89a8cefb0016767cf8fb940f64274a40ea.tar.lz
tissue-1a0e0e89a8cefb0016767cf8fb940f64274a40ea.zip
issue: Move issue printing functions to (tissue issue).
* bin/tissue: Do not import (srfi srfi-19). (print-issue, print-issue-to-gemtext): Move to tissue/issue.scm. (human-date-string): Move to tissue/utils.scm. * tissue/issue.scm: Import (term ansi-color). * tissue/utils.scm: Import (srfi srfi-19).
Diffstat (limited to 'tissue/issue.scm')
-rw-r--r--tissue/issue.scm76
1 files changed, 76 insertions, 0 deletions
diff --git a/tissue/issue.scm b/tissue/issue.scm
index cbf4551..4dd1854 100644
--- a/tissue/issue.scm
+++ b/tissue/issue.scm
@@ -27,6 +27,7 @@
#:use-module (srfi srfi-171)
#:use-module (ice-9 match)
#:use-module (ice-9 regex)
+ #:use-module (term ansi-color)
#:use-module (git)
#:use-module (xapian xapian)
#:use-module (tissue git)
@@ -54,6 +55,8 @@
alist->issue
post->alist
alist->post
+ print-issue
+ print-issue-to-gemtext
issues
read-gemtext-issue
index-issue))
@@ -137,6 +140,79 @@ serialized."
(post (assq-ref alist 'author)
(iso-8601->date (assq-ref alist 'date))))
+(define (print-issue issue)
+ "Print ISSUE, an <issue> object, in search results."
+ (let ((number-of-posts (length (issue-posts issue))))
+ (display (colorize-string (issue-title issue) 'MAGENTA 'UNDERLINE))
+ (unless (null? (issue-keywords issue))
+ (display " ")
+ (display (string-join (map (cut colorize-string <> 'ON-BLUE)
+ (issue-keywords issue))
+ " ")))
+ (unless (null? (issue-assigned issue))
+ (display (colorize-string (string-append " (assigned: "
+ (string-join (issue-assigned issue)
+ ", ")
+ ")")
+ 'GREEN)))
+ (when (> number-of-posts 1)
+ (display (string-append " ["
+ (number->string number-of-posts)
+ " posts]")))
+ (newline)
+ (display (colorize-string (issue-file issue) 'YELLOW))
+ (newline)
+ (display (string-append
+ "opened "
+ (colorize-string (human-date-string (issue-created-date issue)) 'CYAN)
+ " by "
+ (colorize-string (issue-creator issue) 'CYAN)))
+ (when (> number-of-posts 1)
+ (display (string-append (colorize-string "," 'CYAN)
+ " last updated "
+ (colorize-string (human-date-string (issue-last-updated-date issue))
+ 'CYAN)
+ " by "
+ (colorize-string (issue-last-updater issue)
+ 'CYAN))))
+ (unless (zero? (issue-tasks issue))
+ (display (string-append (colorize-string "; " 'CYAN)
+ (number->string (issue-completed-tasks issue))
+ "/"
+ (number->string (issue-tasks issue))
+ " tasks done")))
+ (newline)
+ (newline)))
+
+(define (print-issue-to-gemtext issue)
+ "Print ISSUE to gemtext."
+ (let ((number-of-posts (length (issue-posts issue))))
+ (format #t "# ~a" (issue-title issue))
+ (unless (null? (issue-keywords issue))
+ (format #t " [~a]"
+ (string-join (issue-keywords issue)
+ ", ")))
+ (unless (null? (issue-assigned issue))
+ (format #t " (assigned: ~a)"
+ (string-join (issue-assigned issue)
+ ", ")))
+ (when (> number-of-posts 1)
+ (format #t " [~a posts]" number-of-posts))
+ (newline)
+ (format #t "opened ~a by ~a"
+ (human-date-string (issue-created-date issue))
+ (issue-creator issue))
+ (when (> number-of-posts 1)
+ (format #t ", last updated ~a by ~a"
+ (human-date-string (issue-last-updated-date issue))
+ (issue-last-updater issue)))
+ (unless (zero? (issue-tasks issue))
+ (format #t "; ~a/~a tasks done"
+ (issue-completed-tasks issue)
+ (issue-tasks issue)))
+ (newline)
+ (newline)))
+
(define (hashtable-append! hashtable key new-values)
"Append NEW-VALUES to the list of values KEY is associated to in
HASHTABLE. Deduplicate the resulting list if necessary. If KEY is not