[go: nahoru, domu]

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

Case insensitive prompt choices #3052

Merged

Conversation

seapagan
Copy link
Contributor
@seapagan seapagan commented Jul 23, 2023

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

Optional flag for Prompt.ask allowing case-insensitive responses. Just add case_sensitive=False to the command options:

from rich.prompt import Prompt
name = Prompt.ask("Enter your name", choices=["Paul", "Jessica", "Duncan"], default="Paul", case_sensitive=False)

Now, it would accept "paul" or "Paul" as valid responses. Defaults to True, which is the usual result.

@seapagan seapagan marked this pull request as ready for review July 23, 2023 17:42
@codecov-commenter
Copy link
codecov-commenter commented Nov 7, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (aabfd16) 98.30% compared to head (9038abe) 98.28%.
Report is 35 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3052      +/-   ##
==========================================
- Coverage   98.30%   98.28%   -0.03%     
==========================================
  Files          74       74              
  Lines        8038     8049      +11     
==========================================
+ Hits         7902     7911       +9     
- Misses        136      138       +2     
Flag Coverage Δ
unittests 98.28% <95.45%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
rich/_export_format.py 100.00% <ø> (ø)
rich/align.py 100.00% <ø> (ø)
rich/console.py 98.04% <100.00%> (+<0.01%) ⬆️
rich/containers.py 100.00% <ø> (ø)
rich/markdown.py 99.45% <100.00%> (ø)
rich/markup.py 100.00% <ø> (ø)
rich/panel.py 98.29% <ø> (ø)
rich/pretty.py 96.67% <ø> (ø)
rich/progress.py 92.92% <ø> (ø)
rich/prompt.py 100.00% <100.00%> (ø)
... and 2 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@darrenburns
Copy link
Member

I think this is very useful, and might even be a better default!

The only thing I'd say is perhaps case_sensitive would be better than case_insensitive (we have a parameter in Text.highlight_words which is called case_sensitive, so it'd keep thing consistent)?

Any thoughts @willmcgugan?

@seapagan
Copy link
Contributor Author
seapagan commented Nov 7, 2023

The only thing I'd say is perhaps case_sensitive would be better than case_insensitive (we have a parameter in Text.highlight_words which is called case_sensitive, so it'd keep thing consistent)?

@darrenburns I can quickly rename to case_sensitive and flip the functionality if you want, I'm all for consistency 😁. Can prob squeeze it in later tonight or early tomorrow morning. If you decide between you to make it default, that would be a quick extra change.

@seapagan
Copy link
Contributor Author
seapagan commented Nov 8, 2023

I can quickly rename to case_sensitive and flip the functionality if you want, I'm all for consistency 😁. Can prob squeeze it in later tonight or early tomorrow morning. If you decide between you to make it default, that would be a quick extra change.

@darrenburns Done. I renamed the flag and left the default state as case_sensitive = True. This functionality actually makes more sense to me when you point it out.

@seapagan
Copy link
Contributor Author

@darrenburns, is this PR DOA, or will it be looked at in future?

It could be a useful addition to the library as it's something I use a lot. I guess I can put it into a separate package if it won't be merged.

@darrenburns
Copy link
Member

That's up to @willmcgugan

@willmcgugan willmcgugan merged commit 855cdbe into Textualize:master Jul 1, 2024
@willmcgugan
Copy link
Collaborator

Thanks for the PR.

@seapagan seapagan deleted the case-insensitive-prompt-choices branch July 9, 2024 09:59
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

4 participants