Update format stuff
This commit is contained in:
		| @ -23,7 +23,8 @@ | ||||
|            #:*trashinfo-formatters* | ||||
|            #:*directory-formatters* | ||||
|            #:print-clash-format-info | ||||
|            #:*missing-file-formatters*)) | ||||
|            #:*missing-file-formatters* | ||||
|            #:*format-switch-base-two-base-ten*)) | ||||
|  | ||||
| (in-package :clash/format) | ||||
|  | ||||
| @ -182,7 +183,8 @@ add one to the result." | ||||
|  | ||||
| (defun format-object (stream control-obj obj | ||||
|                       &key (index 1) (max-index 1) | ||||
|                         (max-index-length (number-length max-index))) | ||||
|                         (max-index-length (number-length max-index)) | ||||
|                         extra-args) | ||||
|   "Format the object OBJ to STREAM according to CONTROL-OBJECT (which is from | ||||
| parse-format-string)." | ||||
|   (dolist (part control-obj) | ||||
| @ -200,21 +202,22 @@ parse-format-string)." | ||||
|        (with-slots (padder action) (car part) | ||||
|          (funcall padder stream (cdr part) | ||||
|                   (with-output-to-string (tmp-output) | ||||
|                     (funcall action tmp-output obj)) | ||||
|                     (apply action tmp-output obj extra-args)) | ||||
|                   obj))) | ||||
|       (t (funcall (format-code-action part) stream obj))))) | ||||
|  | ||||
| (defun format-list (stream control-obj objs &optional (indices t) extra-action) | ||||
| (defun format-list (stream control-obj objs | ||||
|                     &key (indices t) extra-action extra-args) | ||||
|   "Format a list of objects OBJS with format-object." | ||||
|   (if (eq t indices) | ||||
|       (loop with max-index = (length objs) | ||||
|             with max-index-length = (number-length max-index) | ||||
|             for obj in objs | ||||
|             for i upfrom 1 | ||||
|             do (format-object stream control-obj obj :index i | ||||
|                                                      :max-index max-index | ||||
|                                                      :max-index-length | ||||
|                                                      max-index-length) | ||||
|             do (format-object stream control-obj obj | ||||
|                               :index i :max-index max-index | ||||
|                               :max-index-length max-index-length | ||||
|                               :extra-args extra-args) | ||||
|             when extra-action | ||||
|               do (funcall extra-action obj)) | ||||
|       (loop with max-index = (reduce #'max indices :initial-value 0) | ||||
| @ -223,7 +226,8 @@ parse-format-string)." | ||||
|             for index in indices | ||||
|             do (format-object stream control-obj (aref objs-arr index) | ||||
|                               :index (1+ index) :max-index max-index | ||||
|                               :max-index-length max-index-length) | ||||
|                               :max-index-length max-index-length | ||||
|                               :extra-args extra-args) | ||||
|             when extra-action | ||||
|               do (funcall extra-action (aref objs-arr index))))) | ||||
|  | ||||
| @ -264,6 +268,9 @@ The recognized printf-style sequences for ~A are: | ||||
|       (:right (format stream "~V<~A~>" width text)) | ||||
|       (t (format stream "~A" text))))) | ||||
|  | ||||
| (defvar *format-switch-base-two-base-ten* nil | ||||
|   "Switch the base 2 and base 10 for codes.") | ||||
|  | ||||
| (defparameter *trashinfo-formatters* | ||||
|   (list | ||||
|    (make-format-code | ||||
| @ -319,14 +326,16 @@ The recognized printf-style sequences for ~A are: | ||||
|     :name #\h | ||||
|     :action (lambda (stream info) | ||||
|               (format stream "~A" | ||||
|                       (format-size (trashinfo-size info)))) | ||||
|                       (format-size (trashinfo-size info) | ||||
|                                    *format-switch-base-two-base-ten*))) | ||||
|     :padder (make-fixed-with-padder 9) | ||||
|     :doc "the file's size with a (h)uman readable suffix (powers of 10)") | ||||
|    (make-format-code | ||||
|     :name #\H | ||||
|     :action (lambda (stream info) | ||||
|               (format stream "~A" | ||||
|                       (format-size (trashinfo-size info) t))) | ||||
|                       (format-size (trashinfo-size info) | ||||
|                                    (not *format-switch-base-two-base-ten*)))) | ||||
|     :padder (make-fixed-with-padder 10) | ||||
|     :doc "the file's size with a (H)uman readable suffix (power of 2)"))) | ||||
|  | ||||
| @ -353,14 +362,16 @@ The recognized printf-style sequences for ~A are: | ||||
|     :name #\h | ||||
|     :action (lambda (stream path-and-infos) | ||||
|               (format stream "~A" (format-size | ||||
|                                    (trashinfo-list-size (cdr path-and-infos))))) | ||||
|                                    (trashinfo-list-size (cdr path-and-infos)) | ||||
|                                    *format-switch-base-two-base-ten*))) | ||||
|     :padder (make-fixed-with-padder 9) | ||||
|     :doc "the directory's size with a (h)uman readable suffix (powers of 10)") | ||||
|    (make-format-code | ||||
|     :name #\H | ||||
|     :action (lambda (stream path-and-infos) | ||||
|               (format stream "~A" | ||||
|                       (format-size (trashinfo-list-size (cdr path-and-infos)) t))) | ||||
|                       (format-size (trashinfo-list-size (cdr path-and-infos)) | ||||
|                                    (not *format-switch-base-two-base-ten*)))) | ||||
|     :padder (make-fixed-with-padder 10) | ||||
|     :doc "the directory's size with a (H)uman readable suffix (powers of 2)") | ||||
|    (make-format-code | ||||
|  | ||||
		Reference in New Issue
	
	Block a user