inquirer-textual 0.4.0__py3-none-any.whl → 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,175 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from textual import on, events
4
- from textual.app import ComposeResult
5
- from textual.containers import VerticalGroup, HorizontalGroup
6
- from textual.css.query import NoMatches
7
- from textual.reactive import reactive
8
- from textual.widgets import ListView, ListItem, Input, Static
9
- from typing_extensions import Self
10
-
11
- from inquirer_textual.common.Answer import Answer
12
- from inquirer_textual.common.Choice import Choice
13
- from inquirer_textual.common.ChoiceLabel import ChoiceLabel
14
- from inquirer_textual.common.Prompt import Prompt
15
- from inquirer_textual.common.defaults import POINTER_CHARACTER
16
- from inquirer_textual.widgets.InquirerWidget import InquirerWidget
17
-
18
-
19
- class InquirerPattern(InquirerWidget):
20
- """A select widget that allows a single selection from a list of choices with pattern filtering."""
21
-
22
- DEFAULT_CSS = """
23
- #inquirer-pattern-query-container {
24
- width: auto;
25
- }
26
- #inquirer-pattern-query {
27
- border: none;
28
- color: $inquirer-textual-input-color;
29
- padding: 0;
30
- height: 1;
31
- width: 20;
32
- }
33
- #inquirer-pattern-query-pointer {
34
- width: auto;
35
- color: $accent;
36
- }
37
- """
38
-
39
- candidates: reactive[list[str | Choice]] = reactive([])
40
-
41
- def __init__(self, message: str, choices: list[str | Choice], name: str | None = None,
42
- default: str | Choice | None = None, mandatory: bool = True):
43
- """
44
- Args:
45
- message (str): The prompt message to display.
46
- choices (list[str | Choice]): A list of choices to present to the user.
47
- default (str | Choice | None): The default choice to pre-select.
48
- mandatory (bool): Whether a response is mandatory.
49
- """
50
- super().__init__(name=name, mandatory=mandatory)
51
- self.message = message
52
- self.choices = choices
53
- self.candidates = choices.copy()
54
- self.list_view: ListView | None = None
55
- self.selected_label: ChoiceLabel | None = None
56
- self.selected_item: str | Choice | None = None
57
- self.default = default
58
- self.query: Input | None = None
59
- self.selected_value: str | Choice | None = None
60
- self.show_selected_value: bool = False
61
-
62
- def on_mount(self):
63
- super().on_mount()
64
- if self.app.is_inline:
65
- self.styles.height = min(10, len(self.choices) + 1)
66
- else:
67
- self.styles.height = '1fr'
68
-
69
- def on_list_view_highlighted(self, event: ListView.Highlighted) -> None:
70
- if self.selected_label:
71
- self.selected_label.remove_pointer()
72
- if event.item:
73
- try:
74
- label = event.item.query_one(ChoiceLabel)
75
- label.add_pointer()
76
- self.selected_label = label
77
- self.selected_item = label.item
78
- return
79
- except NoMatches:
80
- pass
81
- self.selected_label = None
82
- self.selected_item = None
83
-
84
- def on_list_view_selected(self, _: ListView.Selected):
85
- if isinstance(self.selected_item, Choice):
86
- self.submit_current_value(self.selected_item.command)
87
- else:
88
- self.submit_current_value()
89
-
90
- def focus(self, scroll_visible: bool = True) -> Self:
91
- if self.query:
92
- return self.query.focus(scroll_visible)
93
- else:
94
- return super().focus(scroll_visible)
95
-
96
- def current_value(self):
97
- return self.selected_item
98
-
99
- def _collect_list_items(self):
100
- items: list[ListItem] = []
101
- for candidate in self.candidates:
102
- list_item = ListItem(ChoiceLabel(candidate, self.query.value if self.query else None))
103
- items.append(list_item)
104
- return items
105
-
106
- def _find_initial_index(self):
107
- initial_index = 0
108
- for idx, choice in enumerate(self.choices):
109
- if self.default and choice == self.default:
110
- initial_index = idx
111
- return initial_index
112
-
113
- @on(Input.Changed, '#inquirer-pattern-query')
114
- async def handle_query_changed(self, event: Input.Changed):
115
- query = event.value.lower()
116
- if query == '':
117
- self.candidates = self.choices.copy()
118
- else:
119
- filtered = []
120
- for choice in self.choices:
121
- name = choice.name if isinstance(choice, Choice) else choice
122
- if query in name.lower():
123
- filtered.append(choice)
124
- self.candidates = filtered
125
- assert isinstance(self.list_view, ListView)
126
- await self.list_view.clear()
127
- list_items = self._collect_list_items()
128
- await self.list_view.extend(list_items)
129
- if list_items:
130
- self.list_view.index = 0
131
-
132
- def watch_candidates(self, candidates: list[str | Choice]) -> None:
133
- count_suffix = f'[{len(candidates)}/{len(self.choices)}]'
134
- try:
135
- count_widget = self.query_one('#inquirer-pattern-query-count-suffix', Static)
136
- count_widget.update(count_suffix)
137
- except NoMatches:
138
- pass
139
-
140
- def on_key(self, event: events.Key):
141
- assert isinstance(self.list_view, ListView)
142
- if event.key == 'down':
143
- event.stop()
144
- self.list_view.action_cursor_down()
145
- elif event.key == 'up':
146
- event.stop()
147
- self.list_view.action_cursor_up()
148
- elif event.key == 'enter':
149
- event.stop()
150
- self.list_view.action_select_cursor()
151
-
152
- async def set_selected_value(self, value: str | Choice) -> None:
153
- self.selected_value = value
154
- self.styles.height = 1
155
- self.show_selected_value = True
156
- await self.recompose()
157
-
158
- def compose(self) -> ComposeResult:
159
- if self.show_selected_value:
160
- with HorizontalGroup():
161
- yield Prompt(self.message)
162
- yield Answer(str(self.selected_value))
163
- else:
164
- with VerticalGroup():
165
- self.list_view = ListView(*self._collect_list_items(), id='inquirer-pattern-list-view',
166
- initial_index=self._find_initial_index())
167
- with HorizontalGroup():
168
- yield Prompt(self.message)
169
- yield Static(f'[{len(self.candidates)}/{len(self.choices)}]',
170
- id='inquirer-pattern-query-count-suffix')
171
- with HorizontalGroup(id='inquirer-pattern-query-container'):
172
- yield Static(f'{POINTER_CHARACTER} ', id='inquirer-pattern-query-pointer')
173
- self.query = Input(id="inquirer-pattern-query")
174
- yield self.query
175
- yield self.list_view
@@ -1,30 +0,0 @@
1
- inquirer_textual/InquirerApp.py,sha256=oOkEX0D_b5yOf67FXM7Bo7Y_ngbXy502r1YYl1ZCsdA,5863
2
- inquirer_textual/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- inquirer_textual/prompts.py,sha256=QyePg_l3dF2StKANB2oz1H8z5AN3v_CqA7WhxyhONd8,4229
4
- inquirer_textual/version.py,sha256=yhiWOz0HoJGRRI9-JQ2eh_0AbByy-6psK08-kpTSHJw,18
5
- inquirer_textual/common/Answer.py,sha256=4d08uTd1MYxjBwIuWexAe0UOKStwxBqniPGuXc7VOJY,537
6
- inquirer_textual/common/Choice.py,sha256=_0EGDbl6NGGiuOqCmfOkkmRX9IP09KQbRRmAdjPxwYs,203
7
- inquirer_textual/common/ChoiceCheckboxLabel.py,sha256=BZg5vLe6_qc0ipYUaonNfygSOnHyJuEVrB8mmM6tOjw,675
8
- inquirer_textual/common/ChoiceLabel.py,sha256=uJoHzMFCRE3cXCZlBLeMjADbHYHA81N03PyAfCf2y28,1009
9
- inquirer_textual/common/InquirerHeader.py,sha256=txl-TRe3DKsOPcmDKy1fhfTa-YAURsjTYePDDHzcPH8,802
10
- inquirer_textual/common/InquirerResult.py,sha256=2inNdfc2xUTCUFqAGazKJJv6YUQjjFzn-f3NTDxm1-M,481
11
- inquirer_textual/common/Prompt.py,sha256=yv9RKFZwYkNOD_VMMhwEyPOZwmuEMIoJ85p25fyyn8Q,827
12
- inquirer_textual/common/Shortcut.py,sha256=9mzLVnphImnehNo1HHU_gPMv-vFi5nXsb1G2CAbpuEY,297
13
- inquirer_textual/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- inquirer_textual/common/defaults.py,sha256=JE59yeKgCi0q_Q64PreieGbwlZVFPd7hOm4e4Ks1HZ8,673
15
- inquirer_textual/widgets/InquirerCheckbox.py,sha256=nlPLoEeLqhJ8gCLUFLdZsCW1A1zxu72ehDpU--XkBdY,3482
16
- inquirer_textual/widgets/InquirerConfirm.py,sha256=bpub1HiXIPrdNkk9FQbm8i_U6_CguN1LS2Hje_Vgzsc,3026
17
- inquirer_textual/widgets/InquirerEditor.py,sha256=f9H5iCevPOzJCYVIplAvedOgkmf-YVoBFwLiXn4u_58,1978
18
- inquirer_textual/widgets/InquirerMulti.py,sha256=5xwkDA9T9wZB3OOh6w7ZUiW689-bASndpCXIowfOPU0,1616
19
- inquirer_textual/widgets/InquirerNumber.py,sha256=6fH5V9tBj1G5BvTLWVpECLfGYRGbWCGMUHHK8g3BVVA,2083
20
- inquirer_textual/widgets/InquirerPath.py,sha256=K862dhAc_F36w7cJgv3HxGdvOq44bbsISjPq-xw5NJQ,3158
21
- inquirer_textual/widgets/InquirerPattern.py,sha256=z9EnwN6AawU0IH_e86Fpf-arkpyTl8nLMjsj1G5nBOc,6713
22
- inquirer_textual/widgets/InquirerSecret.py,sha256=Auysoj98l6Km__fUAsTOMtq4EN_LJyYuye8cf04UXN8,1629
23
- inquirer_textual/widgets/InquirerSelect.py,sha256=jLzww7O0ezf9OCBevAyeCih9KjUJHWZ7N-Uw2sGfa4E,3541
24
- inquirer_textual/widgets/InquirerText.py,sha256=69xnsrmgcE1xKb_lmtQVWSFLlomvd0Fttk48kLF6_os,2279
25
- inquirer_textual/widgets/InquirerWidget.py,sha256=TUU68Bef4A-S1bomgR0uFiVcQbfudrH-Vp9_h3WJgDg,1060
26
- inquirer_textual/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
- inquirer_textual-0.4.0.dist-info/METADATA,sha256=tsJd4eF71LuYH7XXIZL8_sr3M5UuP4Kmt3XzGYmfYQ4,2410
28
- inquirer_textual-0.4.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
29
- inquirer_textual-0.4.0.dist-info/licenses/LICENSE,sha256=fJuRou64yfkof3ZFdeHcgk7K8pqxis6SBr-vtUEgBuA,1073
30
- inquirer_textual-0.4.0.dist-info/RECORD,,