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

Update renderer to match master commit d099812

This commit is contained in:
makeworld 2021-06-25 19:09:00 -04:00
parent 386b585a41
commit adb7b379cb
2 changed files with 8 additions and 16 deletions

View File

@ -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

View File

@ -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