|
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 | 1 | from __future__ import annotations |
8 | 2 |
|
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] |
| 3 | +from typing import TYPE_CHECKING |
16 | 4 |
|
| 5 | +from inquirer_textual.InquirerApp import InquirerApp |
| 6 | +from inquirer_textual.widgets.InquirerCheckbox import InquirerCheckbox |
| 7 | +from inquirer_textual.widgets.InquirerConfirm import InquirerConfirm |
| 8 | +from inquirer_textual.widgets.InquirerSelect import InquirerSelect |
| 9 | +from inquirer_textual.widgets.InquirerText import InquirerText |
17 | 10 |
|
18 | | -class CodeflashThemedApp(InquirerApp): # type: ignore[misc] |
19 | | - """Custom themed InquirerApp matching the original CodeFlash theme colors.""" |
| 11 | +if TYPE_CHECKING: |
| 12 | + from inquirer_textual.common.Choice import Choice |
20 | 13 |
|
21 | | - def get_theme_variable_defaults(self) -> dict[str, str]: |
22 | | - """Return CodeFlash theme colors. |
23 | 14 |
|
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 |
| 15 | +class CodeflashThemedApp(InquirerApp): |
| 16 | + CSS = """ |
| 17 | + App { |
| 18 | + background: #1e293b; |
| 19 | + } |
| 20 | + Screen { |
| 21 | + border-top: none; |
| 22 | + border-bottom: none; |
| 23 | + background: transparent; |
| 24 | + height: auto; |
| 25 | + } |
| 26 | + ListView { |
| 27 | + background: transparent; |
| 28 | + border: none; |
| 29 | + } |
| 30 | + ListItem { |
| 31 | + background: transparent; |
| 32 | + padding: 0 1; |
| 33 | + color: #f1f5f9; |
| 34 | + } |
| 35 | + ListItem.-highlight { |
| 36 | + background: #334155; |
| 37 | + color: $select-list-item-highlight-foreground; |
| 38 | + } |
| 39 | + Label { |
| 40 | + background: transparent; |
| 41 | + color: #f8fafc; |
| 42 | + } |
| 43 | + Static { |
| 44 | + background: transparent; |
| 45 | + color: #f8fafc; |
| 46 | + } |
| 47 | + Input { |
| 48 | + background: #334155; |
| 49 | + border: solid $primary; |
| 50 | + color: #f8fafc; |
| 51 | + } |
| 52 | + Input:focus { |
| 53 | + border: solid $accent; |
41 | 54 | } |
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 | 55 | """ |
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 | 56 |
|
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 |
| 57 | + def get_theme_variable_defaults(self) -> dict[str, str]: |
| 58 | + return { |
| 59 | + "select-question-mark": "#FFC143", |
| 60 | + "select-list-item-highlight-foreground": "#2563EB", |
| 61 | + "input-color": "#3B82F6", |
| 62 | + "input-selection-background": "#1e293b", |
| 63 | + "accent": "#FFC143", |
| 64 | + "primary": "#2563EB", |
| 65 | + "secondary": "#414372", |
| 66 | + } |
74 | 67 |
|
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 | 68 |
|
| 69 | +def select( # noqa: ANN201 |
| 70 | + message: str, choices: list[str | Choice], default: str | Choice | None = None |
| 71 | +): # type: ignore[no-untyped-def] |
| 72 | + widget = InquirerSelect(message, choices, default, mandatory=True) |
| 73 | + app: CodeflashThemedApp = CodeflashThemedApp(widget, shortcuts=None, show_footer=False) |
| 74 | + return app.run(inline=True) |
80 | 75 |
|
81 | | -def text(message: str) -> Result[str]: # type: ignore[type-arg] |
82 | | - """Display a text input prompt with CodeFlash theming. |
83 | 76 |
|
84 | | - Args: |
85 | | - message: The prompt message to display |
| 77 | +def confirm(message: str, *, default: bool = False): # noqa: ANN201 # type: ignore[no-untyped-def] |
| 78 | + widget = InquirerConfirm(message, default=default, mandatory=True) |
| 79 | + app: CodeflashThemedApp = CodeflashThemedApp(widget, shortcuts=None, show_footer=False) |
| 80 | + return app.run(inline=True) |
86 | 81 |
|
87 | | - Returns: |
88 | | - Result object containing the text value and command |
89 | 82 |
|
90 | | - """ |
| 83 | +def text(message: str): # noqa: ANN201 # type: ignore[no-untyped-def] |
91 | 84 | 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] |
| 85 | + app: CodeflashThemedApp = CodeflashThemedApp(widget, shortcuts=None, show_footer=False) |
| 86 | + return app.run(inline=True) |
94 | 87 |
|
95 | 88 |
|
96 | | -def checkbox( |
| 89 | +def checkbox( # noqa: ANN201 |
97 | 90 | 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 | | - """ |
| 91 | +): # type: ignore[no-untyped-def] |
110 | 92 | 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] |
| 93 | + app: CodeflashThemedApp = CodeflashThemedApp(widget, shortcuts=None, show_footer=False) |
| 94 | + return app.run(inline=True) |
0 commit comments