Add watch key x: reset the current exercise (wave 3, F4)
x asks y/n through the shared input queue. On yes it restores the pristine copy from .lisplings-orig/, unmarks done, and reruns: the restored exercise fails its checks again, as it should. On no (or EOF) it says so and stays. A missing pristine copy (an exercise added after the snapshot) shows a notice instead of crashing, both in watch mode and in the one-shot reset command. The valid-key legend gains x, and the README keys table documents it.
This commit is contained in:
1 parent
04e313a915
commit
dc669376bf
2 files changed
+37
-7
No files matched your search
@@ -65,6 +65,7 @@ Keys in watch mode (each key is a line: type it, then press ENTER):
|
||||
| h | reveal the next hint paragraph (stays pinned) |
|
||||
| r | rerun the current exercise |
|
||||
| l | list all exercises |
|
||||
| x | reset the current exercise (asks y/n) |
|
||||
| q | save progress and quit |
|
||||
|
||||
Keys typed while a check is running are ignored; press the key
|
||||
|
||||
+36
-7
@@ -323,8 +323,8 @@ explain why that is not possible."
|
||||
(push "n next" keys))
|
||||
(when (< revealed total)
|
||||
(push (format nil "h hint (~d/~d)" (1+ revealed) total) keys))
|
||||
(dolist (k '("r rerun" "l list" "q quit"))
|
||||
(push k keys))
|
||||
(dolist (k '("r rerun" "l list" "x reset" "q quit"))
|
||||
(push k keys))
|
||||
(nreverse keys)))
|
||||
|
||||
(defun render-screen (state &key (clear t))
|
||||
@@ -484,6 +484,28 @@ the queue. Returns NIL at EOF."
|
||||
((null (car open-p)) (return nil))
|
||||
(t (sleep 0.05))))))
|
||||
|
||||
(defun reset-prompt (state queue lock open-p)
|
||||
"Ask y/n; on yes restore the pristine copy of the current exercise
|
||||
and rerun it, on no (or EOF) just say so."
|
||||
(let ((ex (current-exercise state)))
|
||||
(cond ((not (probe-file (orig-path ex)))
|
||||
(setf (screen-state-notice state)
|
||||
(format nil "No pristine copy of ~a under .lisplings-orig/; cannot reset."
|
||||
(exercise-name ex)))
|
||||
(render-screen state))
|
||||
(t
|
||||
(let ((answer (prompt-line
|
||||
(format nil "Reset restores exercises/~a/~a.lisp from .lisplings-orig/. Reset? (y/n) "
|
||||
(exercise-dir ex) (exercise-name ex))
|
||||
queue lock open-p)))
|
||||
(cond ((and answer (member answer '("y" "yes") :test #'string-equal))
|
||||
(copy-file (orig-path ex) (exercise-path ex))
|
||||
(unmark-done ex)
|
||||
(run-and-show state queue lock))
|
||||
(t
|
||||
(setf (screen-state-notice state) "Reset cancelled.")
|
||||
(render-screen state))))))))
|
||||
|
||||
(defun watch ()
|
||||
(ensure-orig-snapshot)
|
||||
(unless (probe-file (state-path))
|
||||
@@ -544,6 +566,8 @@ the queue. Returns NIL at EOF."
|
||||
((string-equal cmd "l")
|
||||
(list-exercises :all)
|
||||
(render-screen state :clear nil))
|
||||
((string-equal cmd "x")
|
||||
(reset-prompt state queue lock open-p))
|
||||
((string-equal cmd "q")
|
||||
(return-from watch-loop))
|
||||
(t
|
||||
@@ -609,11 +633,16 @@ the queue. Returns NIL at EOF."
|
||||
(defun reset-command (name)
|
||||
(let ((ex (resolve-exercise name)))
|
||||
(ensure-orig-snapshot)
|
||||
(copy-file (orig-path ex) (exercise-path ex))
|
||||
(unmark-done ex)
|
||||
(format t "~&The exercise ~a has been reset.~%" (exercise-name ex))
|
||||
(format t "~&(It now matches the pristine copy from when lisplings first ran here.)~%")
|
||||
(sb-ext:exit :code 0)))
|
||||
(cond ((not (probe-file (orig-path ex)))
|
||||
(format t "~&No pristine copy of ~a under .lisplings-orig/; cannot reset.~%"
|
||||
(exercise-name ex))
|
||||
(sb-ext:exit :code 1))
|
||||
(t
|
||||
(copy-file (orig-path ex) (exercise-path ex))
|
||||
(unmark-done ex)
|
||||
(format t "~&The exercise ~a has been reset.~%" (exercise-name ex))
|
||||
(format t "~&(It now matches the pristine copy from when lisplings first ran here.)~%")
|
||||
(sb-ext:exit :code 0)))))
|
||||
|
||||
(defun check-all-command ()
|
||||
(ensure-orig-snapshot)
|
||||
|
||||
Reference in new issue
Block a user