Skip to content

feat(tui): Bash checkbox menu (#495 Slice 2) - #505

Merged
primetimetank21 merged 7 commits into
developfrom
squad/495-tui-picker-bash-slice-2
Aug 9, 2026
Merged

primetimetank21 merged 7 commits into
developfrom
squad/495-tui-picker-bash-slice-2

Conversation

@primetimetank21

@primetimetank21 primetimetank21 commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

Implements Slice 2 of #495: the Bash interactive checkbox menu for Linux/macOS/WSL.

Depends on merged #504 (Slice 1) — all non-interactive guards, TTY detection, and the --selection-file seam landed in Slice 1.

Part of #495


What ships in this PR

scripts/linux/lib/tui.sh (new)

Sourced by setup.sh. Two navigation modes:

  • Bash >=4.2: arrow up/down, Space to toggle, Enter to confirm, q/ESC to cancel. ANSI cursor repositioning redraws the list in place.
  • Bash 3.2 fallback: numbered-toggle line mode. _TUI_ARROW_NAV_OVERRIDE=0 env var forces this path for testing without needing a real bash 3.2 environment.

Default tools are pre-checked and labeled (default); opt-in tools (available but not default) are unchecked and labeled (opt-in), sorted alphabetically.

Cancel exits 0 with Install cancelled.
Empty confirm exits 0 with Nothing selected, exiting.
Selection feeds the existing build_final_toolset engine via ARG_ONLY; order is always preserved by DEFAULT_TOOLS sequence.

scripts/linux/setup.sh (modified)

  • Sources lib/tui.sh alongside lib/log.sh.
  • main() now calls show_tool_menu when interactive, or reads from --selection-file (CI seam) without rendering the menu.
  • Updated stale Slice 1 comment.

tests/test_tui_bash.sh (new)

16 assertions across 14 named tests covering:

Test Type Covers
T_tui_sh_sources_clean smoke tui.sh sources without error
T_menu_resolve_defaults integration all defaults selected → run-log == defaults.txt
T_menu_resolve_subset integration reversed-input subset → order preserved
T_menu_resolve_optin integration opt-in tool appended after defaults
T_menu_resolve_empty integration empty selection → exit 0, "Nothing selected"
T_menu_selection_file_e2e integration selection-file seam → correct ordered run-log
T_menu_cancel_aborts unit _MENU_CANCELLED=1 guard → exit 0
T_menu_noop_empty unit empty _MENU_SELECTION guard → exit 0, correct message
T_numbered_render_runs unit _tui_numbered_render draws list with states and labels
T_render_list_runs unit _tui_render_list renders cursor, checkboxes, labels
T_noninteractive_compat regression --non-interactive still runs defaults (Slice 1 compat)
T_selection_file_no_noninteractive_conflict regression --non-interactive + --selection-file → error
T_help_no_selection_file regression --help does not expose hidden --selection-file
T_arrow_redraw_stable regression ANSI redraw emits CSI ${N}A (not ${N+1}A); no viewport creep

Excluded from this PR

  • Slice 3: PowerShell 5.1 ASCII menu (lib/tui.ps1, Resolve-FinalToolset). Separate branch.
  • Slice 4: docs additions (README, ARCHITECTURE). No changes to those files in this PR.
  • No changes to PowerShell scripts, docs, or CI workflow files.

CI validation

ShellCheck passes locally via pre-commit hook and pre-push hook (both ran successfully on commit and push).

CI will run on Ubuntu (bash 5.x) and macOS (bash 3.2):

  • lint-shell-scripts job: shellcheck on setup.sh + tools; test_setup_flags.sh
  • validate-linux / validate-macos: existing install and flag tests

test_tui_bash.sh is wired into validate-linux (Ubuntu, bash 5.x) and validate-macos (macOS, bash 3.2) via a Run TUI bash menu tests step in .github/workflows/validate.yml. All 16 assertions (14 named tests) gate both jobs on every push and pull request.


Fix: ANSI viewport drift on keypress (addressed in review)

Symptom: the terminal scrolled upward on every keypress during arrow-mode navigation.

Root cause: the redraw cursor-up escape used count + 1 lines, but _tui_render_list emits exactly count lines. The static instruction header (3 lines printed once before the loop) was not part of the redrawn region, so each keypress consumed one header line into the clear zone. After 3 keypresses CSI ${N+1}A overshot row 0, causing the terminal to scroll.

Fix: extracted the redraw sequence into _tui_arrow_redraw and changed the cursor-up delta to count (matching the render output exactly). The static header remains printed once and is never redrawn.

Regression test: T_arrow_redraw_stable calls _tui_arrow_redraw directly, captures raw output bytes via od, and asserts CSI 3A (0x1b 0x5b 0x33 0x41) is present and CSI 4A (the buggy byte sequence) is absent.


Manual verification required (not covered by automated tests)

The following cases require a live interactive TTY and are not verified by CI or this PR's automated tests:

  1. Arrow-key navigation on bash 5.x (Ubuntu/Linux terminal) — up/down moves cursor, Space toggles, Enter confirms.
  2. ANSI in-place redraw in tmux / screen, and in mintty / Git Bash on Windows — list redraws stably in place with no upward viewport drift on successive keypresses.
  3. Numbered-toggle mode on macOS bash 3.2 (Terminal.app) — enter a number, a, Enter, q.
  4. ESC / Q cancel from within the rendered menu.
  5. "All defaults checked + Enter" produces identical install to a no-arg run.
  6. Opt-in tool checked produces correct install appended after defaults.

primetimetank21 and others added 2 commits August 5, 2026 03:29
Add scripts/linux/lib/tui.sh: interactive checkbox menu sourced by setup.sh.
- Bash >=4.2: arrow-key navigation, Space toggle, Enter confirm, q/ESC cancel
- Bash 3.2: numbered-toggle fallback (no fractional timeout, no mapfile, no local -n)
- Version detection via BASH_VERSION; _TUI_ARROW_NAV_OVERRIDE seam for tests
- Default tools pre-checked, opt-in tools unchecked and labeled
- Cancel sets _MENU_CANCELLED=1, exits 0 with "Install cancelled."
- Empty confirm exits 0 with "Nothing selected, exiting."
- Selection feeds existing --only engine; order preserved by build_final_toolset

Wire show_tool_menu into setup.sh main():
- --interactive + --selection-file: CI-testable seam, bypasses TTY guard
- Headless/CI/default/--non-interactive paths unchanged (Slice 1 compat)

Add tests/test_tui_bash.sh:
- T_tui_sh_sources_clean, T_menu_resolve_defaults, T_menu_resolve_subset
- T_menu_resolve_optin, T_menu_resolve_empty, T_menu_selection_file_e2e
- T_menu_cancel_aborts, T_menu_noop_empty, T_numbered_render_runs
- T_render_list_runs, T_noninteractive_compat
- T_selection_file_no_noninteractive_conflict, T_help_no_selection_file

Part of #495
Depends on merged #504 (Slice 1)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…495)

Add 'Run TUI bash menu tests' step to validate-linux and validate-macos
jobs so all 13 Slice 2 tests gate CI on both platforms. No new jobs or
dependencies. Corrects omission from Hardcase's Slice 2 commit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
primetimetank21 and others added 3 commits August 7, 2026 05:25
…ression test

The arrow-mode redraw used cursor-up count+1, but _tui_render_list emits
exactly count lines. The 3-line static header (blank + instruction + blank)
printed once before the loop was progressively consumed into the cleared
region on each keypress. After 3 keypresses CSIA overshot row 0 and
the terminal scrolled upward on every subsequent key event.

Fix:
- Extract the three-line redraw sequence into _tui_arrow_redraw (move-up N,
  clear-to-end, render list), which makes the operation independently
  callable and directly testable.
- Use cursor-up delta == count (not count+1). Header is static and remains
  anchored above the redrawn region.

Regression test (T_arrow_redraw_stable):
- Confirms _tui_render_list emits exactly N lines for N tools.
- Calls _tui_arrow_redraw directly, captures raw stdout bytes via od, and
  asserts CSI 3A (0x1b5b3341) present and CSI 4A (0x1b5b3441, the buggy
  byte sequence) absent. Fails on the pre-fix inline code; passes on the
  extracted helper.

16 assertions / 14 named tests. ShellCheck clean.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract _tui_checked_toggle_all and _tui_arrow_handle_key as independently
testable pure functions. _tui_arrow_mode now delegates all key dispatch to
_tui_arrow_handle_key; _tui_numbered_mode reuses the same toggle-all helper
for consistent behavior across both nav paths.

Add a/A toggle-all dispatch to arrow mode (was previously absent); arrow
mode now supports the full keyset: Up/Down navigation with boundary clamps,
Space to toggle the cursor item, Enter to confirm, a/A to toggle-all, and
q/Q/ESC to cancel.

Stable redraw fix (cursor-up delta = N, not N+1) and the ANSI byte
regression guard are preserved from the previous commit.

Test suite expands to 32 assertions covering:
- none-to-all state transition via arrow-mode dispatch ('a' on '0 0 0')
- uppercase Q cancel dispatch (cancelled=1, done=0)
- bare ESC cancel dispatch (cancelled=1, done=0)
- Up/Down movement and boundary clamps, Space toggle, Enter done, noop
- _tui_arrow_redraw ANSI byte invariants (ESC[3A present, ESC[4A absent)
- E2E selection-file, subset ordering, opt-in placement, cancel/noop guards
All 32 pass; ShellCheck clean.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Arrow mode is gated at Bash >=4.2 in production; the three toggle-all
assertions (a-lower-none, a-lower-mixed, A-upper) produce empty output
on Bash 3.2 and falsely fail.  Add a BASH_VERSINFO version guard that
records proper skips on Bash <4.2 using the suite's existing skip()
convention.  No production code is changed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@primetimetank21

Copy link
Copy Markdown
Owner Author

Manual validation completed successfully. Verified stable viewport behavior: A selects all then clears all; Q/Esc cancellation; final run-log behavior. All six CI jobs passed. Independent review approved.

@primetimetank21
primetimetank21 marked this pull request as ready for review August 7, 2026 10:38
primetimetank21 and others added 2 commits August 9, 2026 03:29
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Integrate the merged PowerShell TUI slice while preserving Bash TUI CI coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@primetimetank21
primetimetank21 merged commit 3bf0ce1 into develop Aug 9, 2026
10 checks passed
@primetimetank21
primetimetank21 deleted the squad/495-tui-picker-bash-slice-2 branch August 10, 2026 02:43
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.

1 participant