Number the exercise list and add jump-to (wave 3, F5)

list-exercises prints 1-based right-aligned numbers. In watch mode, l lists the exercises and then asks Jump to (name or number, empty stays): a name or catalogue number switches to that exercise (revealed hints reset, :current saved), an empty answer or EOF stays, and unknown names or out-of-range numbers show a notice.

No new CLI command: run [name] already selects the exercise for
watch mode; usage and README note it.
This commit is contained in:
venomade committed 2026-11-22 10:02:00 +00:00
1 parent dc669376bf
commit 77843402fa
2 files changed
+52 -15

No files matched your search

+2 -2
View File
@@ -64,7 +64,7 @@ Keys in watch mode (each key is a line: type it, then press ENTER):
| n | move to the next pending exercise | | n | move to the next pending exercise |
| h | reveal the next hint paragraph (stays pinned) | | h | reveal the next hint paragraph (stays pinned) |
| r | rerun the current exercise | | r | rerun the current exercise |
| l | list all exercises | | l | list exercises, then jump by name or number |
| x | reset the current exercise (asks y/n) | | x | reset the current exercise (asks y/n) |
| q | save progress and quit | | q | save progress and quit |
@@ -78,7 +78,7 @@ solved.
```sh ```sh
./lisplings watch the current exercise (the default) ./lisplings watch the current exercise (the default)
./lisplings run [name] run one exercise and print its output ./lisplings run [name] run one exercise; also selects it as current
./lisplings hint [name] print every hint paragraph, numbered ./lisplings hint [name] print every hint paragraph, numbered
./lisplings list [pending|done|all] ./lisplings list [pending|done|all]
./lisplings reset <name> restore an exercise to its pristine state ./lisplings reset <name> restore an exercise to its pristine state
+50 -13
View File
@@ -431,14 +431,18 @@ on the fresh frame."
(defun list-exercises (filter) (defun list-exercises (filter)
(format t "~&~a~%" (bold "Lisplings exercises:")) (format t "~&~a~%" (bold "Lisplings exercises:"))
(dolist (ex *exercises*) (let ((width (length (format nil "~d" (max 1 (length *exercises*))))))
(when (ecase filter (loop for ex in *exercises*
(:all t) for number from 1
(:pending (not (exercise-done ex))) do (when (ecase filter
(:done (exercise-done ex))) (:all t)
(format t " ~a ~a~%" (:pending (not (exercise-done ex)))
(if (exercise-done ex) (green "✓ ") (yellow ". ")) (:done (exercise-done ex)))
(format nil "~a/~a" (exercise-dir ex) (exercise-name ex))))) (format t " ~vd ~a ~a~%"
width number
(if (exercise-done ex) (green "✓ ") (yellow ". "))
(format nil "~a/~a"
(exercise-dir ex) (exercise-name ex))))))
(format t "~&~%Pending: ~d of ~d. Progress: ~a~%~%" (format t "~&~%Pending: ~d of ~d. Progress: ~a~%~%"
(count-if (complement #'exercise-done) *exercises*) (count-if (complement #'exercise-done) *exercises*)
(length *exercises*) (length *exercises*)
@@ -506,6 +510,39 @@ and rerun it, on no (or EOF) just say so."
(setf (screen-state-notice state) "Reset cancelled.") (setf (screen-state-notice state) "Reset cancelled.")
(render-screen state)))))))) (render-screen state))))))))
(defun jump-prompt (state queue lock open-p)
"Jump to the exercise the user names or numbers after the list; an
empty answer (or EOF) stays on the current exercise."
(let ((answer (prompt-line "Jump to (name or number, empty stays): "
queue lock open-p)))
(cond ((or (null answer) (string= answer ""))
(render-screen state))
(t
(let ((number (ignore-errors (parse-integer answer :junk-allowed t))))
(cond ((and (integerp number)
(<= 1 number) (<= number (length *exercises*)))
(setf (screen-state-index state) (1- number)
(screen-state-revealed state) 0)
(set-current-name (exercise-name (nth (1- number) *exercises*)))
(run-and-show state queue lock))
((integerp number)
(setf (screen-state-notice state)
(format nil "No exercise number ~d." number))
(render-screen state))
(t
(let ((match (find answer *exercises* :key #'exercise-name
:test #'string=)))
(cond (match
(setf (screen-state-index state)
(position match *exercises*)
(screen-state-revealed state) 0)
(set-current-name (exercise-name match))
(run-and-show state queue lock))
(t
(setf (screen-state-notice state)
(format nil "No exercise matches '~a'." answer))
(render-screen state)))))))))))
(defun watch () (defun watch ()
(ensure-orig-snapshot) (ensure-orig-snapshot)
(unless (probe-file (state-path)) (unless (probe-file (state-path))
@@ -563,9 +600,9 @@ and rerun it, on no (or EOF) just say so."
(render-screen state)) (render-screen state))
((or (string-equal cmd "r") (string= cmd "")) ((or (string-equal cmd "r") (string= cmd ""))
(run-and-show state queue lock)) (run-and-show state queue lock))
((string-equal cmd "l") ((string-equal cmd "l")
(list-exercises :all) (list-exercises :all)
(render-screen state :clear nil)) (jump-prompt state queue lock open-p))
((string-equal cmd "x") ((string-equal cmd "x")
(reset-prompt state queue lock open-p)) (reset-prompt state queue lock open-p))
((string-equal cmd "q") ((string-equal cmd "q")
@@ -708,8 +745,8 @@ and rerun it, on no (or EOF) just say so."
(format t "Running lisplings with no command starts the watcher: it runs~%") (format t "Running lisplings with no command starts the watcher: it runs~%")
(format t "the current exercise and reruns it whenever you save the file.~%~%") (format t "the current exercise and reruns it whenever you save the file.~%~%")
(format t "Commands:~%") (format t "Commands:~%")
(format t " run [name] run one exercise and print its output~%") (format t " run [name] run one exercise, and select it for watch mode~%")
(format t " hint [name] print the hint for an exercise~%") (format t " hint [name] print every hint paragraph, numbered~%")
(format t " list [pending|done|all] list exercises with their status~%") (format t " list [pending|done|all] list exercises with their status~%")
(format t " reset <name> restore an exercise to its pristine state~%") (format t " reset <name> restore an exercise to its pristine state~%")
(format t " check-all run every exercise and resync progress~%") (format t " check-all run every exercise and resync progress~%")