-
-
Notifications
You must be signed in to change notification settings - Fork 239
Add numbered shortcuts and filter search to Question select/checkbox
#2446
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
base: master
Are you sure you want to change the base?
Changes from all commits
732cbcd
06c942f
75bcd23
8f951e4
08371bf
13d341b
20d24f8
f8a8cb1
f734a35
f8c695e
70e7e42
4ba04f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -203,6 +203,16 @@ class Question: | |||||||||||||
| If it is a boolean, it is used directly. If it is a str, it is | ||||||||||||||
| converted to boolean using a parser similar to YAML, but only for | ||||||||||||||
| boolean values. | ||||||||||||||
|
|
||||||||||||||
| use_shortcuts: | ||||||||||||||
| Condition that, if `True`, will use `use_shortcuts` in `select` question, | ||||||||||||||
| allowing for selection via automatically numbered shortcut. Will be | ||||||||||||||
| deactivated if `use_search_filter` is `True`. | ||||||||||||||
|
|
||||||||||||||
| use_search_filter: | ||||||||||||||
| Condition that, if `True`, uses `use_search_filter` in `checkbox`/`select` | ||||||||||||||
| question while deactivating `use_jk_keys`, allowing for selection via | ||||||||||||||
| filtering. | ||||||||||||||
|
Comment on lines
+213
to
+215
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer describing only the behavior of the enabled feature and omitting a reference to the underlying implementation.
Suggested change
|
||||||||||||||
| """ | ||||||||||||||
|
|
||||||||||||||
| var_name: str | ||||||||||||||
|
|
@@ -221,6 +231,8 @@ class Question: | |||||||||||||
| type: str = Field(default="", validate_default=True) | ||||||||||||||
| validator: str = "" | ||||||||||||||
| when: str | bool = True | ||||||||||||||
| use_shortcuts: bool = False | ||||||||||||||
| use_search_filter: bool = False | ||||||||||||||
|
|
||||||||||||||
| @field_validator("var_name") | ||||||||||||||
| @classmethod | ||||||||||||||
|
|
@@ -419,6 +431,13 @@ def _validate(answer: str) -> str | Literal[True]: | |||||||||||||
| result["default"] = False | ||||||||||||||
| if self.choices: | ||||||||||||||
| questionary_type = "checkbox" if self.multiselect else "select" | ||||||||||||||
|
|
||||||||||||||
| if self.use_search_filter: | ||||||||||||||
| result["use_search_filter"] = True | ||||||||||||||
| result["use_jk_keys"] = False | ||||||||||||||
| elif self.use_shortcuts and questionary_type == "select": | ||||||||||||||
| result["use_shortcuts"] = True | ||||||||||||||
|
|
||||||||||||||
| choices = self._formatted_choices | ||||||||||||||
| # Select default choices for a multiselect question. | ||||||||||||||
| if self.multiselect and isinstance( | ||||||||||||||
|
|
||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kudos for the beautiful prompt visualization using HTML in Markdown including the Unicode icon for the question type! 🏆 This looks great! 🤩 |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -185,8 +185,163 @@ Supported keys: | |||||||||
| Some array: "[str, keeps, this, as, a, str]" | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| - **use_shortcuts**: When set to `true`, numbers the choices while allowing for cursor | ||||||||||
| selection by pressing the corresponding number. Only works when `multiselect` is | ||||||||||
| `false`. | ||||||||||
|
Comment on lines
+189
to
+190
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd mention also the mutual exclusiveness with
Suggested change
|
||||||||||
|
|
||||||||||
| !!! example | ||||||||||
|
|
||||||||||
| ```yaml title="copier.yml" | ||||||||||
| language: | ||||||||||
| type: str | ||||||||||
| help: Which programming language do you use? | ||||||||||
| use_shortcuts: true | ||||||||||
| choices: | ||||||||||
| - python | ||||||||||
| - node | ||||||||||
| - c | ||||||||||
| - c++ | ||||||||||
| - rust | ||||||||||
| - zig | ||||||||||
| - asm | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| Will result in: | ||||||||||
|
|
||||||||||
| <pre> | ||||||||||
| <span style="font-weight:bold">🎤 Which programming language do you use?</span> | ||||||||||
| (Use shortcuts or arrow keys) | ||||||||||
| » 1) python | ||||||||||
| 2) node | ||||||||||
| 3) c | ||||||||||
| 4) c++ | ||||||||||
| 5) rust | ||||||||||
| 6) zig | ||||||||||
| 7) asm | ||||||||||
| </pre> | ||||||||||
|
|
||||||||||
| Pressing `5` gives: | ||||||||||
|
|
||||||||||
| <pre> | ||||||||||
| <span style="font-weight:bold">🎤 Which programming language do you use?</span> | ||||||||||
| (Use shortcuts or arrow keys) | ||||||||||
| 1) python | ||||||||||
| 2) node | ||||||||||
| 3) c | ||||||||||
| 4) c++ | ||||||||||
| » 5) rust | ||||||||||
| 6) zig | ||||||||||
| 7) asm | ||||||||||
| </pre> | ||||||||||
|
|
||||||||||
| - **multiselect**: When set to `true`, allows multiple choices. The answer will be a | ||||||||||
| `list[T]` instead of a `T` where `T` is of type `type`. | ||||||||||
|
|
||||||||||
| - **use_search_filter**: When set to `true`, . Also deactivates the use of `j`/`k` | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The description of the effect of the feature is missing after the comma. |
||||||||||
| keys for navigation, as these are captured as prompts for the search filter. | ||||||||||
|
|
||||||||||
| !!! note | ||||||||||
|
|
||||||||||
| If `multiselect` is `true`, you cannot use `Space` in the search as this would actually just still select the option. If it is `false`, the `Space` character can be used in the search filter. | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| !!! note | ||||||||||
|
|
||||||||||
| If `use_shortcuts` & `use_search_filter` are both `true`, then only `use_search_filter` is activated. | ||||||||||
|
Comment on lines
+246
to
+249
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd remove this note and mention the mutual exclusiveness above.
Suggested change
|
||||||||||
|
|
||||||||||
| !!! example | ||||||||||
|
|
||||||||||
| ```yaml title="copier.yml" | ||||||||||
| language: | ||||||||||
| type: str | ||||||||||
| help: Which programming language do you use? | ||||||||||
| use_search_filter: true | ||||||||||
| choices: | ||||||||||
| - python | ||||||||||
| - node | ||||||||||
| - c | ||||||||||
| - c++ | ||||||||||
| - rust | ||||||||||
| - zig | ||||||||||
| - asm | ||||||||||
| - a new language | ||||||||||
| - a good one | ||||||||||
| - an average one | ||||||||||
| - a not so good one | ||||||||||
|
Comment on lines
+259
to
+269
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we stick with the same choices as in the example above? I think the list is already long enough with those choices, and typing |
||||||||||
| ``` | ||||||||||
|
|
||||||||||
| <pre> | ||||||||||
| <span style="font-weight:bold">🎤 Which programming language do you use?</span> | ||||||||||
| (Use arrow keys, type to filter) | ||||||||||
| » python | ||||||||||
| node | ||||||||||
| c | ||||||||||
| c++ | ||||||||||
| rust | ||||||||||
| zig | ||||||||||
| asm | ||||||||||
| a new language | ||||||||||
| a good one | ||||||||||
| an average one | ||||||||||
| a not so good one | ||||||||||
|
|
||||||||||
| </pre> | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
Comment on lines
+290
to
+291
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| Typing `c`: | ||||||||||
|
|
||||||||||
| <pre> | ||||||||||
| <span style="font-weight:bold">🎤 Which programming language do you use?</span> | ||||||||||
| (Use arrow keys, type to filter) | ||||||||||
| » c | ||||||||||
| c++ | ||||||||||
|
|
||||||||||
|
|
||||||||||
| / <span style="color:green;font-weight:bold">c</span>... | ||||||||||
| </pre> | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| Typing `an`: | ||||||||||
|
|
||||||||||
| <pre> | ||||||||||
| <span style="font-weight:bold">🎤 Which programming language do you use?</span> | ||||||||||
| (Use arrow keys, type to filter) | ||||||||||
| » a new language | ||||||||||
| an average one | ||||||||||
|
|
||||||||||
| / <span style="color:green;font-weight:bold">an</span>... | ||||||||||
| </pre> | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| Typing `ago` | ||||||||||
|
|
||||||||||
| <pre> | ||||||||||
| <span style="font-weight:bold">🎤 Which programming language do you use?</span> | ||||||||||
| (Use arrow keys, type to filter) | ||||||||||
| » python | ||||||||||
| node | ||||||||||
| c | ||||||||||
| c++ | ||||||||||
| rust | ||||||||||
| zig | ||||||||||
| asm | ||||||||||
| a new language | ||||||||||
| a good one | ||||||||||
| an average one | ||||||||||
| a not so good one | ||||||||||
|
|
||||||||||
| / <span style="color:red;font-weight:bold">ago</span>... | ||||||||||
| </pre> | ||||||||||
|
|
||||||||||
| When the filter fails, all options are displayed. | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| You can use `Backspace` to modify the search filter. | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we enable the
Suggested change
|
||||||||||
|
|
||||||||||
| - **default**: Leave empty to force the user to answer. Provide a default to save them | ||||||||||
| from typing it if it's quite common. When using `choices`, the default must be the | ||||||||||
| choice _value_, not its _key_, and it must match its _type_. If values are quite | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer describing only the behavior of the enabled feature and omitting a reference to the underlying implementation. Also, I'd prefer documenting mutual exclusiveness with
multiselect(raising a validation error when combined) rather than silent deactivation.