Skip to content

Add back-navigation support to all interactive renderers#14

Merged
ericof merged 2 commits intomainfrom
issue-10
Mar 29, 2026
Merged

Add back-navigation support to all interactive renderers#14
ericof merged 2 commits intomainfrom
issue-10

Conversation

@ericof
Copy link
Copy Markdown
Member

@ericof ericof commented Mar 29, 2026

Summary

  • Users can type < at any prompt to re-answer the previous question
  • A hint (type < to go back) is shown from the second question onward; no hint on the first question
  • Conditional questions respond correctly when the user goes back past a gating answer — the pipeline recomputes active questions on every iteration

Implementation

  • Form.unrecord(key) — removes an answer from form.answers and form._user_answers
  • Form.set_question_index(n) — sets the question index directly (used by the iterative loop)
  • _GoBackRequest(Exception) — sentinel raised by _ask_* methods; caught by _ask_questions
  • BaseRenderer._BACK_COMMAND = "<" — the back command string (override to change it)
  • BaseRenderer._back_hint() — returns a hint string when going back is available, empty string otherwise
  • BaseRenderer._iter_active_leaves() — recomputes active visible leaf questions dynamically each iteration
  • BaseRenderer._ask_questions() — refactored from recursive to iterative with a history: list[str] stack

All three interactive renderers (StdlibRenderer, RichRenderer, CookiecutterRenderer) implement the pattern. NoInputRenderer is unaffected.

Documentation

  • docs/src/reference/base-renderer.md — new "Back navigation" section documenting _GoBackRequest, _BACK_COMMAND, _back_hint(), and the implementation contract
  • docs/src/how-to-guides/create-renderer.md — example renderer updated to support back navigation; new "Support back navigation" section added
  • docs/src/tutorials/your-first-form.md — user-facing mention of the < command

Test plan

  • test_back_on_second_question_rerenders_first — basic back navigation
  • test_back_on_first_question_stays_at_first — no-op on first question
  • test_back_multiple_times — multiple back steps
  • test_back_from_boolean/choice/multiple_rerenders_previous_string — back across question types
  • test_back_past_gating_question_hides_conditional — conditional question hidden after back + re-select
  • test_back_past_gating_question_shows_conditional_on_reselect — conditional question shown after back + re-select
  • test_back_hint_not_shown_for_first_question / test_back_hint_shown_for_second_question

Closes #10

ericof added 2 commits March 28, 2026 21:10
Users can type < at any prompt to re-answer the previous question.
A contextual hint is shown from the second question onward.
Conditional questions respond correctly when a gating answer changes.
@ericof ericof merged commit c586823 into main Mar 29, 2026
11 checks passed
@ericof ericof deleted the issue-10 branch March 29, 2026 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "go back" navigation to the wizard

1 participant