useless stuff: add watch script

This commit is contained in:
xenia 2020-12-12 01:52:02 -05:00
parent 305fca6002
commit 087cfbf4c2
4 changed files with 47 additions and 2 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@
/inputs/*
!/inputs/.gitkeep
/.status.rktd
*.zo
*.dep

View File

@ -12,6 +12,7 @@ function init_day {
scripts/get-challenge $day &
sleep 1
scripts/make-day $day
tmux split-pane -v -- "bash -li <<< 'watch $day; exec</dev/tty'"
fg
return 1
fi

View File

@ -24,6 +24,6 @@
(module+ main
(define input (parse "inputs/@day"))
(answer @day 1 (part1 input))
(answer @day 2 (part2 input))
(answer @day 1 (time (part1 input)))
(answer @day 2 (time (part2 input)))
(displayln "meow"))

42
scripts/watch Executable file
View File

@ -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)))