Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet
### Fixed

- Preserve trailing newlines when printing console markup from stdin (#80).

## [1.8.1] - 2025-07-04

Expand Down
1 change: 1 addition & 0 deletions src/rich_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ def print_usage() -> None:
renderable,
width=None if max_width <= 0 else max_width,
soft_wrap=soft,
end="" if resource_format == PRINT and resource == "-" else "\n",
justify=justify,
)
except Exception as error:
Expand Down
32 changes: 32 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

import click
from click import Command
from click.decorators import FC, Parameter
Expand Down Expand Up @@ -39,3 +41,33 @@ def _param_memo_safe(f: FC, param: Parameter) -> None:

runner = CliRunner()
runner.invoke(main)


@pytest.mark.parametrize("soft", [False, True])
@pytest.mark.parametrize(
("source", "expected"),
[
("", ""),
("hello", "hello"),
("hello\n", "hello\n"),
("hello\n\n", "hello\n\n"),
("[bold]hello[/bold]\n", "hello\n"),
],
)
def test_print_stdin_preserves_line_endings(soft, source, expected):
import rich_cli.__main__ as cli

args = ["-", "--print"]
if soft:
args.append("--soft")
result = CliRunner().invoke(cli.main, args, input=source)
assert result.exit_code == 0, result.output
assert result.output == expected


def test_print_argument_keeps_terminal_newline():
import rich_cli.__main__ as cli

result = CliRunner().invoke(cli.main, ["hello", "--print"])
assert result.exit_code == 0, result.output
assert result.output == "hello\n"