From dc669376bf02aef1f05c0efa41ab813c989cef85 Mon Sep 17 00:00:00 2001 From: venomade Date: Sun, 22 Nov 2026 09:57:33 +0000 Subject: [PATCH] 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. --- README.md | 1 + src/core.lisp | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d48d124..e22fabd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/core.lisp b/src/core.lisp index d0d3189..f2659be 100644 --- a/src/core.lisp +++ b/src/core.lisp @@ -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)