Skip to content

Make Select and MultiSelect item and limit handling consistent - #430

Merged
shibayan merged 2 commits into
masterfrom
select-limits
Oct 21, 2026
Merged

shibayan merged 2 commits into
masterfrom
select-limits

Conversation

@shibayan

Copy link
Copy Markdown
Owner

Summary

Closes #410.

#403 and #417 already covered part of this issue:

  • one snapshot of Items for rendering and the result
  • DefaultValues outside Items are ignored
  • Ctrl+A / Ctrl+I that would exceed Maximum are rejected as a whole
  • empty lists no longer divide by zero

This PR covers the remaining boundary conditions and documents the rules.

Changes

  • Duplicate items (Select and MultiSelect): equal items (EqualityComparer<T>.Default) are listed once, at the position of the first.

    • Before, checking one of several equal items in MultiSelect checked all of them, and the result returned each one. With Items = ["a", "a"] and Maximum = 1, Enter returned two items, and Minimum counted distinct items while the result did not.
  • Options that make the prompt unanswerable now throw before it is shown:

    Options Exception Before
    Select with no items ArgumentException (Items) Shown, but Enter was always rejected
    MultiSelect with Minimum > item count (after duplicates are removed) ArgumentOutOfRangeException (Minimum) Shown, but Enter was always rejected

    With these options, the only way out was to cancel. When ThrowExceptionOnCancel is false, canceling calls Environment.Exit(1). An empty MultiSelect with Minimum = 0 still works.

  • Validation before the driver is created: options are validated and Items is snapshotted in a static Prepare that runs before the base constructor creates the console driver. Before, invalid options (for example, a negative Minimum) threw after the driver was created, and the driver was never disposed.

  • Japanese message fix: Validation_Minimum_OutOfRange referenced {1} with a single argument. In the ja culture, a negative Minimum threw FormatException instead of ArgumentOutOfRangeException.

  • New messages: for the two new exceptions, in en, ja, de-DE, and zh-Hans.

  • Docs (en/ja):

    • Select: "Item Rules" (snapshot and duplicates, DefaultValue, Enter and filter selection, empty items).
    • MultiSelect: "Selection Rules", with a table of how Minimum and Maximum apply to Space, Ctrl+A / Ctrl+I, DefaultValues, and Enter.

Compatibility

Testing

  • New FormInteractionTests:
    • empty Select and Minimum > items, including duplicates and empty Items, throw without creating the console driver
    • invalid options also throw without creating the console driver
    • limit errors format correctly in ja-JP, de-DE, and zh-Hans
    • duplicates in Select, MultiSelect, and Ctrl+A with Maximum = 1
  • All 11 new cases fail on master.
  • dotnet build, dotnet test (1246 passed), and dotnet format --verify-no-changes
  • Native AOT verification (net10.0, win-x64): 65/65
  • VitePress docs build

🤖 Generated with Claude Code

- Equal items are listed once, at the position of the first. In
  MultiSelect, checking one of several equal items checked all of them
  and returned each, so the result could exceed Maximum and disagree with
  the Minimum check.
- Options that leave the prompt unanswerable now throw before it is
  shown: an empty Select (ArgumentException) and a MultiSelect whose
  Minimum exceeds the number of items (ArgumentOutOfRangeException).
  Before, the user could only cancel, which exits the process when
  ThrowExceptionOnCancel is false.
- Options are validated and Items are snapshotted before the base
  constructor creates the console driver, so invalid options no longer
  leave it undisposed.
- The Japanese invalid-minimum message referenced {1} with a single
  argument and threw FormatException instead of the intended
  ArgumentOutOfRangeException.
- Docs (en/ja) describe the item rules and how Minimum and Maximum apply
  to each MultiSelect operation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 07:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Static review found no blocking issues; the remaining documentation clarification is nonblocking.

1 open issue
1 file not reviewed
  • src/Sharprompt/Strings/Resource.Designer.cs: Generated file
What changed in this PR

Makes Select and MultiSelect boundary behavior consistent and documents compatibility changes.

Changes:

  • Deduplicates items and rejects unanswerable options before creating the console driver.
  • Adds localized validation messages and fixes Japanese error formatting.
  • Adds regression tests and English/Japanese selection rules.
File Description
tests/​Sharprompt.Tests/​Forms/​FormInteractionTests.cs Tests duplicates, validation timing, and localized errors.
src/​Sharprompt/​Strings/​Resource.zh-Hans.resx Adds Chinese validation messages.
src/​Sharprompt/​Strings/​Resource.resx Adds default validation messages.
src/​Sharprompt/​Strings/​Resource.ja.resx Adds Japanese messages and fixes a placeholder.
src/​Sharprompt/​Strings/​Resource.Designer.cs Exposes new resource strings.
src/​Sharprompt/​Strings/​Resource.de-DE.resx Adds German validation messages.
src/​Sharprompt/​Forms/​SelectForm.cs Deduplicates items and validates before driver creation.
src/​Sharprompt/​Forms/​MultiSelectForm.cs Deduplicates items and rejects impossible minimums early.
docs/​ja/​prompt-types/​select.md Documents Select rules in Japanese.
docs/​ja/​prompt-types/​multi-select.md Documents MultiSelect rules in Japanese.
docs/​en/​prompt-types/​select.md Documents Select rules in English.
docs/​en/​prompt-types/​multi-select.md Documents MultiSelect rules in English.

Review effort: Balanced

Comment thread docs/en/prompt-types/select.md Outdated
An unmatched DefaultValue does not select anything, but when only one item
is listed, with or without a filter, that item is selected, so Enter
returns it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 07:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved issues were identified, and the implementation, regression coverage, and documentation consistently address the intended boundary conditions.

No open issues 🎉

1 resolved since last review
1 file not reviewed
  • src/Sharprompt/Strings/Resource.Designer.cs: Generated file

Review effort: Balanced

@shibayan
shibayan merged commit 2faa027 into master Oct 21, 2026
10 checks passed
@shibayan
shibayan deleted the select-limits branch October 21, 2026 07:51
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.

Make selection data and limit handling consistent in Select/MultiSelect

2 participants