diff options
Diffstat (limited to 'src/lib.lisp')
-rw-r--r-- | src/lib.lisp | 53 |
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 |