Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fine tune parameter controls label format #58

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ''}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The {name} part here is a bug as Text.plain is used when a Text object is referenced in an f-string, so we lose the dim style in the rendered result.

However, it looks better without the dim, so I did not include the dim in this PR.

)
def yield_segments() -> Iterable[Text]:
if isinstance(name, str):
yield Text(name)
else:
yield Text(" / ").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