Last active
November 28, 2016 02:02
-
-
Save glider-gun/2286e38fe787e9792890 to your computer and use it in GitHub Desktop.
mock watch command (because OS X's original watch command can't display Japanese chars...)
This file contains hidden or 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
#!/bin/sh | |
#|-*- mode:lisp -*-|# | |
#| | |
exec ros -Q -- $0 "$@" | |
|# | |
;; $ watch -n 10 date | |
;; $ ./watch.ros 10 date | |
(ql:quickload '(:cl-charms :external-program) :silent t) | |
(defun main (&rest argv) | |
(declare (ignorable argv)) | |
(charms:with-curses () | |
(multiple-value-bind (width height) | |
(charms:window-dimensions charms:*standard-window*) | |
(declare (ignorable width height)) | |
(charms:clear-window charms:*standard-window*) | |
(let ((n (read-from-string (car argv))) | |
(cmd (cadr argv)) | |
(args (cddr argv))) | |
(handler-case | |
(loop | |
(charms:move-cursor charms:*standard-window* 0 0) | |
(charms:write-string-at-cursor charms:*standard-window* | |
(format nil "~A, ~A ~:A~%" n cmd args)) | |
(loop with proc = (external-program:start cmd args :output :stream) | |
with s = (external-program:process-output-stream proc) | |
for l = (read-line s nil nil) | |
for y from 1 | |
while (and (or l | |
(eq (external-program:process-status proc) :running)) | |
(< y height)) | |
do | |
(progn (ignore-errors | |
(charms:write-string-at-cursor charms:*standard-window* | |
(format nil "~A~%" l))))) | |
(charms:refresh-window charms:*standard-window*) | |
(sleep n)) | |
(sb-sys:interactive-interrupt ())))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment