diff --git a/render/gemtext.go b/render/gemtext.go index 18e537f..bb03eed 100644 --- a/render/gemtext.go +++ b/render/gemtext.go @@ -148,11 +148,14 @@ func (ren *GemtextRenderer) renderLine(line string) string { if ren.pre { if ren.ansiEnabled { line = cview.TranslateANSI(line) - // 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. - line = strings.ReplaceAll(line, "[-:-:-]", - fmt.Sprintf("[%s:%s:-]", config.GetColorString("preformatted_text"), config.GetColorString("bg")), + // The TranslateANSI function will reset the colors when it encounters + // an ANSI reset code, injecting a full reset tag: [-:-:-] + // This uses the default foreground and background colors of the + // application, but in this case we want it to use the preformatted text + // color as the foreground, as we're still in a preformat block. + line = strings.ReplaceAll( + line, "[-:-:-]", + fmt.Sprintf("[%s:-:-]", config.GetColorString("preformatted_text")), ) // Set color at beginning and end of line to prevent background glitches diff --git a/render/renderer.go b/render/renderer.go index 2aa3cac..c8f8418 100644 --- a/render/renderer.go +++ b/render/renderer.go @@ -3,12 +3,10 @@ package render import ( "bufio" "bytes" - "fmt" "io" "regexp" "code.rocketnine.space/tslocum/cview" - "github.com/makeworld-the-better-one/amfora/config" "github.com/spf13/viper" ) @@ -166,15 +164,6 @@ func (ren *ANSIRenderer) handler() { // Shouldn't error because everything it writes to are all bytes.Buffer ren.ansiWriter.Write(line) //nolint:errcheck - - // The ANSIWriter 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. - line = bytes.ReplaceAll( - ren.buf.Bytes(), - []byte("[-:-:-]"), - []byte(fmt.Sprintf("[-:%s:-]", config.GetColorString("bg"))), - ) } ren.readIn.Write(line) //nolint:errcheck