Skip to content

Commit

Permalink
Fine tune parameter controls label format
Browse files Browse the repository at this point in the history
  • Loading branch information
liancheng committed Sep 5, 2023
1 parent 636f114 commit d493678
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions trogon/widgets/parameter_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d493678

Please sign in to comment.