From 2fab4d7f237c91568c2206527535c70d657b2846 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Tue, 9 Aug 2022 10:38:41 -0500 Subject: [change] printout of oneliners --- lib/oneliner.lisp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'lib/oneliner.lisp') diff --git a/lib/oneliner.lisp b/lib/oneliner.lisp index 3935a0e..3c92a26 100644 --- a/lib/oneliner.lisp +++ b/lib/oneliner.lisp @@ -69,11 +69,18 @@ ;;; PRINTING +(defun print-in-center-of-term (string) + (when (and *term-width* (< (length string) *term-width*)) + (let ((pad + (floor (* 0.5 (- *term-width* (length string)))))) + (loop repeat pad do (princ #\space)))) + (princ string)) + (defun print-oneliner-result-for-user (ol) "Prints information about the oneliner to the terminal." (unless *term-width* (set-term-width)) ; setting here as a fallback, can set it elswere if desired. (let* ((title-line-format-str - (concatenate 'string "~" (prin1-to-string *term-width*) "<[~a]~;~a~;~a~>~%")) + (concatenate 'string "~" (prin1-to-string *term-width*) "~%")) (tags-line-format-string (concatenate 'string "~" (prin1-to-string *term-width*) "<~a~;by ~a ~a~>~%"))) (loop repeat *term-width* do (princ #\_)) @@ -85,18 +92,22 @@ (oneliner-isflagged ol) (oneliner-islocked ol) (equalp "manual" (oneliner-runstyle ol)))) - (format t tags-line-format-string - (format nil "tags: ~{~a~^ ~}" (oneliner-tags ol)) - (or (oneliner-createdby ol) " ") - (if (oneliner-createdat ol) - (datestring-of-universal-time (oneliner-createdat ol)) - " ")) + (loop for x from 0 to (length (oneliner-brief ol)) by *term-width* do (format t "~a~%" (string-trim '(#\space) (alexandria-2:subseq* (oneliner-brief ol) x (+ x *term-width*))))) - (format t "~%~a~%~%" (oneliner-oneliner ol)))) + (princ #\newline) + (print-in-center-of-term (oneliner-oneliner ol)) + (princ #\newline) (princ #\newline) + (format t tags-line-format-string + (format nil "[~{~a~^ ~}]" (oneliner-tags ol)) + (or (oneliner-createdby ol) " ") + (if (oneliner-createdat ol) + (datestring-of-universal-time (oneliner-createdat ol)) + " ")) + (princ #\newline))) ;;;; json serialization -- cgit v1.2.3