Merge pull request '[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/cli/RFC.md fully. Find features des...' (#86) from agent/read---spec-code-core-go-cli-rfc-md-full into dev
All checks were successful
Security Scan / security (push) Successful in 21s
All checks were successful
Security Scan / security (push) Successful in 21s
This commit is contained in:
commit
9a80a604f4
2 changed files with 30 additions and 2 deletions
|
|
@ -304,7 +304,7 @@ func TestChoose_Bad_FilteredDefaultDoesNotFallBackToFirstVisible(t *testing.T) {
|
|||
defer SetStdin(nil)
|
||||
|
||||
val := Choose("Pick", []string{"apple", "banana", "apricot"}, WithDefaultIndex[string](1), Filter[string]())
|
||||
assert.Equal(t, "apricot", val)
|
||||
assert.Equal(t, "banana", val)
|
||||
}
|
||||
|
||||
func TestChoose_Bad_InvalidNumberUsesStderrHint(t *testing.T) {
|
||||
|
|
@ -333,7 +333,23 @@ func TestChooseMulti_Bad_FilteredDefaultDoesNotFallBackToFirstVisible(t *testing
|
|||
defer SetStdin(nil)
|
||||
|
||||
vals := ChooseMulti("Pick", []string{"apple", "banana", "apricot"}, WithDefaultIndex[string](1), Filter[string]())
|
||||
assert.Equal(t, []string{"apricot"}, vals)
|
||||
assert.Equal(t, []string{"banana"}, vals)
|
||||
}
|
||||
|
||||
func TestChoose_Good_ClearFilter(t *testing.T) {
|
||||
SetStdin(strings.NewReader("ap\n\n2\n"))
|
||||
defer SetStdin(nil)
|
||||
|
||||
val := Choose("Pick", []string{"apple", "banana", "apricot"}, Filter[string]())
|
||||
assert.Equal(t, "banana", val)
|
||||
}
|
||||
|
||||
func TestChooseMulti_Good_ClearFilter(t *testing.T) {
|
||||
SetStdin(strings.NewReader("ap\n\n2\n"))
|
||||
defer SetStdin(nil)
|
||||
|
||||
vals := ChooseMulti("Pick", []string{"apple", "banana", "apricot"}, Filter[string]())
|
||||
assert.Equal(t, []string{"banana"}, vals)
|
||||
}
|
||||
|
||||
func TestChooseMulti_Good_Commas(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -359,6 +359,7 @@ func Choose[T any](prompt string, items []T, opts ...ChooseOption[T]) T {
|
|||
for i := range items {
|
||||
visible[i] = i
|
||||
}
|
||||
allVisible := append([]int(nil), visible...)
|
||||
|
||||
for {
|
||||
renderChoices(prompt, items, visible, cfg.displayFn, cfg.defaultN, cfg.filter)
|
||||
|
|
@ -380,6 +381,11 @@ func Choose[T any](prompt string, items []T, opts ...ChooseOption[T]) T {
|
|||
}
|
||||
|
||||
if response == "" {
|
||||
if cfg.filter && len(visible) != len(allVisible) {
|
||||
visible = append([]int(nil), allVisible...)
|
||||
promptHint("Filter cleared.")
|
||||
continue
|
||||
}
|
||||
if idx, ok := defaultVisibleIndex(visible, cfg.defaultN); ok {
|
||||
return items[idx]
|
||||
}
|
||||
|
|
@ -453,6 +459,7 @@ func ChooseMulti[T any](prompt string, items []T, opts ...ChooseOption[T]) []T {
|
|||
for i := range items {
|
||||
visible[i] = i
|
||||
}
|
||||
allVisible := append([]int(nil), visible...)
|
||||
|
||||
for {
|
||||
renderChoices(prompt, items, visible, cfg.displayFn, -1, cfg.filter)
|
||||
|
|
@ -467,6 +474,11 @@ func ChooseMulti[T any](prompt string, items []T, opts ...ChooseOption[T]) []T {
|
|||
|
||||
// Empty response returns no selections
|
||||
if response == "" {
|
||||
if cfg.filter && len(visible) != len(allVisible) {
|
||||
visible = append([]int(nil), allVisible...)
|
||||
promptHint("Filter cleared.")
|
||||
continue
|
||||
}
|
||||
if idx, ok := defaultVisibleIndex(visible, cfg.defaultN); ok {
|
||||
return []T{items[idx]}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue