• R/O
  • SSH

cl-sack: Commit

CL-Sack is a Common Lisp library for making and manipulating Sack files.


Commit MetaInfo

Revisionf54ebcdaa28c51825fe374ba7790c401076ef245 (tree)
Time2019-02-15 18:02:10
AuthorAlexa Jones-Gonzales <alexa@part...>
CommiterAlexa Jones-Gonzales

Log Message

Added a macro to italicize text, and a function to convert a number
into a human-readable size.

Change Summary

Incremental Difference

diff -r 96b76fca0810 -r f54ebcdaa28c gsacked-src/globals.lisp
--- a/gsacked-src/globals.lisp Tue Feb 12 00:51:02 2019 -0700
+++ b/gsacked-src/globals.lisp Fri Feb 15 02:02:10 2019 -0700
@@ -26,3 +26,7 @@
2626
2727 (declaim (type (or argparser:parser null) *args*))
2828 (defparameter *args* nil)
29+
30+(alexandria:define-constant +size-suffixes+
31+ '("Bytes" "KiB" "MiB" "GiB" "TiB" "PiB" "EiB" "ZiB" "YiB")
32+ :test #'equalp)
diff -r 96b76fca0810 -r f54ebcdaa28c gsacked-src/util.lisp
--- a/gsacked-src/util.lisp Tue Feb 12 00:51:02 2019 -0700
+++ b/gsacked-src/util.lisp Fri Feb 15 02:02:10 2019 -0700
@@ -38,3 +38,18 @@
3838 (with-text-face (,real-stream :bold)
3939 (format ,real-stream "Error: ")))
4040 (format ,real-stream ,msg ,@fmt-args))))
41+
42+(defmacro italicized ((stream) text)
43+ `(with-text-face (,stream :italic)
44+ (write-string ,text ,stream)))
45+
46+(defun bytes->pretty-size (bytes)
47+ (let* ((mag (if (> bytes 0)
48+ (truncate (log bytes 1024))
49+ 0))
50+ (human-size (if (> bytes 0)
51+ (float (/ bytes (ash 1 (* mag 10))))
52+ 0)))
53+ (if (= mag 0)
54+ (format nil "~:d ~a" human-size (nth mag +size-suffixes+))
55+ (format nil "~,2f ~a" human-size (nth mag +size-suffixes+)))))
Show on old repository browser