Skip to content

Commit b2f959d

Browse files
TheItsNamelessTheItsNamless
andauthored
[FIX] 41: Show selected option after key in expand prompt (#48)
Co-authored-by: TheItsNamless <[email protected]>
1 parent df965c6 commit b2f959d

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
exclude: ".*tests\/fixtures.*"
22
repos:
33
- repo: https://github.com/google/yapf
4-
rev: v0.33.0
4+
rev: v0.43.0
55
hooks:
66
- id: yapf
77
args: [ --diff ]

ItsPrompt/data/expand.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,27 @@ class ExpandOption(Option):
1414
is_disabled: bool
1515

1616

17-
def process_data(options: OptionsList) -> OptionsWithSeparator[ExpandOption | Separator]:
17+
class ExpandOptionsWithSeparator(OptionsWithSeparator[ExpandOption | Separator]):
18+
19+
def __init__(self, *args: ExpandOption | Separator):
20+
super().__init__(*args)
21+
22+
def get_option(self, key: str) -> ExpandOption | None:
23+
"""
24+
Get the option with the given key.
25+
26+
:param key: The key of the option to get
27+
:type key: str
28+
:return: The option with the given key or None if not found
29+
:rtype: ExpandOption | None
30+
"""
31+
for option in self.with_separators:
32+
if isinstance(option, ExpandOption) and option.key == key:
33+
return option
34+
return None
35+
36+
37+
def process_data(options: OptionsList) -> ExpandOptionsWithSeparator:
1838
"""
1939
Processes the given `options` and returns the processed list
2040
@@ -71,4 +91,4 @@ def process_data(options: OptionsList) -> OptionsWithSeparator[ExpandOption | Se
7191
ExpandOption(key='h', name='Help Menu, list or hide all options', id='', is_disabled=False)
7292
)
7393

74-
return OptionsWithSeparator(*processed_options)
94+
return ExpandOptionsWithSeparator(*processed_options)

ItsPrompt/objects/prompts/options_with_separator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import Iterator, TypeVar, Generic
22

3+
from ItsPrompt.objects.prompts.option import Option
34
from ItsPrompt.objects.prompts.separator import Separator
45

5-
OptionOrSeparator = TypeVar("OptionOrSeparator")
6+
OptionOrSeparator = TypeVar("OptionOrSeparator", bound=Option | Separator)
67

78

89
class OptionsWithSeparator(Generic[OptionOrSeparator], list):

ItsPrompt/prompts/expand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def update(self):
9494
content += f'\n{disabled[0]}<option> {option.key}) {option.name}</option>{disabled[1]}' # type: ignore
9595

9696
# text
97-
content += f'\n<text> Answer: {self.selection}</text>'
97+
content += f'\n<text> Answer: {self.selection} ({self.options.get_option(self.selection).name})</text>' # type: ignore
9898

9999
self.prompt_content.text = HTML(content)
100100

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pre-commit==3.3.1
22
pytest==7.3.1
3-
yapf==0.32.0
3+
yapf==0.43.0
44
mypy==1.2.0
55
pytest-cov==4.0.0
66
pandas-stubs==2.0.1.230501

0 commit comments

Comments
 (0)