summaryrefslogtreecommitdiff
path: root/util.lisp
diff options
context:
space:
mode:
authorLogan Hunt <loganjh@amazon.com>2022-05-24 16:22:00 -0700
committerLogan Hunt <loganjh@amazon.com>2022-05-24 16:22:00 -0700
commit47b6bdf8b737bf12f5f7b8839ed2389ff28c723c (patch)
treeb5be62069a96b7461b8ec4bae588d375591616e3 /util.lisp
parent3db9a2eb7a7d14ce935f5902b0c21ce4fd5eb729 (diff)
downloadlispruns-47b6bdf8b737bf12f5f7b8839ed2389ff28c723c.tar.gz
lispruns-47b6bdf8b737bf12f5f7b8839ed2389ff28c723c.zip
Write code into systems and add formatting for highlight lists
Diffstat (limited to 'util.lisp')
-rw-r--r--util.lisp63
1 files changed, 8 insertions, 55 deletions
diff --git a/util.lisp b/util.lisp
index 805e0bc..584f442 100644
--- a/util.lisp
+++ b/util.lisp
@@ -1,55 +1,8 @@
-;; For big ascii-art digits
-(load "digits.lisp")
-
-(defmacro inc (x)
- `(setf ,x (1+ ,x)))
-
-;; Wraps text and adds ellipsis if it doesn't fit within width, scrolling
-;; by index i
-(defun maybe-wrap-text (text width i)
- (let ((textlen (length text)))
- (if (>= width textlen)
- text
- (let* ((max-width (1- width))
- (max-wrap (1+ (- textlen max-width)))
- (wrap-i (rem i max-wrap)))
- (concatenate 'string (subseq text wrap-i (+ wrap-i (min max-width textlen))) "-")))))
-
-;; Makes a-list with '((hours . HOURS) (minutes . MINUTES) (seconds . SECONDS) (ms . MILLISECONDS))
-(defun make-time-alist (ms)
- `((hours . ,(floor (/ ms (* 1000 60 60))))
- (minutes . ,(floor (mod (/ ms (* 1000 60)) 60)))
- (seconds . ,(floor (mod (/ ms 1000) 60)))
- (ms . ,(mod ms 1000))))
-
-
-;; Add a list of strings representing horizontal slices of a character to another list of strings representing horizontal slices of a string, or create a new list of horizontal slices if the original was empty.
-;; Character height will be truncated to the height of the first character in the slices.
-(defun add-to-horizontal (character horizontal-layers &key (seperator " "))
- (let ((layer-height (length horizontal-layers)))
- (loop for i from 0 to (1- (if (zerop layer-height) (length character) layer-height))
- collect
- (let ((layer (nth i horizontal-layers))
- (character-slice (nth i character)))
- (if (and layer (> (length layer) 0))
- (concatenate 'string layer seperator character-slice)
- character-slice)))))
-
-;; Formats, disregarding min/hour if they shouldn't be shown, a time alist to "H:M:S.ms"
-(defun format-time (time-alist)
- (let
- ((hours (cdr (assoc 'hours time-alist)))
- (minutes (cdr (assoc 'minutes time-alist)))
- (seconds (cdr (assoc 'seconds time-alist)))
- (centis (round (/ (cdr (assoc 'ms time-alist)) 10))))
- (concatenate 'string
- (unless (zerop hours) (format nil "~2,'0d:" hours))
- (unless (and (zerop minutes) (zerop hours)) (format nil "~2,'0d:" minutes))
- (format nil "~2,'0d.~2,'0d" seconds centis))))
-
-;; Creates a list of horizontal slices to display a formatted larger string by using figlet characters
-(defun lispglet (str &optional (char-hashes *big-digits*))
- (loop for horizontal-layers = '()
- then (add-to-horizontal (gethash c char-hashes) horizontal-layers)
- for c across str
- finally (return horizontal-layers)))
+(defmacro inc (x &optional (val 1))
+ `(setf ,x (+ ,val ,x)))
+
+;; For system arguments
+(defmacro when-option ((options opt) &body body)
+ `(let ((it (getf ,options ,opt)))
+ (when it
+ ,@body)))