Skip to content

Commit

Permalink
Merge pull request #192 from xen0n/really-fix-issue181
Browse files Browse the repository at this point in the history
Fix incorrectly cropped lines after #187
  • Loading branch information
xen0n authored Sep 9, 2024
2 parents 35d89b0 + c63a0ac commit 2d1c67b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions ruyi/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"__main__.py",
)


def is_called_as_ruyi(argv0: str) -> bool:
return os.path.basename(argv0).lower() in ALLOWED_RUYI_ENTRYPOINT_NAMES

Expand Down
6 changes: 5 additions & 1 deletion ruyi/log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def log_time_formatter(x: datetime.datetime) -> Text:


STDOUT_CONSOLE = Console(file=sys.stdout, highlight=False, soft_wrap=True)
DEBUG_CONSOLE = Console(file=sys.stderr, log_time_format=log_time_formatter, soft_wrap=True)
DEBUG_CONSOLE = Console(
file=sys.stderr,
log_time_format=log_time_formatter,
soft_wrap=True,
)
LOG_CONSOLE = Console(file=sys.stderr, highlight=False, soft_wrap=True)
PORCELAIN_SINK = PorcelainOutput(sys.stderr.buffer)

Expand Down
15 changes: 14 additions & 1 deletion ruyi/utils/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def __rich_console__(
console: Console,
options: ConsoleOptions,
) -> RenderResult:
# re-enable non-wrapping options locally for code blocks
render_options = options.update(no_wrap=True, overflow="ignore")

code = str(self.text).rstrip()
syntax = Syntax(
code,
Expand All @@ -34,10 +37,20 @@ def __rich_console__(
word_wrap=False,
padding=0,
)
return syntax.highlight(code).__rich_console__(console, options)
return syntax.highlight(code).__rich_console__(console, render_options)


class RuyiStyledMarkdown(Markdown):
elements = Markdown.elements
elements["fence"] = NonWrappingCodeBlock
elements["heading_open"] = SlimHeading

def __rich_console__(
self,
console: Console,
options: ConsoleOptions,
) -> RenderResult:
# we have to undo the ruyi-global console's non-wrapping setting
# for proper CLI rendering of long lines
render_options = options.update(no_wrap=False, overflow="fold")
return super().__rich_console__(console, render_options)

0 comments on commit 2d1c67b

Please sign in to comment.