aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-03-04 12:09:47 -0600
committerColin Okay <okay@toyful.space>2022-03-04 12:10:06 -0600
commit924896962c42acf55018521e9f08e5ba4b311903 (patch)
treedd073ba5fd6b9daa842991315ead1f2db70f9990 /src
parent1088702ed0c7f64f9fb9c5909ffec02b6b586924 (diff)
printout of oneliners updated
Diffstat (limited to 'src')
-rw-r--r--src/lib.lisp53
1 files changed, 35 insertions, 18 deletions
diff --git a/src/lib.lisp b/src/lib.lisp
index c77619c..1ddb103 100644
--- a/src/lib.lisp
+++ b/src/lib.lisp
@@ -520,28 +520,44 @@ the directories that appear in the value of that variable."
(print results output))
(merge-into-cache results))
-(defun print-oneliner-result-for-user (number oneliner)
- (dotimes (n 80) (princ #\_))
- (terpri)
- (format t "~3a~a~a~a [~a] ~a"
- number
- (if (getf oneliner :isflagged)
- "⚠" " ")
- (if (getf oneliner :islocked)
- "🔒" " ")
- (if (equalp "manual" (getf oneliner :runstyle))
- "📋" " ")
- (getf oneliner :id)
- (getf oneliner :brief))
- (format t "~% by: ~12a tags: ~{~a~^ ~}" (getf oneliner :createdby) (getf oneliner :tags))
- (format t "~%~% ~a~%~%" (getf oneliner :oneliner)))
+(defvar *term-width* 80)
+
+(defun set-term-width ()
+ (setf *term-width*
+ (or (parse-integer (uiop:run-program '("tput" "cols") :output :string) :junk-allowed t)
+ 80)))
+
+(defun print-oneliner-result-for-user (oneliner)
+ (let* ((title-line-format-str
+ (concatenate 'string "~" (prin1-to-string *term-width*) "<[~a]~;~a~;~a~>~%"))
+ (tags-line-format-string
+ (concatenate 'string "~" (prin1-to-string *term-width*) "<~a~;by ~a~>~%")))
+ (loop repeat *term-width* do (princ #\_))
+ (terpri)
+ (format t title-line-format-str
+ (getf oneliner :id)
+ (or (getf oneliner :name) " ")
+ (format nil "~:[ ~;⚠~]~:[ ~;🔒~]~:[ ~;📋~]"
+ (getf oneliner :isflagged)
+ (getf oneliner :islocked)
+ (equalp "manual" (getf oneliner :runstyle))))
+ (format t tags-line-format-string
+ (format nil "tags: ~{~a~^ ~}"
+ (getf oneliner :tags))
+ (getf oneliner :createdby))
+ (loop
+ with brief = (getf oneliner :brief)
+ for x from 0 to (length brief) by *term-width*
+ do (format t "~a~%"
+ (string-trim '(#\space)
+ (alexandria-2:subseq* brief x (+ x *term-width*)))))
+ (format t "~%~a~%~%" (getf oneliner :oneliner))))
(defun cache-and-print-search-response (response)
(cache-search-results-to-last-search-file
- (loop for number from 1
- for oneliner in (getf (jonathan:parse response) :oneliners)
+ (loop for oneliner in (getf (jonathan:parse response) :oneliners)
collect oneliner
- do (print-oneliner-result-for-user number oneliner))))
+ do (print-oneliner-result-for-user oneliner))))
(defun newest-oneliners (&optional limit)
(ensure-config)
@@ -565,6 +581,7 @@ the directories that appear in the value of that variable."
(defun search-for-oneliners (terms limit not-flagged-p)
(assert (loop for term in terms never (find #\, term) ))
+ (set-term-width)
(ensure-config)
(let ((response
(api:request-with