Skip to content

Commit

Permalink
captions
Browse files Browse the repository at this point in the history
  • Loading branch information
soldni committed Oct 19, 2022
1 parent 5053af4 commit 88825bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/springs/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ def wrap_main_method(
title="Registered Resolvers",
columns=["Resolver Name"],
values=[(r,) for r in sorted(all_resolvers())],
caption=(
"Resolvers use syntax ${resolver_name:'arg1','arg2'}. "
"For more information, visit https://omegaconf.readthedocs.io/"
"en/latest/custom_resolvers.html"
)
)

if opts.nicknames:
Expand All @@ -246,6 +251,12 @@ def wrap_main_method(
title="Registered Nicknames",
columns=["Nickname", "Path"],
values=NicknameRegistry().all(),
caption=(
"Nicknames are invoked via: "
"${sp.from_node:nickname,'path.to.key1=value1',...}. "
"\nOverride keys are optional (but quotes are required)."

)
)

# Print default options if requested py the user
Expand Down
12 changes: 11 additions & 1 deletion src/springs/rich_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from argparse import ArgumentParser, HelpFormatter
import os
from typing import IO, Any, Dict, Optional, Sequence, Type, Union

from omegaconf import DictConfig, ListConfig
Expand All @@ -21,6 +22,7 @@ def print_table(
columns: Sequence[str],
values: Sequence[Sequence[Any]],
colors: Optional[Sequence[str]] = None,
caption: Optional[str] = None,
):
colors = list(
colors or ["magenta", "cyan", "red", "green", "yellow", "blue"]
Expand All @@ -29,13 +31,21 @@ def print_table(
# repeat colors if we have more columns than colors
colors = colors * (len(columns) // len(colors) + 1)

min_width = min(
max(len(title), len(caption or '')) + 2,
os.get_terminal_size().columns - 2
)

table = Table(
*(
Column(column, justify="center", style=color, vertical="middle")
for column, color in zip(columns, colors)
),
title=f"\n{title}",
min_width=len(title) + 2,
min_width=min_width,
caption=caption,
title_style="bold",
caption_style="grey74"
)
for row in values:
table.add_row(*row)
Expand Down

0 comments on commit 88825bb

Please sign in to comment.