From 46044092ad91b93dca957b7676c2b739e98720e9 Mon Sep 17 00:00:00 2001 From: Tom Pacheco Date: Fri, 11 Oct 2024 10:24:26 -0400 Subject: [PATCH] fix: ansi.Wrap issue with a limit of 1 (#214) --- ansi/wrap.go | 3 +++ ansi/wrap_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/ansi/wrap.go b/ansi/wrap.go index 2cab5cec..d080a77a 100644 --- a/ansi/wrap.go +++ b/ansi/wrap.go @@ -349,6 +349,9 @@ func Wrap(s string, limit int, breakpoints string) string { curWidth++ } default: + if curWidth == limit { + addNewline() + } word.WriteRune(r) wordLen++ diff --git a/ansi/wrap_test.go b/ansi/wrap_test.go index a1464d59..ad3c7291 100644 --- a/ansi/wrap_test.go +++ b/ansi/wrap_test.go @@ -32,6 +32,7 @@ var cases = []struct { {"preserve_style", "\x1B[38;2;249;38;114m(\x1B[0m\x1B[38;2;248;248;242mjust another test\x1B[38;2;249;38;114m)\x1B[0m", 3, "\x1B[38;2;249;38;114m(\x1B[0m\x1B[38;2;248;248;242mju\nst \nano\nthe\nr t\nest\x1B[38;2;249;38;114m\n)\x1B[0m", false}, {"emoji", "foo🫧foobar", 4, "foo\n🫧fo\nobar", false}, {"osc8_wrap", "สวัสดีสวัสดี\x1b]8;;https://example.com\x1b\\สวัสดีสวัสดี\x1b]8;;\x1b\\", 8, "สวัสดีสวัสดี\x1b]8;;https://example.com\x1b\\\nสวัสดีสวัสดี\x1b]8;;\x1b\\", false}, + {"column", "VERTICAL", 1, "V\nE\nR\nT\nI\nC\nA\nL", false}, } func TestHardwrap(t *testing.T) {