Skip to content
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

Make lists searchable and add key mapping to README.md #20

Merged
merged 1 commit into from Jul 16, 2021

Conversation

pascal-hofmann
Copy link
Contributor

This PR enables the search functionality of promptui.Select.

  • The search functions just filter the resource addresses with strings.Contains(address, searchTerm).
  • The prompt now defaults to search mode. So users can either directly filter by entering a search term or select an entry via the arrow keys. The only downside to this is, that the key mapping is not displayed as part of the prompt anymore. That's why I added the key mapping to README.md.

@codecov
Copy link

codecov bot commented Jul 16, 2021

Codecov Report

Merging #20 (eb633bf) into master (cf3b2f6) will decrease coverage by 1.38%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #20      +/-   ##
==========================================
- Coverage   32.40%   31.01%   -1.39%     
==========================================
  Files           5        5              
  Lines         179      187       +8     
==========================================
  Hits           58       58              
- Misses        109      117       +8     
  Partials       12       12              
Impacted Files Coverage Δ
prompt.go 12.50% <0.00%> (-2.50%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf3b2f6...eb633bf. Read the comment docs.

@@ -16,7 +16,16 @@ func prompt(sources map[Resource]bool, destinations map[Resource]bool) (Resource
Selected: "{{ .Address }}",
}
srcs := toSlice(sources)
prompt := promptui.Select{Label: "Select Source", Items: append(srcs, Resource{"Finished", "no more resources to move"}), Templates: srcTempl}
srcSearcher := func(input string, index int) bool {
if index >= len(srcs) {
Copy link
Owner

@mbode mbode Jul 16, 2021

Choose a reason for hiding this comment

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

If I understand https://github.com/manifoldco/promptui/blob/master/list/list.go#L82 correctly, this check might be a bit defensive - what do you think?
If we need it here, should we also add a corresponding check in destSearcher below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only need it because of the additional Resource{"Finished", "no more resources to move"} item that's added to the end of the list.

Copy link
Owner

Choose a reason for hiding this comment

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

I see, thanks for the explanation!

@mbode
Copy link
Owner

mbode commented Jul 16, 2021

Great idea, thank you very much for the contribution!

@mbode mbode merged commit 47b3eb2 into mbode:master Jul 16, 2021
@pascal-hofmann pascal-hofmann deleted the add-search branch July 16, 2021 09:47
@mbode
Copy link
Owner

mbode commented Jul 16, 2021

Has been released in 0.4.0.

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.

None yet

2 participants