TextEditor
Base classes
| Name |
Children |
Inherits |
Editor promptantic.textual.editors Base of all editors: a node, its path in the value, and an error line. |
|
|
⋔ Inheritance diagram
graph TD
2070812812["editors.TextEditor"]
2997256436["editors.Editor"]
4188532303["widget.Widget"]
3946681048["dom.DOMNode"]
53685856["message_pump.MessagePump"]
2751680898["builtins.object"]
2997256436 --> 2070812812
4188532303 --> 2997256436
3946681048 --> 4188532303
53685856 --> 3946681048
2751680898 --> 53685856
🛈 DocStrings
Bases: Editor
Typed input: text, numbers, or free JSON.
Source code in src/promptantic/textual/editors.py
| class TextEditor(Editor):
"""Typed input: text, numbers, or free JSON."""
node: StringNode | NumberNode | AnyNode
def compose(self) -> ComposeResult:
node = self.node
text = "" if self.initial in (UNSET, None) else self._format(self.initial)
input_type = "text"
if isinstance(node, NumberNode):
input_type = "integer" if node.integer else "number"
yield Input(
value=text,
placeholder=_hint(node),
password=isinstance(node, StringNode) and node.secret,
type=input_type,
compact=True,
)
yield self.errors_widget()
def _format(self, value: Any) -> str:
if isinstance(self.node, AnyNode):
return json.dumps(value)
return str(value)
def get_value(self) -> Any | Unset:
text = self.query_one(Input).value
value = parse_text(self.node, text)
return None if value is UNSET and self.node.nullable and text == "" else value
def on_input_changed(self, event: Input.Changed) -> None:
event.stop()
self.check()
|
:fa-brands-github: Show source on GitHub