5 Commits

Author SHA1 Message Date
ee67bcb768 Merge pull request 'Fix code wrapping for syntax-highlighted output' (#3) from hotfix/code-wrap into main
All checks were successful
Release / checks (3.12) (push) Successful in -26s
Release / checks (3.13) (push) Successful in -24s
Release / checks (3.14) (push) Successful in -22s
Release / release (push) Successful in -11s
CI / lint (push) Successful in -27s
CI / typecheck (push) Successful in -23s
CI / test (3.12) (push) Successful in -27s
CI / test (3.13) (push) Successful in -26s
CI / test (3.14) (push) Successful in -26s
2026-04-04 15:06:49 -07:00
868656ea12 Bump version to 0.3.1
All checks were successful
CI / lint (pull_request) Successful in -25s
CI / typecheck (pull_request) Successful in -22s
CI / test (3.12) (pull_request) Successful in -24s
CI / test (3.13) (pull_request) Successful in -23s
CI / test (3.14) (pull_request) Successful in -26s
2026-04-04 14:57:45 -07:00
7df3acde9b fix: enable word wrapping for syntax-highlighted code output
Long code lines were clipped at the terminal width, making them
unreadable. Pass word_wrap=True to all Syntax() calls so lines wrap
instead of being cut off.
2026-04-04 14:47:21 -07:00
579df72869 Merge pull request 'Bump version to 0.3.0' (#2) from dev into main
All checks were successful
CI / lint (push) Successful in -28s
CI / test (3.12) (push) Successful in -24s
CI / test (3.13) (push) Successful in -23s
CI / test (3.14) (push) Successful in -26s
CI / typecheck (push) Successful in -25s
Release / checks (3.12) (push) Successful in -24s
Release / checks (3.13) (push) Successful in -21s
Release / checks (3.14) (push) Successful in -21s
Release / release (push) Successful in -1s
2026-04-04 07:00:54 -07:00
598450d9e2 Merge pull request 'Merge dev into main' (#1) from dev into main
All checks were successful
CI / lint (push) Successful in -28s
CI / typecheck (push) Successful in -24s
CI / test (3.12) (push) Successful in -24s
CI / test (3.13) (push) Successful in -23s
CI / test (3.14) (push) Successful in -24s
2026-04-04 06:42:41 -07:00
5 changed files with 72 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
[project]
name = "rp"
version = "0.3.0"
version = "0.3.1"
description = "Rich print files — markdown, JSON, code, and more — beautifully in your terminal"
readme = "README.md"
license = "MIT"

View File

@@ -2,6 +2,6 @@
from __future__ import annotations
__version__ = "0.3.0"
__version__ = "0.3.1"
__author__ = "Yunxiao Xu"
__license__ = "MIT"

View File

@@ -83,12 +83,20 @@ def render(
except (SyntaxError, ValueError):
log_debug(options.debug, "render: invalid JSON, falling back to syntax")
renderable = Syntax(
content, "json", theme=options.theme, line_numbers=line_numbers
content,
"json",
theme=options.theme,
line_numbers=line_numbers,
word_wrap=True,
)
else:
try:
renderable = Syntax(
content, file_type, theme=options.theme, line_numbers=line_numbers
content,
file_type,
theme=options.theme,
line_numbers=line_numbers,
word_wrap=True,
)
except Exception:
log_debug(
@@ -96,7 +104,11 @@ def render(
f"render: unknown lexer {file_type!r}, falling back to plain text",
)
renderable = Syntax(
content, "text", theme=options.theme, line_numbers=line_numbers
content,
"text",
theme=options.theme,
line_numbers=line_numbers,
word_wrap=True,
)
padded = Padding(renderable, (1, 2))

View File

@@ -94,6 +94,7 @@ class TestRenderJson:
"json",
theme="monokai",
line_numbers=False,
word_wrap=True,
)
@@ -113,6 +114,7 @@ class TestRenderCode:
"python",
theme="monokai",
line_numbers=True,
word_wrap=True,
)
def test_renders_unknown_type_as_text_fallback(self, capture_console) -> None:
@@ -136,11 +138,13 @@ class TestRenderCode:
assert mock_syntax.call_args_list[0].kwargs == {
"theme": "monokai",
"line_numbers": True,
"word_wrap": True,
}
assert mock_syntax.call_args_list[1].args == ("some content", "text")
assert mock_syntax.call_args_list[1].kwargs == {
"theme": "monokai",
"line_numbers": True,
"word_wrap": True,
}
def test_renders_rust(self, capture_console) -> None:
@@ -156,9 +160,59 @@ class TestRenderCode:
"rust",
theme="monokai",
line_numbers=True,
word_wrap=True,
)
class TestCodeWrap:
"""Code wrapping (word_wrap) for syntax-highlighted output."""
def test_python_syntax_has_word_wrap(
self, capture_console, sample_python: str
) -> None:
opts = RenderOptions(pager=False)
with patch("rp.render.Syntax", wraps=Syntax) as mock_syntax:
render(sample_python, "python", capture_console, opts)
mock_syntax.assert_called_once()
assert mock_syntax.call_args.kwargs["word_wrap"] is True
def test_long_line_wraps_in_output(self, capture_console) -> None:
long_line = "x = " + "'a' * " * 200 + "1"
opts = RenderOptions(pager=False, line_numbers=False)
render(long_line, "python", capture_console, opts)
output = capture_console.file.getvalue()
assert len(output) > 0
lines = output.split("\n")
non_empty = [line for line in lines if line.strip()]
assert len(non_empty) > 1, "Long line should wrap across multiple visual lines"
def test_text_fallback_has_word_wrap(self, capture_console) -> None:
opts = RenderOptions(pager=False)
def raise_on_bad_lexer(*args, **kwargs):
if args[1] == "unknown_xyz":
raise Exception("bad lexer")
return Syntax(*args, **kwargs)
with patch("rp.render.Syntax", side_effect=raise_on_bad_lexer) as mock_syntax:
render("some text", "unknown_xyz", capture_console, opts)
fallback_call = mock_syntax.call_args_list[-1]
assert fallback_call.args[1] == "text"
assert fallback_call.kwargs["word_wrap"] is True
def test_json_fallback_has_word_wrap(self, capture_console) -> None:
opts = RenderOptions(pager=False)
with patch("rp.render.Syntax", wraps=Syntax) as mock_syntax:
render("{invalid}", "json", capture_console, opts)
mock_syntax.assert_called_once()
assert mock_syntax.call_args.kwargs["word_wrap"] is True
class TestLineNumbers:
"""Line number auto-detection logic."""

2
uv.lock generated
View File

@@ -339,7 +339,7 @@ wheels = [
[[package]]
name = "rp"
version = "0.3.0"
version = "0.3.1"
source = { editable = "." }
dependencies = [
{ name = "pygments" },