Gallery of some requested formatters #82
hamdanal
started this conversation in
Show and tell
Replies: 2 comments
-
A formatter that wraps long lines but does not remove existing line breaks (#78): import argparse
from rich.containers import Lines
from rich.text import Text
from rich_argparse import RichHelpFormatter
class WrappedTextRichHelpFormatter(RichHelpFormatter):
def _rich_split_lines(self, text: Text, width: int) -> Lines:
lines = Lines()
for line in text.split():
lines.extend(line.wrap(self.console, width))
return lines
def _rich_fill_text(self, text: Text, width: int, indent: Text) -> Text:
lines = self._rich_split_lines(text, width)
return Text("\n").join(indent + line for line in lines) + "\n" |
Beta Was this translation helpful? Give feedback.
0 replies
-
A formatter that displays the description and epilog as markdown (#81): import argparse
from rich.markdown import Markdown
from rich_argparse import RichHelpFormatter
class MarkdownTextRichHelpFormatter(RichHelpFormatter):
def add_text(self, text: str | None) -> None: # attention, this affects "description", "epilog", "--version" and maybe other edge cases
if text is not argparse.SUPPRESS and text is not None:
self._current_section.rich_items.append(Markdown(text)) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I will use this thread to show some formatters people have requested to be included in
rich-argparse
Beta Was this translation helpful? Give feedback.
All reactions