diff --git a/InquirerPy/base/control.py b/InquirerPy/base/control.py index 69cdc38..eaba586 100644 --- a/InquirerPy/base/control.py +++ b/InquirerPy/base/control.py @@ -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.""" diff --git a/InquirerPy/prompts/checkbox.py b/InquirerPy/prompts/checkbox.py index 60f3bde..f9aff4e 100644 --- a/InquirerPy/prompts/checkbox.py +++ b/InquirerPy/prompts/checkbox.py @@ -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]]: diff --git a/InquirerPy/prompts/expand.py b/InquirerPy/prompts/expand.py index e95f967..7eb52bb 100644 --- a/InquirerPy/prompts/expand.py +++ b/InquirerPy/prompts/expand.py @@ -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]]: diff --git a/InquirerPy/prompts/fuzzy.py b/InquirerPy/prompts/fuzzy.py index 8f1a5b6..0df64c2 100644 --- a/InquirerPy/prompts/fuzzy.py +++ b/InquirerPy/prompts/fuzzy.py @@ -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]]: diff --git a/InquirerPy/prompts/list.py b/InquirerPy/prompts/list.py index acbda33..f55a15b 100644 --- a/InquirerPy/prompts/list.py +++ b/InquirerPy/prompts/list.py @@ -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]]: diff --git a/InquirerPy/prompts/rawlist.py b/InquirerPy/prompts/rawlist.py index 0de466d..f7d9694 100644 --- a/InquirerPy/prompts/rawlist.py +++ b/InquirerPy/prompts/rawlist.py @@ -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]]: diff --git a/InquirerPy/utils.py b/InquirerPy/utils.py index 8e2b62f..1cd1a46 100644 --- a/InquirerPy/utils.py +++ b/InquirerPy/utils.py @@ -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", ""), @@ -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", ""),