useless stuff: add watch script
This commit is contained in:
parent
305fca6002
commit
087cfbf4c2
|
@ -2,3 +2,5 @@
|
||||||
/inputs/*
|
/inputs/*
|
||||||
!/inputs/.gitkeep
|
!/inputs/.gitkeep
|
||||||
/.status.rktd
|
/.status.rktd
|
||||||
|
*.zo
|
||||||
|
*.dep
|
||||||
|
|
|
@ -12,6 +12,7 @@ function init_day {
|
||||||
scripts/get-challenge $day &
|
scripts/get-challenge $day &
|
||||||
sleep 1
|
sleep 1
|
||||||
scripts/make-day $day
|
scripts/make-day $day
|
||||||
|
tmux split-pane -v -- "bash -li <<< 'watch $day; exec</dev/tty'"
|
||||||
fg
|
fg
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
(module+ main
|
(module+ main
|
||||||
(define input (parse "inputs/@day"))
|
(define input (parse "inputs/@day"))
|
||||||
(answer @day 1 (part1 input))
|
(answer @day 1 (time (part1 input)))
|
||||||
(answer @day 2 (part2 input))
|
(answer @day 2 (time (part2 input)))
|
||||||
(displayln "meow"))
|
(displayln "meow"))
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
#!/usr/bin/env racket
|
||||||
|
#lang racket
|
||||||
|
|
||||||
|
(require racket/rerequire racket/runtime-path)
|
||||||
|
|
||||||
|
(define (reinvoke file)
|
||||||
|
(displayln "invoking module")
|
||||||
|
(define p (build-path file))
|
||||||
|
(dynamic-rerequire p)
|
||||||
|
(dynamic-require (list 'submod p 'main) #f)
|
||||||
|
(displayln "invocation complete"))
|
||||||
|
|
||||||
|
(define (watch-forever file)
|
||||||
|
(sleep 0.2)
|
||||||
|
(define chg-evt (filesystem-change-evt file (lambda ()
|
||||||
|
(displayln "error watching file...")
|
||||||
|
(sleep 1) (watch-forever file))))
|
||||||
|
(define runner (thread (lambda () (reinvoke file))))
|
||||||
|
|
||||||
|
(define (handle-break _)
|
||||||
|
(cond
|
||||||
|
[(sync/timeout 0 runner)
|
||||||
|
(displayln "exiting")
|
||||||
|
(exit)]
|
||||||
|
[else
|
||||||
|
(displayln "killing module")
|
||||||
|
(kill-thread runner)
|
||||||
|
(filesystem-change-evt-cancel chg-evt)]))
|
||||||
|
|
||||||
|
(with-handlers ([exn:break? handle-break])
|
||||||
|
(sync chg-evt)
|
||||||
|
(kill-thread runner))
|
||||||
|
(watch-forever file))
|
||||||
|
|
||||||
|
(define-runtime-path aoc "aoc.rkt")
|
||||||
|
(command-line
|
||||||
|
#:program "watch"
|
||||||
|
#:args (day)
|
||||||
|
(displayln "warming up")
|
||||||
|
(dynamic-require aoc #f)
|
||||||
|
(displayln "ready to go!")
|
||||||
|
(watch-forever (format "~a.rkt" day)))
|
Loading…
Reference in New Issue