From 3a34cb6251b5a27009aa5f7050f1d754153b18a5 Mon Sep 17 00:00:00 2001 From: Cheng Lian Date: Tue, 5 Sep 2023 09:09:58 -0700 Subject: [PATCH 1/2] Fine tune parameter controls label format --- trogon/widgets/parameter_controls.py | 36 +++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/trogon/widgets/parameter_controls.py b/trogon/widgets/parameter_controls.py index 3ea3b13..f75fd23 100644 --- a/trogon/widgets/parameter_controls.py +++ b/trogon/widgets/parameter_controls.py @@ -6,7 +6,7 @@ import click from rich.text import Text -from textual import log, on +from textual import on from textual.app import ComposeResult from textual.containers import Vertical, Horizontal from textual.css.query import NoMatches @@ -406,23 +406,27 @@ def _make_command_form_control_label( is_required: bool, multiple: bool, ) -> Text: - if isinstance(name, str): - text = Text.from_markup( - f"{name}[dim]{' multiple' if multiple else ''} {type.name}[/] {' [b red]*[/]required' if is_required else ''}" - ) - else: - names = Text(" / ", style="dim").join([Text(n) for n in name]) - text = Text.from_markup( - f"{names}[dim]{' multiple' if multiple else ''} {type.name}[/] {' [b red]*[/]required' if is_required else ''}" - ) + def yield_segments() -> Iterable[Text]: + if isinstance(name, str): + yield Text(name) + else: + yield Text(" / ", style="dim").join([Text(n) for n in name]) + + if multiple: + yield Text("multiple", style="dim") + + yield Text(type.name, style="dim") + + if is_required: + yield Text.assemble(Text("*", style="b red"), "required") - if isinstance(type, (click.IntRange, click.FloatRange)): - if type.min is not None: - text = Text.assemble(text, Text(f"min={type.min} ", "dim")) - if type.max is not None: - text = Text.assemble(text, Text(f"max={type.max}", "dim")) + if isinstance(type, (click.IntRange, click.FloatRange)): + if type.min is not None: + yield Text(f"min={type.min}", style="dim") + if type.max is not None: + yield Text(f"max={type.max}", style="dim") - return text + return Text(" ").join(yield_segments()) def focus(self, scroll_visible: bool = True): if self.first_control is not None: From c0e0f1a402924d30f25e88b52d3c0c6e974088f8 Mon Sep 17 00:00:00 2001 From: Cheng Lian Date: Thu, 1 Aug 2024 09:17:46 -0700 Subject: [PATCH 2/2] Fix text style --- trogon/widgets/parameter_controls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trogon/widgets/parameter_controls.py b/trogon/widgets/parameter_controls.py index f75fd23..b00a349 100644 --- a/trogon/widgets/parameter_controls.py +++ b/trogon/widgets/parameter_controls.py @@ -410,7 +410,7 @@ def yield_segments() -> Iterable[Text]: if isinstance(name, str): yield Text(name) else: - yield Text(" / ", style="dim").join([Text(n) for n in name]) + yield Text(" / ").join([Text(n) for n in name]) if multiple: yield Text("multiple", style="dim")