Created
May 8, 2018 22:58
-
-
Save jasonrobot/fecc0da6f29fa6f5136376876a14dca0 to your computer and use it in GitHub Desktop.
Simple command line invoked timer. I plan to add some way of notifying.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/sbcl --script | |
;;; Documentation: | |
;;; Commentary: | |
;;; Code: | |
(defun timer-tick () | |
"Waits for 1 second" | |
(sleep 1)) | |
(defun update-display (time-left) | |
"Write TIME-LEFT to stdout, replacing whatever was on the last line previously." | |
(format t "~C~D" #\return time-left) | |
(finish-output)) | |
(defun run-timer (time) | |
"Runs a countdown timer for TIME seconds." | |
(loop | |
for current-time | |
from time | |
downto 1 | |
do (progn | |
(update-display current-time) | |
(timer-tick))) | |
(format t "~CDone!" #\return)) | |
(defun my-command-line () | |
"Reads command line args." | |
(or | |
#+CLISP *args* | |
#+SBCL *posix-argv* | |
#+LISPWORKS system:*line-arguments-list* | |
#+CMU extensions:*command-line-words* | |
nil)) | |
;;; Script: | |
(let ((time (parse-integer (elt (my-command-line) 1)))) | |
(run-timer time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment