From 119c5f885a5a4a25d19c682cac9152e6a7b024f0 Mon Sep 17 00:00:00 2001 From: Luis del Rio Francos Date: Wed, 5 Feb 2025 12:01:53 +0100 Subject: [PATCH] inline render return as space --- style.go | 3 ++- style_test.go | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/style.go b/style.go index 0eb5c016..0afd7001 100644 --- a/style.go +++ b/style.go @@ -358,7 +358,8 @@ func (s Style) Render(strs ...string) string { // Strip newlines in single line mode if inline { - str = strings.ReplaceAll(str, "\n", "") + str = strings.ReplaceAll(str, "\n", " ") + str = strings.Trim(str, " ") } // Word wrap diff --git a/style_test.go b/style_test.go index 0db740b4..f78dde6b 100644 --- a/style_test.go +++ b/style_test.go @@ -589,4 +589,13 @@ func TestCarriageReturnInRender(t *testing.T) { t.Logf("got(detailed):\n%q\nwant(detailed):\n%q", got, want) t.Fatalf("got(string):\n%s\nwant(string):\n%s", got, want) } + + got = testStyle.Inline(true).Render("\nHello\nworld\n") + want = testStyle.Inline(true).Render("Hello world") + + if got != want { + t.Logf("got(detailed):\n%q\nwant(detailed):\n%q", got, want) + t.Fatalf("got(string):\n%s\nwant(string):\n%s", got, want) + } + }