Skip to content

Commit

Permalink
feat(choice): Add instruction
Browse files Browse the repository at this point in the history
Allows the developer to specify additional information to appear next to their choices.

kazhala#55
  • Loading branch information
Gracecr authored and chris-grace-mastodon committed Feb 13, 2023
1 parent 714d906 commit 0f59382
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions InquirerPy/base/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ class Choice:
This value is optional, if not provided, it will fallback to the string representation of `value`.
enabled: Indicates if the choice should be pre-selected.
This only has effects when the prompt has `multiselect` enabled.
instruction: Extra details that should be presented to the user when hovering the choice.
This value is optional, if not provided, no information will be shown on hover.
"""

value: Any
name: Optional[str] = None
enabled: bool = False
instruction: Optional[str] = None

def __post_init__(self):
"""Assign strinify value to name if not present."""
Expand Down
4 changes: 4 additions & 0 deletions InquirerPy/prompts/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def _get_hover_text(self, choice) -> List[Tuple[str, str]]:
display_choices.append(("", " "))
display_choices.append(("[SetCursorPosition]", ""))
display_choices.append(("class:pointer", choice["name"]))
if "instruction" in choice:
display_choices.append(
("class:choice_instruction", " " + choice["instruction"])
)
return display_choices

def _get_normal_text(self, choice) -> List[Tuple[str, str]]:
Expand Down
4 changes: 4 additions & 0 deletions InquirerPy/prompts/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ def _get_hover_text(self, choice) -> List[Tuple[str, str]]:
)
display_choices.append(("[SetCursorPosition]", ""))
display_choices.append(("class:pointer", choice["name"]))
if "instruction" in choice:
display_choices.append(
("class:choice_instruction", " " + choice["instruction"])
)
return display_choices

def _get_normal_text(self, choice) -> List[Tuple[str, str]]:
Expand Down
4 changes: 4 additions & 0 deletions InquirerPy/prompts/fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ def _get_hover_text(self, choice) -> List[Tuple[str, str]]:
display_choices.append(("class:fuzzy_match", char))
else:
display_choices.append(("class:pointer", char))
if "instruction" in choice:
display_choices.append(
("class:choice_instruction", " " + choice["instruction"])
)
return display_choices

def _get_normal_text(self, choice) -> List[Tuple[str, str]]:
Expand Down
4 changes: 4 additions & 0 deletions InquirerPy/prompts/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def _get_hover_text(self, choice) -> List[Tuple[str, str]]:
)
display_choices.append(("[SetCursorPosition]", ""))
display_choices.append(("class:pointer", choice["name"]))
if "instruction" in choice:
display_choices.append(
("class:choice_instruction", " " + choice["instruction"])
)
return display_choices

def _get_normal_text(self, choice) -> List[Tuple[str, str]]:
Expand Down
4 changes: 4 additions & 0 deletions InquirerPy/prompts/rawlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def _get_hover_text(self, choice) -> List[Tuple[str, str]]:
)
display_choices.append(("[SetCursorPosition]", ""))
display_choices.append(("class:pointer", choice["name"]))
if "instruction" in choice:
display_choices.append(
("class:choice_instruction", " " + choice["instruction"])
)
return display_choices

def _get_normal_text(self, choice) -> List[Tuple[str, str]]:
Expand Down
4 changes: 4 additions & 0 deletions InquirerPy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def get_style(
"long_instruction": os.getenv(
"INQUIRERPY_STYLE_LONG_INSTRUCTION", "#abb2bf"
),
"choice_instruction": os.getenv(
"INQUIRERPY_STYLE_CHOICE_INSTRUCTION", "grey italic"
),
"pointer": os.getenv("INQUIRERPY_STYLE_POINTER", "#61afef"),
"checkbox": os.getenv("INQUIRERPY_STYLE_CHECKBOX", "#98c379"),
"separator": os.getenv("INQUIRERPY_STYLE_SEPARATOR", ""),
Expand All @@ -138,6 +141,7 @@ def get_style(
"answered_question": os.getenv("INQUIRERPY_STYLE_ANSWERED_QUESTION", ""),
"instruction": os.getenv("INQUIRERPY_STYLE_INSTRUCTION", ""),
"long_instruction": os.getenv("INQUIRERPY_STYLE_LONG_INSTRUCTION", ""),
"choice_instruction": os.getenv("INQUIRERPY_STYLE_CHOICE_INSTRUCTION", ""),
"pointer": os.getenv("INQUIRERPY_STYLE_POINTER", ""),
"checkbox": os.getenv("INQUIRERPY_STYLE_CHECKBOX", ""),
"separator": os.getenv("INQUIRERPY_STYLE_SEPARATOR", ""),
Expand Down

0 comments on commit 0f59382

Please sign in to comment.