diff --git a/rich/console.py b/rich/console.py index 994adfc0..406a088c 100644 --- a/rich/console.py +++ b/rich/console.py @@ -1723,12 +1723,13 @@ class Console: for renderable in renderables: extend(render(renderable, render_options)) else: + render_style = self.get_style(style) + new_line = Segment.line() for renderable in renderables: - extend( - Segment.apply_style( - render(renderable, render_options), self.get_style(style) - ) - ) + for line in Segment.split_lines(render(renderable, render_options)): + extend(Segment.apply_style(line, render_style)) + new_segments.append(new_line) + if new_line_start: if ( len("".join(segment.text for segment in new_segments).splitlines()) diff --git a/tests/test_text.py b/tests/test_text.py index b528608a..b6d39f59 100644 --- a/tests/test_text.py +++ b/tests/test_text.py @@ -1110,3 +1110,20 @@ def test_soft_wrap() -> None: print(repr(output)) expected = "\x1b[37;44m Hello World \x1b[0m\n" assert output == expected + + +def test_soft_wrap_styled() -> None: + """Regression test for https://github.com/Textualize/rich/issues/3838 + + If soft_wrap is True and a style is set, we don't want to style the new lines. + """ + console = Console(color_system="standard", width=80, force_terminal=True) + with console.capture() as capture: + console.print("soft wrap is on", style="blue on white", soft_wrap=True) + console.print("Next line") + + output = capture.get() + print(repr(output)) + # Background is reset before \n + expected = "\x1b[34;47msoft wrap is on\x1b[0m\nNext line\n" + assert output == expected