-
Notifications
You must be signed in to change notification settings - Fork 155
feat(core + prompts): adds autocomplete #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5b2f38a
feat: adds autocomplete
dreyfus92 0f4aa04
Apply suggestions from @MacFJA and @natemoo.re reviews
dreyfus92 e207c32
Merge branch 'main' into feat/autocomplete
dreyfus92 6ae902c
add: missing changes after merge
dreyfus92 d7523e3
chore: use selectedValue getter
43081j 74ffae6
chore: run format
43081j 9b1ebc5
core rework/simplification (#308)
43081j e3ef952
Apply suggestions from @43081j & @MacFJA's review
dreyfus92 4eebe3c
Apply suggestions from @43081j's review
dreyfus92 3a16bcb
tests: refactor autocomplete prompt tests to avoid core functionality…
dreyfus92 6f11483
format
dreyfus92 a65db40
fix: handle undefined values in text prompts
43081j 0c034ff
Apply suggestions from @43081j's review
dreyfus92 2dfbdf8
Apply suggestions from @43081j's review
dreyfus92 984a92d
remove: overflowFormat param from LimitOptionsParams interface
dreyfus92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
packages/prompts/test/__snapshots__/autocomplete.test.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
|
||
| exports[`autocomplete > limits displayed options when maxItems is set 1`] = ` | ||
| [ | ||
| "<cursor.hide>", | ||
| "[90m│[39m | ||
| [36m◆[39m Select a fruit | ||
|
|
||
| [36m│[39m [2mSearch:[22m [7m[8m_[28m[27m | ||
| [36m│[39m [32m●[39m Apple | ||
| [36m│[39m [2m○[22m [2mBanana[22m | ||
| [36m│[39m [2m○[22m [2mCherry[22m | ||
| [36m│[39m [2m○[22m [2mGrape[22m | ||
| [36m│[39m [2m○[22m [2mOrange[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| ] | ||
| `; | ||
|
|
||
| exports[`autocomplete > renders initial UI with message and instructions 1`] = ` | ||
| [ | ||
| "<cursor.hide>", | ||
| "[90m│[39m | ||
| [36m◆[39m Select a fruit | ||
|
|
||
| [36m│[39m [2mSearch:[22m [7m[8m_[28m[27m | ||
| [36m│[39m [32m●[39m Apple | ||
| [36m│[39m [2m○[22m [2mBanana[22m | ||
| [36m│[39m [2m○[22m [2mCherry[22m | ||
| [36m│[39m [2m○[22m [2mGrape[22m | ||
| [36m│[39m [2m○[22m [2mOrange[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| ] | ||
| `; | ||
|
|
||
| exports[`autocomplete > shows hint when option has hint and is focused 1`] = ` | ||
| [ | ||
| "<cursor.hide>", | ||
| "[90m│[39m | ||
| [36m◆[39m Select a fruit | ||
|
|
||
| [36m│[39m [2mSearch:[22m [7m[8m_[28m[27m | ||
| [36m│[39m [32m●[39m Apple | ||
| [36m│[39m [2m○[22m [2mBanana[22m | ||
| [36m│[39m [2m○[22m [2mCherry[22m | ||
| [36m│[39m [2m○[22m [2mGrape[22m | ||
| [36m│[39m [2m○[22m [2mOrange[22m | ||
| [36m│[39m [2m○[22m [2mKiwi[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| "<cursor.backward count=999><cursor.up count=11>", | ||
| "<cursor.down count=3>", | ||
| "<erase.down>", | ||
| "[36m│[39m [2mSearch:[22m[2m[22m | ||
| [36m│[39m [2m○[22m [2mApple[22m | ||
| [36m│[39m [32m●[39m Banana | ||
| [36m│[39m [2m○[22m [2mCherry[22m | ||
| [36m│[39m [2m○[22m [2mGrape[22m | ||
| [36m│[39m [2m○[22m [2mOrange[22m | ||
| [36m│[39m [2m○[22m [2mKiwi[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| "<cursor.backward count=999><cursor.up count=11>", | ||
| "<cursor.down count=5>", | ||
| "<erase.down>", | ||
| "[36m│[39m [2m○[22m [2mBanana[22m | ||
| [36m│[39m [32m●[39m Cherry | ||
| [36m│[39m [2m○[22m [2mGrape[22m | ||
| [36m│[39m [2m○[22m [2mOrange[22m | ||
| [36m│[39m [2m○[22m [2mKiwi[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| "<cursor.backward count=999><cursor.up count=11>", | ||
| "<cursor.down count=6>", | ||
| "<erase.down>", | ||
| "[36m│[39m [2m○[22m [2mCherry[22m | ||
| [36m│[39m [32m●[39m Grape | ||
| [36m│[39m [2m○[22m [2mOrange[22m | ||
| [36m│[39m [2m○[22m [2mKiwi[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| "<cursor.backward count=999><cursor.up count=11>", | ||
| "<cursor.down count=7>", | ||
| "<erase.down>", | ||
| "[36m│[39m [2m○[22m [2mGrape[22m | ||
| [36m│[39m [32m●[39m Orange | ||
| [36m│[39m [2m○[22m [2mKiwi[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| "<cursor.backward count=999><cursor.up count=11>", | ||
| "<cursor.down count=8>", | ||
| "<erase.down>", | ||
| "[36m│[39m [2m○[22m [2mOrange[22m | ||
| [36m│[39m [32m●[39m Kiwi[2m (New Zealand)[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| ] | ||
| `; | ||
|
|
||
| exports[`autocomplete > shows no matches message when search has no results 1`] = ` | ||
| [ | ||
| "<cursor.hide>", | ||
| "[90m│[39m | ||
| [36m◆[39m Select a fruit | ||
|
|
||
| [36m│[39m [2mSearch:[22m [7m[8m_[28m[27m | ||
| [36m│[39m [32m●[39m Apple | ||
| [36m│[39m [2m○[22m [2mBanana[22m | ||
| [36m│[39m [2m○[22m [2mCherry[22m | ||
| [36m│[39m [2m○[22m [2mGrape[22m | ||
| [36m│[39m [2m○[22m [2mOrange[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| "<cursor.backward count=999><cursor.up count=10>", | ||
| "<cursor.down count=3>", | ||
| "<erase.down>", | ||
| "[36m│[39m [2mSearch:[22m z█[2m (0 matches)[22m | ||
| [36m│[39m [33mNo matches found[39m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| ] | ||
| `; | ||
|
|
||
| exports[`autocomplete > shows placeholder when provided 1`] = ` | ||
| [ | ||
| "<cursor.hide>", | ||
| "[90m│[39m | ||
| [36m◆[39m Select a fruit | ||
|
|
||
| [36m│[39m [2mSearch:[22m [7m[8m_[28m[27m | ||
| [36m│[39m [32m●[39m Apple | ||
| [36m│[39m [2m○[22m [2mBanana[22m | ||
| [36m│[39m [2m○[22m [2mCherry[22m | ||
| [36m│[39m [2m○[22m [2mGrape[22m | ||
| [36m│[39m [2m○[22m [2mOrange[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| ] | ||
| `; | ||
|
|
||
| exports[`autocomplete > shows selected value in submit state 1`] = ` | ||
| [ | ||
| "<cursor.hide>", | ||
| "[90m│[39m | ||
| [36m◆[39m Select a fruit | ||
|
|
||
| [36m│[39m [2mSearch:[22m [7m[8m_[28m[27m | ||
| [36m│[39m [32m●[39m Apple | ||
| [36m│[39m [2m○[22m [2mBanana[22m | ||
| [36m│[39m [2m○[22m [2mCherry[22m | ||
| [36m│[39m [2m○[22m [2mGrape[22m | ||
| [36m│[39m [2m○[22m [2mOrange[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| "<cursor.backward count=999><cursor.up count=10>", | ||
| "<cursor.down count=3>", | ||
| "<erase.down>", | ||
| "[36m│[39m [2mSearch:[22m[2m[22m | ||
| [36m│[39m [2m○[22m [2mApple[22m | ||
| [36m│[39m [32m●[39m Banana | ||
| [36m│[39m [2m○[22m [2mCherry[22m | ||
| [36m│[39m [2m○[22m [2mGrape[22m | ||
| [36m│[39m [2m○[22m [2mOrange[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| "<cursor.backward count=999><cursor.up count=10>", | ||
| "<cursor.down count=1>", | ||
| "<erase.down>", | ||
| "[32m◇[39m Select a fruit | ||
| [90m│[39m [2mBanana[22m", | ||
| " | ||
| ", | ||
| "<cursor.show>", | ||
| ] | ||
| `; | ||
|
|
||
| exports[`autocomplete > shows strikethrough in cancel state 1`] = ` | ||
| [ | ||
| "<cursor.hide>", | ||
| "[90m│[39m | ||
| [36m◆[39m Select a fruit | ||
|
|
||
| [36m│[39m [2mSearch:[22m [7m[8m_[28m[27m | ||
| [36m│[39m [32m●[39m Apple | ||
| [36m│[39m [2m○[22m [2mBanana[22m | ||
| [36m│[39m [2m○[22m [2mCherry[22m | ||
| [36m│[39m [2m○[22m [2mGrape[22m | ||
| [36m│[39m [2m○[22m [2mOrange[22m | ||
| [36m│[39m [2m[2m↑/↓[22m[2m to select • [2mEnter:[22m[2m confirm • [2mType:[22m[2m to search[22m | ||
| [36m└[39m", | ||
| "<cursor.backward count=999><cursor.up count=10>", | ||
| "<cursor.down count=1>", | ||
| "<erase.down>", | ||
| "[31m■[39m Select a fruit | ||
| [90m│[39m[9m[2m[22m[29m", | ||
| " | ||
| ", | ||
| "<cursor.show>", | ||
| ] | ||
| `; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.