Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
732cbcd
feat(copier/_user_data.py): add `questionary` `use_shorcuts` & `use_f…
RR5555 Jan 8, 2026
06c942f
docs(copier/_user_data.py): complement `Question` docstring to doc `u…
RR5555 Jan 8, 2026
75bcd23
test(copier/_user_data.py): add tests for `Question` `use_shortcuts` …
RR5555 Jan 8, 2026
8f951e4
Merge branch 'copier-org:master' into question_filter_shortcut
RR5555 Jan 8, 2026
08371bf
test(tests/): rename `test_shortcut.py` to `test_choices.py`
RR5555 Jan 11, 2026
13d341b
fix(copier/_user_data.py): fix attribute name of `Question` from `use…
RR5555 Jan 11, 2026
20d24f8
docs(Question): line-wrap the docstring to max length 88 for consistency
RR5555 Jan 11, 2026
f8a8cb1
test(tests/test_choices.py): remove useless elements
RR5555 Jan 11, 2026
f734a35
test(tests/test_choices.py): curate the test template
RR5555 Jan 11, 2026
f8c695e
docs(docs/configuring.md): add docs for `use_shortcuts` & `use_search…
RR5555 Jan 11, 2026
70e7e42
test(tests/test_choices.py): split tests between `use_shortcuts` & `u…
RR5555 Jan 12, 2026
4ba04f7
test(tests/test_choices): fix type hints for compliance with `test_ty…
RR5555 Jan 12, 2026
c1f6643
Merge branch 'copier-org:master' into question_filter_shortcut
RR5555 Mar 16, 2026
bcdf3d2
Merge branch 'copier-org:master' into question_filter_shortcut
RR5555 Mar 16, 2026
5b3e902
fix(Question): change from superseeding to `ValidationError` for mutu…
RR5555 Mar 16, 2026
928e117
docs(Question): improve & adapt docstring to mutual exclusiveness
RR5555 Mar 16, 2026
215cd0c
test(tests/test_choices.py): break down fixtures into clearer tests; …
RR5555 Mar 16, 2026
04cd33d
docs(docs/configuring.md): improve & simplify the docs relative to `u…
RR5555 Mar 16, 2026
db9794e
feat(mkdocs.yml): enable `pymdownx.keys` for pretty keyboard keys
RR5555 Mar 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions copier/_user_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""

var_name: str
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
155 changes: 155 additions & 0 deletions docs/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

!!! 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`
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.

!!! note

If `use_shortcuts` & `use_search_filter` are both `true`, then only `use_search_filter` is activated.

!!! 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
```

<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>

---


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.

- **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
Expand Down
Loading
Loading