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.
- inquirer_textual/InquirerApp.py +22 -24
- inquirer_textual/common/Choice.py +0 -3
- inquirer_textual/common/ChoiceLabel.py +5 -14
- inquirer_textual/common/{Prompt.py → PromptMessage.py} +3 -3
- inquirer_textual/common/Result.py +15 -0
- inquirer_textual/prompts.py +45 -57
- inquirer_textual/version.py +1 -1
- inquirer_textual/widgets/InquirerCheckbox.py +22 -30
- inquirer_textual/widgets/InquirerConfirm.py +11 -31
- inquirer_textual/widgets/InquirerMulti.py +17 -16
- inquirer_textual/widgets/InquirerNumber.py +12 -20
- inquirer_textual/widgets/InquirerSecret.py +6 -5
- inquirer_textual/widgets/InquirerSelect.py +28 -32
- inquirer_textual/widgets/InquirerText.py +7 -10
- inquirer_textual/widgets/InquirerWidget.py +2 -8
- {inquirer_textual-0.4.0.dist-info → inquirer_textual-1.0.0.dist-info}/METADATA +3 -42
- inquirer_textual-1.0.0.dist-info/RECORD +25 -0
- inquirer_textual/common/Answer.py +0 -22
- inquirer_textual/common/InquirerResult.py +0 -24
- inquirer_textual/common/defaults.py +0 -24
- inquirer_textual/widgets/InquirerEditor.py +0 -72
- inquirer_textual/widgets/InquirerPath.py +0 -95
- inquirer_textual/widgets/InquirerPattern.py +0 -175
- inquirer_textual-0.4.0.dist-info/RECORD +0 -30
- {inquirer_textual-0.4.0.dist-info → inquirer_textual-1.0.0.dist-info}/WHEEL +0 -0
- {inquirer_textual-0.4.0.dist-info → inquirer_textual-1.0.0.dist-info}/licenses/LICENSE +0 -0
inquirer_textual/InquirerApp.py
CHANGED
|
@@ -10,19 +10,22 @@ from textual.binding import Binding, BindingsMap
|
|
|
10
10
|
from textual.widgets import Footer
|
|
11
11
|
|
|
12
12
|
from inquirer_textual.common.InquirerHeader import InquirerHeader
|
|
13
|
-
from inquirer_textual.common.
|
|
13
|
+
from inquirer_textual.common.Result import Result
|
|
14
14
|
from inquirer_textual.common.Shortcut import Shortcut
|
|
15
|
-
from inquirer_textual.common.defaults import DEFAULT_THEME
|
|
16
15
|
from inquirer_textual.widgets.InquirerWidget import InquirerWidget
|
|
17
16
|
|
|
18
17
|
T = TypeVar('T')
|
|
19
18
|
|
|
20
19
|
|
|
21
|
-
class InquirerApp(App[
|
|
20
|
+
class InquirerApp(App[Result[T]], inherit_bindings=False): # type: ignore[call-arg]
|
|
22
21
|
CSS = """
|
|
22
|
+
App {
|
|
23
|
+
background: black;
|
|
24
|
+
}
|
|
23
25
|
Screen {
|
|
24
26
|
border-top: none;
|
|
25
27
|
border-bottom: none;
|
|
28
|
+
background: transparent;
|
|
26
29
|
height: auto;
|
|
27
30
|
}
|
|
28
31
|
"""
|
|
@@ -32,21 +35,18 @@ class InquirerApp(App[InquirerResult[T]], inherit_bindings=False): # type: igno
|
|
|
32
35
|
Binding("ctrl+d", "quit", "Quit", show=False, priority=True)
|
|
33
36
|
]
|
|
34
37
|
|
|
35
|
-
def __init__(self
|
|
36
|
-
self._theme = theme
|
|
38
|
+
def __init__(self) -> None:
|
|
37
39
|
self.widget: InquirerWidget | None = None
|
|
38
40
|
self.shortcuts: list[Shortcut] | None = None
|
|
39
41
|
self.header: str | list[str] | None = None
|
|
40
42
|
self.show_footer: bool = False
|
|
41
|
-
self.result:
|
|
43
|
+
self.result: Result[T] | None = None
|
|
42
44
|
self.result_ready: Event | None = None
|
|
43
45
|
self.inquiry_func: Callable[[InquirerApp[T]], None] | None = None
|
|
44
46
|
self.inquiry_func_stop: bool = False
|
|
45
47
|
super().__init__()
|
|
46
48
|
|
|
47
49
|
def on_mount(self) -> None:
|
|
48
|
-
self.register_theme(DEFAULT_THEME)
|
|
49
|
-
self.theme = self._theme
|
|
50
50
|
self._update_bindings()
|
|
51
51
|
if self.inquiry_func:
|
|
52
52
|
self.run_worker(self.inquiry_func_worker, thread=True)
|
|
@@ -63,24 +63,21 @@ class InquirerApp(App[InquirerResult[T]], inherit_bindings=False): # type: igno
|
|
|
63
63
|
if self.inquiry_func:
|
|
64
64
|
self.inquiry_func(self)
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
def action_shortcut(self, command: str):
|
|
67
67
|
value = self.widget.current_value() if self.widget else None
|
|
68
|
-
|
|
68
|
+
self._handle_result(command, value)
|
|
69
69
|
|
|
70
70
|
async def action_quit(self):
|
|
71
|
-
|
|
71
|
+
self._handle_result('quit', None)
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
def on_inquirer_widget_submit(self, event: InquirerWidget.Submit) -> None:
|
|
74
|
+
self._handle_result(event.command, event.value)
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
def _handle_result(self, command: str | None, value: Any | None):
|
|
77
77
|
if self.result_ready is not None:
|
|
78
|
-
self.result =
|
|
79
|
-
command)
|
|
78
|
+
self.result = Result(command, value) # type: ignore[arg-type]
|
|
80
79
|
self.result_ready.set()
|
|
81
80
|
else:
|
|
82
|
-
if self.widget:
|
|
83
|
-
await self.widget.set_selected_value(value)
|
|
84
81
|
self.call_after_refresh(lambda: self._terminate(command, value))
|
|
85
82
|
|
|
86
83
|
def _terminate(self, command: str | None = None, value: Any | None = None):
|
|
@@ -88,9 +85,9 @@ class InquirerApp(App[InquirerResult[T]], inherit_bindings=False): # type: igno
|
|
|
88
85
|
if self.result_ready:
|
|
89
86
|
self.result_ready.set()
|
|
90
87
|
if command is not None:
|
|
91
|
-
self.app.exit(
|
|
88
|
+
self.app.exit(Result(command, value))
|
|
92
89
|
else:
|
|
93
|
-
self.exit(
|
|
90
|
+
self.exit(value)
|
|
94
91
|
|
|
95
92
|
def compose(self) -> ComposeResult:
|
|
96
93
|
if self.header is not None:
|
|
@@ -105,7 +102,7 @@ class InquirerApp(App[InquirerResult[T]], inherit_bindings=False): # type: igno
|
|
|
105
102
|
if self.widget:
|
|
106
103
|
self.call_after_refresh(self.widget.focus)
|
|
107
104
|
|
|
108
|
-
def prompt(self, widget: InquirerWidget, shortcuts: list[Shortcut] | None = None) ->
|
|
105
|
+
def prompt(self, widget: InquirerWidget, shortcuts: list[Shortcut] | None = None) -> Result[T]:
|
|
109
106
|
if shortcuts:
|
|
110
107
|
self.shortcuts = shortcuts
|
|
111
108
|
self.show_footer = True
|
|
@@ -138,7 +135,7 @@ class InquirerApp(App[InquirerResult[T]], inherit_bindings=False): # type: igno
|
|
|
138
135
|
auto_pilot: AutopilotCallbackType | None = None,
|
|
139
136
|
loop: AbstractEventLoop | None = None,
|
|
140
137
|
inquiry_func: Callable[[InquirerApp[T]], None] | None = None,
|
|
141
|
-
) ->
|
|
138
|
+
) -> Result[T]:
|
|
142
139
|
if not self.inquiry_func:
|
|
143
140
|
self.inquiry_func = inquiry_func
|
|
144
141
|
return super().run(
|
|
@@ -153,6 +150,7 @@ class InquirerApp(App[InquirerResult[T]], inherit_bindings=False): # type: igno
|
|
|
153
150
|
|
|
154
151
|
def get_theme_variable_defaults(self) -> dict[str, str]:
|
|
155
152
|
return {
|
|
156
|
-
'
|
|
157
|
-
'
|
|
153
|
+
'select-question-mark': '#e5c07b',
|
|
154
|
+
'select-list-item-highlight-foreground': '#61afef',
|
|
155
|
+
'input-color': '#98c379'
|
|
158
156
|
}
|
|
@@ -1,27 +1,18 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from rich.text import Text
|
|
4
3
|
from textual.widgets import Label
|
|
5
4
|
|
|
6
5
|
from inquirer_textual.common.Choice import Choice
|
|
7
|
-
from inquirer_textual.common.defaults import DEFAULT_THEME, POINTER_CHARACTER
|
|
8
6
|
|
|
9
7
|
|
|
10
8
|
class ChoiceLabel(Label):
|
|
11
|
-
def __init__(self, item: str | Choice
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
def __init__(self, item: str | Choice):
|
|
10
|
+
super().__init__(f' {item if isinstance(item, str) else item.name}')
|
|
11
|
+
self._text = item if isinstance(item, str) else item.name
|
|
14
12
|
self.item = item
|
|
15
13
|
|
|
16
|
-
def _get_text(self, item: str | Choice, pattern: str | None = None) -> Text:
|
|
17
|
-
result = Text(item if isinstance(item, str) else item.name)
|
|
18
|
-
if pattern:
|
|
19
|
-
result.highlight_words([pattern], style=self.app.current_theme.accent or DEFAULT_THEME.accent,
|
|
20
|
-
case_sensitive=False)
|
|
21
|
-
return result
|
|
22
|
-
|
|
23
14
|
def add_pointer(self):
|
|
24
|
-
self.update(
|
|
15
|
+
self.update(f'\u276f {self._text}')
|
|
25
16
|
|
|
26
17
|
def remove_pointer(self):
|
|
27
|
-
self.update(
|
|
18
|
+
self.update(f' {self._text}')
|
|
@@ -4,9 +4,9 @@ from textual.widget import Widget
|
|
|
4
4
|
from textual.widgets import Static, Label
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
class
|
|
7
|
+
class PromptMessage(Widget):
|
|
8
8
|
DEFAULT_CSS = """
|
|
9
|
-
|
|
9
|
+
PromptMessage {
|
|
10
10
|
width: auto;
|
|
11
11
|
height: auto;
|
|
12
12
|
}
|
|
@@ -16,7 +16,7 @@ class Prompt(Widget):
|
|
|
16
16
|
}
|
|
17
17
|
#prompt-message-question-mark {
|
|
18
18
|
width: auto;
|
|
19
|
-
color: $
|
|
19
|
+
color: $select-question-mark;
|
|
20
20
|
}
|
|
21
21
|
"""
|
|
22
22
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import TypeVar, Generic
|
|
5
|
+
|
|
6
|
+
T = TypeVar('T')
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class Result(Generic[T]):
|
|
11
|
+
command: str | None
|
|
12
|
+
value: T
|
|
13
|
+
|
|
14
|
+
def __str__(self):
|
|
15
|
+
return str(self.value)
|
inquirer_textual/prompts.py
CHANGED
|
@@ -4,85 +4,73 @@ from textual.validation import Validator
|
|
|
4
4
|
|
|
5
5
|
from inquirer_textual.InquirerApp import InquirerApp
|
|
6
6
|
from inquirer_textual.common.Choice import Choice
|
|
7
|
+
from inquirer_textual.common.Result import Result
|
|
8
|
+
from inquirer_textual.common.Shortcut import Shortcut
|
|
7
9
|
from inquirer_textual.widgets.InquirerCheckbox import InquirerCheckbox
|
|
8
10
|
from inquirer_textual.widgets.InquirerConfirm import InquirerConfirm
|
|
9
|
-
from inquirer_textual.widgets.InquirerEditor import InquirerEditor
|
|
10
11
|
from inquirer_textual.widgets.InquirerMulti import InquirerMulti
|
|
11
12
|
from inquirer_textual.widgets.InquirerNumber import InquirerNumber
|
|
12
|
-
from inquirer_textual.widgets.InquirerPath import InquirerPath, PathType
|
|
13
|
-
from inquirer_textual.widgets.InquirerPattern import InquirerPattern
|
|
14
13
|
from inquirer_textual.widgets.InquirerSecret import InquirerSecret
|
|
15
14
|
from inquirer_textual.widgets.InquirerSelect import InquirerSelect
|
|
16
15
|
from inquirer_textual.widgets.InquirerText import InquirerText
|
|
17
16
|
from inquirer_textual.widgets.InquirerWidget import InquirerWidget
|
|
18
17
|
|
|
19
18
|
|
|
20
|
-
def
|
|
21
|
-
|
|
22
|
-
app: InquirerApp[list[str | Choice]] = InquirerApp()
|
|
23
|
-
app.widget = InquirerCheckbox(message, choices, enabled=enabled, mandatory=mandatory)
|
|
24
|
-
return app.run(inline=True, inline_no_clear=not clear).value
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def confirm(message: str, default: bool = False, mandatory: bool = False, clear: bool = False) -> bool:
|
|
28
|
-
app: InquirerApp[bool] = InquirerApp()
|
|
29
|
-
app.widget = InquirerConfirm(message, default=default, mandatory=mandatory)
|
|
30
|
-
return app.run(inline=True, inline_no_clear=not clear).value
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def editor(message: str, clear: bool = False) -> str:
|
|
19
|
+
def text(message: str, shortcuts: list[Shortcut] | None = None,
|
|
20
|
+
validators: Validator | Iterable[Validator] | None = None) -> Result[str]:
|
|
34
21
|
app: InquirerApp[str] = InquirerApp()
|
|
35
|
-
app.widget =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def external(widget: InquirerWidget, clear: bool = False) -> Any:
|
|
40
|
-
app: InquirerApp[Any] = InquirerApp()
|
|
41
|
-
app.widget = widget
|
|
42
|
-
return app.run(inline=True, inline_no_clear=not clear).value
|
|
22
|
+
app.widget = InquirerText(message, validators=validators)
|
|
23
|
+
app.shortcuts = shortcuts
|
|
24
|
+
app.show_footer = bool(shortcuts)
|
|
25
|
+
return app.run(inline=True)
|
|
43
26
|
|
|
44
27
|
|
|
45
|
-
def
|
|
46
|
-
app: InquirerApp[
|
|
47
|
-
app.widget =
|
|
48
|
-
|
|
28
|
+
def secret(message: str, shortcuts: list[Shortcut] | None = None) -> Result[str]:
|
|
29
|
+
app: InquirerApp[str] = InquirerApp()
|
|
30
|
+
app.widget = InquirerSecret(message)
|
|
31
|
+
app.shortcuts = shortcuts
|
|
32
|
+
app.show_footer = bool(shortcuts)
|
|
33
|
+
return app.run(inline=True)
|
|
49
34
|
|
|
50
35
|
|
|
51
|
-
def number(message: str,
|
|
36
|
+
def number(message: str, shortcuts: list[Shortcut] | None = None) -> Result[int]:
|
|
52
37
|
app: InquirerApp[int] = InquirerApp()
|
|
53
|
-
app.widget = InquirerNumber(message
|
|
54
|
-
|
|
38
|
+
app.widget = InquirerNumber(message)
|
|
39
|
+
app.shortcuts = shortcuts
|
|
40
|
+
app.show_footer = bool(shortcuts)
|
|
41
|
+
return app.run(inline=True)
|
|
55
42
|
|
|
56
43
|
|
|
57
|
-
def
|
|
58
|
-
|
|
59
|
-
app: InquirerApp[
|
|
60
|
-
app.widget =
|
|
61
|
-
|
|
44
|
+
def confirm(message: str, shortcuts: list[Shortcut] | None = None, default: bool = False, mandatory: bool = True) -> \
|
|
45
|
+
Result[bool]:
|
|
46
|
+
app: InquirerApp[bool] = InquirerApp()
|
|
47
|
+
app.widget = InquirerConfirm(message, default=default, mandatory=mandatory)
|
|
48
|
+
app.shortcuts = shortcuts
|
|
49
|
+
app.show_footer = bool(shortcuts)
|
|
50
|
+
return app.run(inline=True)
|
|
62
51
|
|
|
63
52
|
|
|
64
|
-
def
|
|
65
|
-
|
|
53
|
+
def select(message: str, choices: list[str | Choice], shortcuts: list[Shortcut] | None = None,
|
|
54
|
+
default: str | Choice | None = None, mandatory: bool = True) -> Result[str | Choice]:
|
|
66
55
|
app: InquirerApp[str | Choice] = InquirerApp()
|
|
67
|
-
app.widget =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def secret(message: str, mandatory: bool = False, clear: bool = False) -> str:
|
|
72
|
-
app: InquirerApp[str] = InquirerApp()
|
|
73
|
-
app.widget = InquirerSecret(message, mandatory=mandatory)
|
|
74
|
-
return app.run(inline=True, inline_no_clear=not clear).value
|
|
56
|
+
app.widget = InquirerSelect(message, choices, default, mandatory)
|
|
57
|
+
app.shortcuts = shortcuts
|
|
58
|
+
app.show_footer = bool(shortcuts)
|
|
59
|
+
return app.run(inline=True)
|
|
75
60
|
|
|
76
61
|
|
|
77
|
-
def
|
|
78
|
-
|
|
79
|
-
app: InquirerApp[str | Choice] = InquirerApp()
|
|
80
|
-
app.widget =
|
|
81
|
-
|
|
62
|
+
def checkbox(message: str, choices: list[str | Choice], shortcuts: list[Shortcut] | None = None,
|
|
63
|
+
enabled: list[str | Choice] | None = None) -> Result[list[str | Choice]]:
|
|
64
|
+
app: InquirerApp[list[str | Choice]] = InquirerApp()
|
|
65
|
+
app.widget = InquirerCheckbox(message, choices, enabled)
|
|
66
|
+
app.shortcuts = shortcuts
|
|
67
|
+
app.show_footer = bool(shortcuts)
|
|
68
|
+
return app.run(inline=True)
|
|
82
69
|
|
|
83
70
|
|
|
84
|
-
def
|
|
85
|
-
|
|
86
|
-
app
|
|
87
|
-
app.
|
|
88
|
-
|
|
71
|
+
def multi(widgets: list[InquirerWidget], shortcuts: list[Shortcut] | None = None) -> Result[list[Any]]:
|
|
72
|
+
app: InquirerApp[list[Any]] = InquirerApp()
|
|
73
|
+
app.widget = InquirerMulti(widgets)
|
|
74
|
+
app.shortcuts = shortcuts
|
|
75
|
+
app.show_footer = bool(shortcuts)
|
|
76
|
+
return app.run(inline=True)
|
inquirer_textual/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
version = "0.
|
|
1
|
+
version = "1.0.0"
|
|
@@ -1,43 +1,46 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from textual.app import ComposeResult
|
|
4
|
-
from textual.containers import VerticalGroup
|
|
4
|
+
from textual.containers import VerticalGroup
|
|
5
5
|
from textual.widgets import ListItem, ListView
|
|
6
6
|
from typing_extensions import Self
|
|
7
7
|
|
|
8
|
-
from inquirer_textual.common.Answer import Answer
|
|
9
8
|
from inquirer_textual.common.Choice import Choice
|
|
10
9
|
from inquirer_textual.common.ChoiceCheckboxLabel import ChoiceCheckboxLabel
|
|
11
|
-
from inquirer_textual.common.
|
|
10
|
+
from inquirer_textual.common.PromptMessage import PromptMessage
|
|
12
11
|
from inquirer_textual.widgets.InquirerWidget import InquirerWidget
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
class InquirerCheckbox(InquirerWidget):
|
|
16
15
|
"""A checkbox widget that allows multiple selections from a list of choices."""
|
|
17
16
|
|
|
17
|
+
DEFAULT_CSS = """
|
|
18
|
+
#inquirer-checkbox-list-view {
|
|
19
|
+
background: transparent;
|
|
20
|
+
}
|
|
21
|
+
#inquirer-checkbox-list-view ListItem.-highlight {
|
|
22
|
+
color: $select-list-item-highlight-foreground;
|
|
23
|
+
background: transparent;
|
|
24
|
+
}
|
|
25
|
+
"""
|
|
18
26
|
BINDINGS = [
|
|
19
27
|
("space", "toggle_selected", "Toggle selection"),
|
|
20
28
|
]
|
|
21
29
|
|
|
22
|
-
def __init__(self, message: str, choices: list[str | Choice],
|
|
23
|
-
enabled: list[str | Choice] | None = None, mandatory: bool = False):
|
|
30
|
+
def __init__(self, message: str, choices: list[str | Choice], enabled: list[str | Choice] | None = None):
|
|
24
31
|
"""
|
|
25
32
|
Args:
|
|
26
33
|
message (str): The prompt message to display.
|
|
27
34
|
choices (list[str | Choice]): A list of choices to present to the user.
|
|
28
|
-
name (str | None): The name of the input field.
|
|
29
35
|
enabled (list[str | Choice] | None): A list of choices that should be pre-selected.
|
|
30
|
-
mandatory (bool): Whether at least one selection is mandatory.
|
|
31
36
|
"""
|
|
32
|
-
super().__init__(
|
|
37
|
+
super().__init__()
|
|
33
38
|
self.message = message
|
|
34
39
|
self.choices = choices
|
|
35
40
|
self.enabled = enabled
|
|
36
41
|
self.list_view: ListView | None = None
|
|
37
42
|
self.selected_label: ChoiceCheckboxLabel | None = None
|
|
38
43
|
self.selected_item: str | Choice | None = None
|
|
39
|
-
self.selected_value: list[str | Choice] | None = None
|
|
40
|
-
self.show_selected_value: bool = False
|
|
41
44
|
|
|
42
45
|
def on_mount(self):
|
|
43
46
|
self.styles.height = min(10, len(self.choices) + 1)
|
|
@@ -52,7 +55,7 @@ class InquirerCheckbox(InquirerWidget):
|
|
|
52
55
|
self.selected_item = label.item
|
|
53
56
|
|
|
54
57
|
def on_list_view_selected(self, _: ListView.Selected) -> None:
|
|
55
|
-
self.
|
|
58
|
+
self.post_message(InquirerWidget.Submit(self.current_value()))
|
|
56
59
|
|
|
57
60
|
def focus(self, scroll_visible: bool = True) -> Self:
|
|
58
61
|
if self.list_view:
|
|
@@ -64,23 +67,12 @@ class InquirerCheckbox(InquirerWidget):
|
|
|
64
67
|
labels = self.query(ChoiceCheckboxLabel)
|
|
65
68
|
return [label.item for label in labels if label.checked]
|
|
66
69
|
|
|
67
|
-
async def set_selected_value(self, value: list[str | Choice]) -> None:
|
|
68
|
-
self.selected_value = value
|
|
69
|
-
self.styles.height = 1
|
|
70
|
-
self.show_selected_value = True
|
|
71
|
-
await self.recompose()
|
|
72
|
-
|
|
73
70
|
def compose(self) -> ComposeResult:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
list_item = ListItem(ChoiceCheckboxLabel(choice))
|
|
83
|
-
items.append(list_item)
|
|
84
|
-
self.list_view = ListView(*items, id='inquirer-checkbox-list-view')
|
|
85
|
-
yield Prompt(self.message)
|
|
86
|
-
yield self.list_view
|
|
71
|
+
with VerticalGroup():
|
|
72
|
+
items: list[ListItem] = []
|
|
73
|
+
for idx, choice in enumerate(self.choices):
|
|
74
|
+
list_item = ListItem(ChoiceCheckboxLabel(choice))
|
|
75
|
+
items.append(list_item)
|
|
76
|
+
self.list_view = ListView(*items, id='inquirer-checkbox-list-view')
|
|
77
|
+
yield PromptMessage(self.message)
|
|
78
|
+
yield self.list_view
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
from
|
|
2
|
-
|
|
1
|
+
from inquirer_textual.widgets.InquirerWidget import InquirerWidget
|
|
2
|
+
from inquirer_textual.common.PromptMessage import PromptMessage
|
|
3
3
|
from textual import events
|
|
4
4
|
from textual.app import ComposeResult
|
|
5
5
|
from textual.containers import HorizontalGroup
|
|
6
6
|
from textual.widgets import Label
|
|
7
7
|
|
|
8
|
-
from inquirer_textual.common.Answer import Answer
|
|
9
|
-
from inquirer_textual.common.Prompt import Prompt
|
|
10
|
-
from inquirer_textual.widgets.InquirerWidget import InquirerWidget
|
|
11
|
-
|
|
12
8
|
|
|
13
9
|
class InquirerConfirm(InquirerWidget):
|
|
14
10
|
"""A confirmation prompt that allows the user to confirm or reject."""
|
|
@@ -20,58 +16,42 @@ class InquirerConfirm(InquirerWidget):
|
|
|
20
16
|
"""
|
|
21
17
|
can_focus = True
|
|
22
18
|
|
|
23
|
-
def __init__(self, message: str, confirm_character: str = 'y', reject_character: str = 'n',
|
|
24
|
-
|
|
19
|
+
def __init__(self, message: str, confirm_character: str = 'y', reject_character: str = 'n', default=False,
|
|
20
|
+
mandatory: bool = True):
|
|
25
21
|
"""
|
|
26
22
|
Args:
|
|
27
23
|
message (str): The prompt message to display.
|
|
28
24
|
confirm_character (str): The character to use for confirmation.
|
|
29
25
|
reject_character (str): The character to use for rejection.
|
|
30
|
-
name (str | None): The name of the prompt.
|
|
31
26
|
default (bool): The default value if the user presses Enter without input.
|
|
32
27
|
mandatory (bool): Whether a response is mandatory.
|
|
33
28
|
"""
|
|
34
|
-
super().__init__(
|
|
29
|
+
super().__init__(mandatory)
|
|
35
30
|
if len(confirm_character) != 1 or len(reject_character) != 1:
|
|
36
31
|
raise ValueError("confirm_character and reject_character must be a single character")
|
|
37
32
|
if confirm_character.lower() == reject_character.lower():
|
|
38
33
|
raise ValueError("confirm_character and reject_character must be different")
|
|
39
34
|
self.message = message
|
|
40
|
-
self.confirm_character = confirm_character
|
|
41
|
-
self.reject_character = reject_character
|
|
42
35
|
c = confirm_character if not default else confirm_character.upper()
|
|
43
36
|
r = reject_character if default else reject_character.upper()
|
|
44
37
|
self.label = Label(f'({c}/{r})')
|
|
45
38
|
self.value: bool = default
|
|
46
|
-
self.selected_value: bool | None = None
|
|
47
|
-
self.show_selected_value: bool = False
|
|
48
39
|
|
|
49
40
|
def on_key(self, event: events.Key):
|
|
50
41
|
if event.key.lower() == 'y':
|
|
51
42
|
self.value = True
|
|
52
|
-
self.
|
|
43
|
+
self.post_message(InquirerWidget.Submit(self.value))
|
|
53
44
|
elif event.key.lower() == 'n':
|
|
54
45
|
self.value = False
|
|
55
|
-
self.
|
|
46
|
+
self.post_message(InquirerWidget.Submit(self.value))
|
|
56
47
|
elif event.key == 'enter':
|
|
57
48
|
event.stop()
|
|
58
|
-
self.
|
|
49
|
+
self.post_message(InquirerWidget.Submit(self.value))
|
|
59
50
|
|
|
60
51
|
def current_value(self):
|
|
61
52
|
return self.value
|
|
62
53
|
|
|
63
|
-
async def set_selected_value(self, value: bool) -> None:
|
|
64
|
-
self.selected_value = value
|
|
65
|
-
self.styles.height = 1
|
|
66
|
-
self.show_selected_value = True
|
|
67
|
-
await self.recompose()
|
|
68
|
-
|
|
69
54
|
def compose(self) -> ComposeResult:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
yield Answer(self.confirm_character if self.selected_value else self.reject_character)
|
|
74
|
-
else:
|
|
75
|
-
with HorizontalGroup():
|
|
76
|
-
yield Prompt(self.message)
|
|
77
|
-
yield self.label
|
|
55
|
+
with HorizontalGroup():
|
|
56
|
+
yield PromptMessage(self.message)
|
|
57
|
+
yield self.label
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from typing import Any
|
|
2
2
|
|
|
3
3
|
from textual.app import ComposeResult
|
|
4
|
+
from textual.widgets import ContentSwitcher
|
|
4
5
|
|
|
5
6
|
from inquirer_textual.widgets.InquirerWidget import InquirerWidget
|
|
6
7
|
|
|
@@ -14,32 +15,32 @@ class InquirerMulti(InquirerWidget):
|
|
|
14
15
|
}
|
|
15
16
|
"""
|
|
16
17
|
|
|
17
|
-
def __init__(self, widgets:
|
|
18
|
+
def __init__(self, widgets: list[InquirerWidget]) -> None:
|
|
18
19
|
"""
|
|
19
20
|
Args:
|
|
20
|
-
widgets (
|
|
21
|
+
widgets (list[InquirerWidget]): A list of InquirerWidget instances to present in sequence.
|
|
21
22
|
"""
|
|
22
23
|
super().__init__()
|
|
23
24
|
self.widgets = widgets
|
|
24
25
|
self._current_widget_index = 0
|
|
25
|
-
self.
|
|
26
|
+
self._return_values: list[Any] = []
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
self.
|
|
30
|
-
|
|
28
|
+
def on_mount(self):
|
|
29
|
+
self.query_one(ContentSwitcher).current = f'widget-{self._current_widget_index}'
|
|
30
|
+
self.query_one(ContentSwitcher).visible_content.focus()
|
|
31
|
+
|
|
32
|
+
def on_inquirer_widget_submit(self, message: InquirerWidget.Submit) -> None:
|
|
33
|
+
self._return_values.append(message.value)
|
|
31
34
|
self._current_widget_index += 1
|
|
32
35
|
if self._current_widget_index < len(self.widgets):
|
|
33
36
|
message.stop()
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
next_widget.focus()
|
|
37
|
+
self.query_one(ContentSwitcher).current = f'widget-{self._current_widget_index}'
|
|
38
|
+
self.query_one(ContentSwitcher).visible_content.focus()
|
|
37
39
|
else:
|
|
38
|
-
message.value = self.
|
|
40
|
+
message.value = self._return_values
|
|
39
41
|
|
|
40
42
|
def compose(self) -> ComposeResult:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
yield item[1]
|
|
43
|
+
with ContentSwitcher(initial=f'widget-{self._current_widget_index}'):
|
|
44
|
+
for idx, widget in enumerate(self.widgets):
|
|
45
|
+
widget.id = f'widget-{idx}'
|
|
46
|
+
yield widget
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from typing_extensions import Self
|
|
4
|
+
|
|
3
5
|
from textual.app import ComposeResult
|
|
4
6
|
from textual.containers import HorizontalGroup
|
|
5
7
|
from textual.widgets import Input
|
|
6
|
-
from typing_extensions import Self, Literal
|
|
7
8
|
|
|
8
|
-
from inquirer_textual.common.Prompt import Prompt
|
|
9
9
|
from inquirer_textual.widgets.InquirerWidget import InquirerWidget
|
|
10
|
+
from inquirer_textual.common.PromptMessage import PromptMessage
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class InquirerNumber(InquirerWidget):
|
|
@@ -18,28 +19,24 @@ class InquirerNumber(InquirerWidget):
|
|
|
18
19
|
}
|
|
19
20
|
#inquirer-number-input {
|
|
20
21
|
border: none;
|
|
21
|
-
|
|
22
|
+
background: transparent;
|
|
23
|
+
color: $input-color;
|
|
22
24
|
padding: 0;
|
|
23
25
|
height: 1;
|
|
24
26
|
}
|
|
25
27
|
"""
|
|
26
28
|
|
|
27
|
-
def __init__(self, message: str
|
|
28
|
-
mandatory: bool = False):
|
|
29
|
+
def __init__(self, message: str):
|
|
29
30
|
"""
|
|
30
31
|
Args:
|
|
31
32
|
message (str): The prompt message to display.
|
|
32
|
-
name (str | None): The name of the input field.
|
|
33
|
-
input_type (Literal['integer', 'number']): The type of number input ('integer' or 'number').
|
|
34
|
-
mandatory (bool): Whether the input is mandatory.
|
|
35
33
|
"""
|
|
36
|
-
super().__init__(
|
|
34
|
+
super().__init__()
|
|
37
35
|
self.message = message
|
|
38
|
-
self.input_type = input_type
|
|
39
36
|
self.input: Input | None = None
|
|
40
37
|
|
|
41
|
-
def on_input_submitted(self
|
|
42
|
-
self.
|
|
38
|
+
def on_input_submitted(self, submitted: Input.Submitted):
|
|
39
|
+
self.post_message(InquirerWidget.Submit(submitted.value))
|
|
43
40
|
|
|
44
41
|
def focus(self, scroll_visible: bool = True) -> Self:
|
|
45
42
|
if self.input:
|
|
@@ -48,15 +45,10 @@ class InquirerNumber(InquirerWidget):
|
|
|
48
45
|
return super().focus(scroll_visible)
|
|
49
46
|
|
|
50
47
|
def current_value(self):
|
|
51
|
-
|
|
52
|
-
if self.input_type == 'integer':
|
|
53
|
-
return int(self.input.value)
|
|
54
|
-
elif self.input_type == 'number':
|
|
55
|
-
return float(self.input.value)
|
|
56
|
-
return None
|
|
48
|
+
return self.input.value if self.input else None
|
|
57
49
|
|
|
58
50
|
def compose(self) -> ComposeResult:
|
|
59
51
|
with HorizontalGroup():
|
|
60
|
-
yield
|
|
61
|
-
self.input = Input(id="inquirer-number-input", type=
|
|
52
|
+
yield PromptMessage(self.message)
|
|
53
|
+
self.input = Input(id="inquirer-number-input", type="integer")
|
|
62
54
|
yield self.input
|