From 4dff2b01196652ebe3f09fe3ad9118143642e61c Mon Sep 17 00:00:00 2001 From: makeworld Date: Tue, 29 Dec 2020 00:14:31 -0500 Subject: [PATCH] Fix ANSI document left margin color leaking --- CHANGELOG.md | 1 + renderer/renderer.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f822718..0afc283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix downloading of pages that are too large or timed out - More reliable start, no more flash of unindented text, or text that stays unindented (#107) - Pages with ANSI resets don't use the terminal's default text and background colors (#107) +- ANSI documents don't leak color into the left margin (#107) ## [1.7.2] - 2020-12-21 diff --git a/renderer/renderer.go b/renderer/renderer.go index 06d2436..cd9d09b 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -25,13 +25,18 @@ func RenderANSI(s string, leftMargin int) string { s = cview.Escape(s) if viper.GetBool("a-general.color") && viper.GetBool("a-general.ansi") { s = cview.TranslateANSI(s) + // The TranslateANSI function injects tags like [-:-:-] + // but this will reset the background to use the user's terminal color. + // These tags need to be replaced with resets that use the theme color. + s = strings.ReplaceAll(s, "[-:-:-]", + fmt.Sprintf("[-:%s:-]", config.GetColorString("bg"))) } else { s = ansiRegex.ReplaceAllString(s, "") } var shifted string lines := strings.Split(s, "\n") for i := range lines { - shifted += strings.Repeat(" ", leftMargin) + lines[i] + "\n" + shifted += fmt.Sprintf("[-:%s]", config.GetColorString("bg")) + strings.Repeat(" ", leftMargin) + lines[i] + "\n" } return shifted }