|
| 1 | +"""Themed prompts wrapper for inquirer-textual with CodeFlash styling. |
| 2 | +
|
| 3 | +This module provides themed prompt functions that match the original CodeFlash |
| 4 | +inquirer theme (yellow question marks, bright blue selections, cyan defaults). |
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import annotations |
| 8 | + |
| 9 | +from inquirer_textual.common.Choice import Choice # type: ignore[import-untyped] |
| 10 | +from inquirer_textual.common.Result import Result # type: ignore[import-untyped] |
| 11 | +from inquirer_textual.InquirerApp import InquirerApp # type: ignore[import-untyped] |
| 12 | +from inquirer_textual.widgets.InquirerCheckbox import InquirerCheckbox # type: ignore[import-untyped] |
| 13 | +from inquirer_textual.widgets.InquirerConfirm import InquirerConfirm # type: ignore[import-untyped] |
| 14 | +from inquirer_textual.widgets.InquirerSelect import InquirerSelect # type: ignore[import-untyped] |
| 15 | +from inquirer_textual.widgets.InquirerText import InquirerText # type: ignore[import-untyped] |
| 16 | + |
| 17 | + |
| 18 | +class CodeflashThemedApp(InquirerApp): # type: ignore[misc] |
| 19 | + """Custom themed InquirerApp matching the original CodeFlash theme colors.""" |
| 20 | + |
| 21 | + def get_theme_variable_defaults(self) -> dict[str, str]: |
| 22 | + """Return CodeFlash theme colors. |
| 23 | +
|
| 24 | + Original CodeFlash theme from inquirer: |
| 25 | + - Question mark: yellow |
| 26 | + - Brackets: bright blue |
| 27 | + - Default: bright cyan |
| 28 | + - Selection: bright blue |
| 29 | + - Checkbox selected: ✅ |
| 30 | + - Checkbox unselected: ⬜ |
| 31 | + """ |
| 32 | + return { |
| 33 | + # Question mark color - yellow like the original |
| 34 | + "select-question-mark": "#e5c07b", # Gold/yellow |
| 35 | + # List item highlight - bright blue like the original selection |
| 36 | + "select-list-item-highlight-foreground": "#61afef", # Bright blue |
| 37 | + # Input/text color - cyan like the original |
| 38 | + "input-color": "#61afef", # Bright blue (used for inputs and selections) |
| 39 | + # Additional contrast colors |
| 40 | + "input-selection-background": "#3e4451", # Subtle background for selected items |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | +def select( |
| 45 | + message: str, choices: list[str | Choice], default: str | Choice | None = None, mandatory: bool = True |
| 46 | +) -> Result[str | Choice]: # type: ignore[type-arg] |
| 47 | + """Display a select prompt with CodeFlash theming. |
| 48 | +
|
| 49 | + Args: |
| 50 | + message: The prompt message to display |
| 51 | + choices: List of choices (strings or Choice objects) |
| 52 | + default: Default choice to pre-select |
| 53 | + mandatory: Whether a response is mandatory |
| 54 | +
|
| 55 | + Returns: |
| 56 | + Result object containing the selected value and command |
| 57 | +
|
| 58 | + """ |
| 59 | + widget = InquirerSelect(message, choices, default, mandatory) |
| 60 | + app: CodeflashThemedApp = CodeflashThemedApp(widget, shortcuts=None, show_footer=False) # type: ignore[assignment] |
| 61 | + return app.run(inline=True) # type: ignore[return-value] |
| 62 | + |
| 63 | + |
| 64 | +def confirm(message: str, default: bool = False, mandatory: bool = True) -> Result[bool]: # type: ignore[type-arg] |
| 65 | + """Display a confirm prompt with CodeFlash theming. |
| 66 | +
|
| 67 | + Args: |
| 68 | + message: The prompt message to display |
| 69 | + default: Default value (True for yes, False for no) |
| 70 | + mandatory: Whether a response is mandatory |
| 71 | +
|
| 72 | + Returns: |
| 73 | + Result object containing the boolean value and command |
| 74 | +
|
| 75 | + """ |
| 76 | + widget = InquirerConfirm(message, default=default, mandatory=mandatory) |
| 77 | + app: CodeflashThemedApp = CodeflashThemedApp(widget, shortcuts=None, show_footer=False) # type: ignore[assignment] |
| 78 | + return app.run(inline=True) # type: ignore[return-value] |
| 79 | + |
| 80 | + |
| 81 | +def text(message: str) -> Result[str]: # type: ignore[type-arg] |
| 82 | + """Display a text input prompt with CodeFlash theming. |
| 83 | +
|
| 84 | + Args: |
| 85 | + message: The prompt message to display |
| 86 | +
|
| 87 | + Returns: |
| 88 | + Result object containing the text value and command |
| 89 | +
|
| 90 | + """ |
| 91 | + widget = InquirerText(message) |
| 92 | + app: CodeflashThemedApp = CodeflashThemedApp(widget, shortcuts=None, show_footer=False) # type: ignore[assignment] |
| 93 | + return app.run(inline=True) # type: ignore[return-value] |
| 94 | + |
| 95 | + |
| 96 | +def checkbox( |
| 97 | + message: str, choices: list[str | Choice], enabled: list[str | Choice] | None = None |
| 98 | +) -> Result[list[str | Choice]]: # type: ignore[type-arg] |
| 99 | + """Display a checkbox prompt with CodeFlash theming. |
| 100 | +
|
| 101 | + Args: |
| 102 | + message: The prompt message to display |
| 103 | + choices: List of choices (strings or Choice objects) |
| 104 | + enabled: List of pre-selected choices |
| 105 | +
|
| 106 | + Returns: |
| 107 | + Result object containing the list of selected values and command |
| 108 | +
|
| 109 | + """ |
| 110 | + widget = InquirerCheckbox(message, choices, enabled) |
| 111 | + app: CodeflashThemedApp = CodeflashThemedApp(widget, shortcuts=None, show_footer=False) # type: ignore[assignment] |
| 112 | + return app.run(inline=True) # type: ignore[return-value] |
0 commit comments