Skip to content

Commit d493678

Browse files
committed
Fine tune parameter controls label format
1 parent 636f114 commit d493678

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

trogon/widgets/parameter_controls.py

+20-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import click
88
from rich.text import Text
9-
from textual import log, on
9+
from textual import on
1010
from textual.app import ComposeResult
1111
from textual.containers import Vertical, Horizontal
1212
from textual.css.query import NoMatches
@@ -406,23 +406,27 @@ def _make_command_form_control_label(
406406
is_required: bool,
407407
multiple: bool,
408408
) -> Text:
409-
if isinstance(name, str):
410-
text = Text.from_markup(
411-
f"{name}[dim]{' multiple' if multiple else ''} {type.name}[/] {' [b red]*[/]required' if is_required else ''}"
412-
)
413-
else:
414-
names = Text(" / ", style="dim").join([Text(n) for n in name])
415-
text = Text.from_markup(
416-
f"{names}[dim]{' multiple' if multiple else ''} {type.name}[/] {' [b red]*[/]required' if is_required else ''}"
417-
)
409+
def yield_segments() -> Iterable[Text]:
410+
if isinstance(name, str):
411+
yield Text(name)
412+
else:
413+
yield Text(" / ", style="dim").join([Text(n) for n in name])
414+
415+
if multiple:
416+
yield Text("multiple", style="dim")
417+
418+
yield Text(type.name, style="dim")
419+
420+
if is_required:
421+
yield Text.assemble(Text("*", style="b red"), "required")
418422

419-
if isinstance(type, (click.IntRange, click.FloatRange)):
420-
if type.min is not None:
421-
text = Text.assemble(text, Text(f"min={type.min} ", "dim"))
422-
if type.max is not None:
423-
text = Text.assemble(text, Text(f"max={type.max}", "dim"))
423+
if isinstance(type, (click.IntRange, click.FloatRange)):
424+
if type.min is not None:
425+
yield Text(f"min={type.min}", style="dim")
426+
if type.max is not None:
427+
yield Text(f"max={type.max}", style="dim")
424428

425-
return text
429+
return Text(" ").join(yield_segments())
426430

427431
def focus(self, scroll_visible: bool = True):
428432
if self.first_control is not None:

0 commit comments

Comments
 (0)