Repository navigation
Conversation
Automated AI review
Verified:
One option shape does not invert correctly, so the "never a wrong row" guarantee does not hold in general. It does not affect the two callers converted here. An empty trailing subtext produces a wrong index or a false "matches no option"
Synthetic options (
Impact: Neither caller converted here produces tabs, so nothing changes for users in this PR. The glyph/label/subtext shape is what later callers would pass (for example, Suggested change: After dropping the glyph, mirror line 768 by removing a trailing tab when it is the only one left: returned="${options[index]#*$'\t'}"
label="${returned%%$'\t'*}"
if [[ $returned == "$label"$'\t' ]]; then
returned="$label"
fiWith this change plus the key prefix suggested below, all 11 existing assertions still pass, the picks above return the correct index, and the two ambiguous lists are refused before the menu opens. One assertion such as Related edge case (trailing newline): an option argument that ends in a newline ( An empty returned text aborts with bash's own errorUnder Impact: The failure is loud, not a wrong row, but one stray blank line in piped input rejects the whole list with an internal error. Suggested change: Prefix the keys (for example Documentation note: Review informationTest scope: Command-only runs in an isolated sandbox on GNU bash 5.3.15. The menu was stood in for by the PR's own test stub and by a model of AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments, Opus 5.5 Medium editorial check. Opt out: To stop receiving these reviews, reply to this comment saying so. |
omarchy-menu-select answers with the text of the row it displayed, so a caller that needs an id cuts it back out of that text. The webcam picker and the RetroArch core picker both do, and each one breaks as soon as the label it parses is written any other way. --print-index answers with the position of the choice in the list the caller passed in, leaving the id to be looked up in the caller's own data. The key it maps has to be exactly what the menu sends back, which means dropping the trailing tab the menu drops along with an empty subtext, and taking off the one trailing newline the menu adds rather than every one of them. It refuses a list whose options cannot be told apart by what comes back, or one holding an option that comes back as nothing, which would be a blank row and is not a key bash will take. It fails rather than guess when the answer matches no option.
4682cb7 to
03837a4
Compare
|
All three taken, and the caveat in your test-scope note is gone: the newline case now reproduces through this PR's own harness rather than only against a model. The branch is rebased onto What changed
11 Why the newline case was invisible to the harness, and is not now. Why the keys are not prefixed. Prefixing would work, and it would accept these lists rather than refuse them. I refused instead because a row that comes back as nothing is a blank row on screen: exact or not, its index is not an answer anyone wants to act on, and a caller that piped in a stray blank line is better off hearing which line. That is a judgement about what the list ought to contain, not about what is recoverable, so if a maintainer would rather blank rows be accepted, the prefix is the change, plus a way for the stub to tell an empty answer apart from no answer, since A claim in the PR body that your review disprovedThe body said "every pathological option shape is a loud error, never a wrong row". Two of the shapes in your table returned a wrong row silently, so that was false when written, and stating it that broadly was the mistake rather than a slip in wording. The body now says what is actually pinned: the shapes the assertions cover, and that the guarantee rests on the key matching For the record, both sides of your table, run through the harness with the faithful stub, at the old head and at this commit:
How this was run
Each of the three changes to Two things worth knowing if you re-run it. 🤖 Generated with Claude Code |
|
|
omarchy-menu-selectanswers with the text of the row the menu displayed. A caller that needs an id rather than a label therefore has to cut the id back out of that text, which makes the display string a protocol.Two callers do exactly that today:
Each breaks the first time its row is written any other way: a core label with a second parenthesis, a device label with the name first. Neither is a defect today, and neither changes behaviour in this PR. The point is that the fragile coupling goes away.
--print-indexanswers with the position of the choice in the list the caller passed in, so the caller looks the id up in its own array:The string surgery is still there, but now it runs on a line the caller built rather than on a string that came back from the UI, which is free to gain a glyph, a subtext, or a translation later.
No QML change. The inversion runs entirely in
omarchy-menu-select. What the menu returns is the option with everything up to its first tab removed, which isshell/plugins/menu/Menu.qml:568-571(split("\t"), shift the glyph when there is more than one field, keep the rest) rejoined at:768. That is${option#*$'\t'}in bash, with two details the join adds::768omits the tab when the subtext is empty, and:132writes the answer throughprintf '%s\n'. So the key drops that trailing tab, and the read takes off exactly one trailing newline rather than every one. With those, bash maps an answer back to a position without the menu knowing anything new. That also keeps this PR clear of #12338, which is open on the same file.It refuses to guess. Mapping an answer back to a position is only sound while every option comes back as different, non-empty text.
--print-indexbuilds that map before summoning the menu and exits 1 with a message if two options would collide, or if one would come back as nothing, so an ambiguous list fails without ever showing the user a menu whose answer would be acted on wrongly. If the selection matches no option it also fails rather than print a position.That holds only while the key matches
Menu.qml's returned text byte for byte, which is what the assertions pin and what a change to that file could break. @llstrk's review found two shapes where it did not hold: an option whose subtext is empty, and one ending in a newline. Each returned a wrong row silently. Both are fixed and both have an assertion.The flag has to come before the prompt, since every argument after the prompt is an option.
omarchy-menu-images --print-namealready has this shape, so the pattern is not new.docs/menu.mdgains a paragraph describing the flag, next to the select protocol it inverts.test/shell.d/menu-select-test.shis new: 15 assertions, covering plain options, options fed on stdin, glyph-prefixed options, same-label-different-subtext rows, an option whose subtext is empty and one ending in a newline, the shapes that are refused, the unchanged answer when the flag is absent, dismissal, a selection matching nothing, and the two callers actually passing the flag. The stub stands in foromarchy-shelland replays the QML transformation in perl, including the trailing newlineMenu.qml:132writes and the empty file a cancel leaves, so what the test pins is the returned-text contract rather than this implementation of it../test/cliand./test/shellwere run at this commit and atb421b1b4on bash 5.3.15 (Arch), same box, each in its own worktree. Both sides end with the same 8 failing assertions, and a per-file comparison across both suites differs in exactly one line,menu-select-test.sh ok=15 notok=0, present here and absent at the base because the file is new. Neither suite passes on a plain checkout, so that is a differential rather than a clean run. The existingtest/shell.d/screenrecording-test.shpasses with its stub updated to answer with a position. Reverting any one of the three changes tobin/omarchy-menu-selectstops the new file at that change's own assertion, so the assertions do bite.Follow-up to #12345 §7, sent on its own as promised there. It is the mechanism the rest of that issue's §7 items depend on, which is why it comes first even though nothing user-visible moves.
🤖 Generated with Claude Code