@@ -210,6 +210,46 @@ def test_print_text_multiple() -> None:
210210 assert console .file .getvalue () == "\x1b [1mfoo\x1b [0m bar baz\n "
211211
212212
213+ def test_print_no_styled_newlines () -> None :
214+ """Test that newlines are never styled when printed."""
215+
216+ # Put newlines into all values.
217+ str1 = "line1\n line2\n "
218+ str2 = "line5\n line6\n "
219+ sep = "(sep1)\n (sep2)\n "
220+ end = "(end1)\n (end2)\n "
221+
222+ # All newlines should appear outside of ANSI style sequences.
223+ expected = (
224+ "\x1b [34;47mline1\x1b [0m\n "
225+ "\x1b [34;47mline2\x1b [0m\n "
226+ "\x1b [34;47m(sep1)\x1b [0m\n "
227+ "\x1b [34;47m(sep2)\x1b [0m\n "
228+ "\x1b [34;47mline5\x1b [0m\n "
229+ "\x1b [34;47mline6\x1b [0m\n "
230+ "\x1b [34;47m(end1)\x1b [0m\n "
231+ "\x1b [34;47m(end2)\x1b [0m\n "
232+ )
233+
234+ # Set a width wider than our lines so that the output
235+ # is the same whether or not soft_wrap is enabled.
236+ console = Console (color_system = "truecolor" , width = 80 )
237+
238+ # Test with soft wrapping enabled.
239+ with console .capture () as capture :
240+ console .print (
241+ str1 , str2 , sep = sep , end = end , style = "blue on white" , soft_wrap = True
242+ )
243+ assert capture .get () == expected
244+
245+ # Test with soft wrapping disabled.
246+ with console .capture () as capture :
247+ console .print (
248+ str1 , str2 , sep = sep , end = end , style = "blue on white" , soft_wrap = False
249+ )
250+ assert capture .get () == expected
251+
252+
213253def test_print_json () -> None :
214254 console = Console (file = io .StringIO (), color_system = "truecolor" )
215255 console .print_json ('[false, true, null, "foo"]' , indent = 4 )
0 commit comments