Skip to content

Commit 981c48d

Browse files
committed
Support dynamic default values
Typer allows passing a `default_factory` to options and arguments, which is a callable that will be used at runtime to determine the default value. The Textual application created by Trogon crashes when this is used, because it tries to convert the str representation of the callable function for display when it should be converting the result of calling that function instead. This change ensures dynamic default values do not crash the application, and has the effect of setting the default value appropriately in the TUI.
1 parent eaa9e68 commit 981c48d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

trogon/widgets/parameter_controls.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ def compose(self) -> ComposeResult:
157157
for default_value, control_widget in zip(
158158
default_value_tuple, widget_group
159159
):
160-
self._apply_default_value(control_widget, default_value)
160+
if isinstance(default_value, Callable):
161+
self._apply_default_value(control_widget, default_value())
162+
else:
163+
self._apply_default_value(control_widget, default_value)
161164
yield control_widget
162165
# Keep track of the first control we render, for easy focus
163166
if first_focus_control is None:

0 commit comments

Comments
 (0)