From bdbf42df15291375a25addc3379005d74d1ef0ed Mon Sep 17 00:00:00 2001 From: Evan Wies Date: Wed, 20 May 2026 15:44:29 -0400 Subject: [PATCH] `Close` BEFORE reading `buf` so the trailing `ResetStyle / ResetHyperlink` the `WrapWriter` emits on close is included in the returned string. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using `defer w.Close()` here would write the closing resets to buf *after* `buf.String()` snapshots it, dropping them from the return value and leaving callers with output that ends in a dangling SGR/OSC8 — which in turn trips a use-after-close panic in glamour's `IndentWriter.Close` write-cascade. Signed-off-by: Evan Wies --- wrap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrap.go b/wrap.go index ca0a1e23..139adccb 100644 --- a/wrap.go +++ b/wrap.go @@ -13,8 +13,8 @@ func Wrap(s string, width int, breakpoints string) string { var buf bytes.Buffer s = ansi.Wrap(s, width, breakpoints) w := NewWrapWriter(&buf) - defer w.Close() //nolint:errcheck _, _ = io.WriteString(w, s) + _ = w.Close() return buf.String() }