1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-12-04 14:46:29 -05:00

Fix ANSI document left margin color leaking

This commit is contained in:
makeworld 2020-12-29 00:14:31 -05:00
parent e1a92a999a
commit 4dff2b0119
2 changed files with 7 additions and 1 deletions

View File

@ -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 - 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) - 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) - 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 ## [1.7.2] - 2020-12-21

View File

@ -25,13 +25,18 @@ func RenderANSI(s string, leftMargin int) string {
s = cview.Escape(s) s = cview.Escape(s)
if viper.GetBool("a-general.color") && viper.GetBool("a-general.ansi") { if viper.GetBool("a-general.color") && viper.GetBool("a-general.ansi") {
s = cview.TranslateANSI(s) 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 { } else {
s = ansiRegex.ReplaceAllString(s, "") s = ansiRegex.ReplaceAllString(s, "")
} }
var shifted string var shifted string
lines := strings.Split(s, "\n") lines := strings.Split(s, "\n")
for i := range lines { 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 return shifted
} }