diff --git a/src/utils.lisp b/src/utils.lisp index 9e362cb..2a1a702 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -11,6 +11,7 @@ :safe-first :safe-list :group :restartable + :loop-with-progress :add-hook :remove-hook :run-hook :update-current-time :get-delta-time :make-clock :clock-time :clock-delta @@ -63,6 +64,20 @@ ,@body) (continue () :report "Continue")))) +(defmacro loop-with-progress (msg &body body) + "Allow a looping process to display feedback." + `(macrolet ((progress-step () + `(progn + (when (> progress-index progress-max-columns) + (format t "~%") + (setf progress-index 0)) + (format t ".")))) + (let ((progress-max-columns 80)) + (format t ,msg) + (loop for progress-index upfrom ,(length msg) + ,@body) + (format t "~%")))) + (defmacro add-hook (hook fun &optional append) "Setup `fun' to be called within specified `hook'." `(unless (member ,fun ,hook)