mirror of
https://github.com/makew0rld/amfora.git
synced 2025-02-02 15:07:34 -05:00
Pages with ANSI resets don't use the terminal's default text and background colors
This commit is contained in:
parent
306213aab2
commit
db6e0f4074
@ -16,7 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Fixed
|
### Fixed
|
||||||
- Don't use cache when URL is typed in bottom bar (#159)
|
- Don't use cache when URL is typed in bottom bar (#159)
|
||||||
- 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)
|
||||||
|
|
||||||
|
|
||||||
## [1.7.2] - 2020-12-21
|
## [1.7.2] - 2020-12-21
|
||||||
|
@ -289,30 +289,52 @@ func RenderGemini(s string, width, leftMargin int, proxied bool) (string, []stri
|
|||||||
rendered := "" // Final result
|
rendered := "" // Final result
|
||||||
pre := false
|
pre := false
|
||||||
buf := "" // Block of regular or preformatted lines
|
buf := "" // Block of regular or preformatted lines
|
||||||
|
|
||||||
|
// processPre is for rendering preformatted blocks
|
||||||
|
processPre := func() {
|
||||||
|
// Support ANSI color codes in preformatted blocks - see #59
|
||||||
|
if viper.GetBool("a-general.color") && viper.GetBool("a-general.ansi") {
|
||||||
|
buf = cview.TranslateANSI(buf)
|
||||||
|
// 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.
|
||||||
|
buf = strings.ReplaceAll(buf, "[-:-:-]",
|
||||||
|
fmt.Sprintf("[%s:%s:-]", config.GetColorString("preformatted_text"), config.GetColorString("bg")))
|
||||||
|
} else {
|
||||||
|
buf = ansiRegex.ReplaceAllString(buf, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
// The final newline is removed (and re-added) to prevent background glitches
|
||||||
|
// where the terminal background color slips through. This only happens on
|
||||||
|
// preformatted blocks with ANSI characters.
|
||||||
|
//
|
||||||
|
// Lines are modified below to always end with \r\n
|
||||||
|
buf = strings.TrimSuffix(buf, "\r\n")
|
||||||
|
|
||||||
|
rendered += fmt.Sprintf("[%s]", config.GetColorString("preformatted_text")) +
|
||||||
|
buf + fmt.Sprintf("[%s:%s:-]\r\n", config.GetColorString("regular_text"), config.GetColorString("bg"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// processRegular processes non-preformatted sections
|
||||||
|
processRegular := func() {
|
||||||
|
// ANSI not allowed in regular text - see #59
|
||||||
|
buf = ansiRegex.ReplaceAllString(buf, "")
|
||||||
|
|
||||||
|
ren, lks := convertRegularGemini(buf, len(links), width, proxied)
|
||||||
|
links = append(links, lks...)
|
||||||
|
rendered += ren
|
||||||
|
}
|
||||||
|
|
||||||
for i := range lines {
|
for i := range lines {
|
||||||
if strings.HasPrefix(lines[i], "```") {
|
if strings.HasPrefix(lines[i], "```") {
|
||||||
if pre {
|
if pre {
|
||||||
// In a preformatted block, so add the text as is
|
// In a preformatted block, so add the text as is
|
||||||
// Don't add the current line with backticks
|
// Don't add the current line with backticks
|
||||||
|
processPre()
|
||||||
|
|
||||||
// Support ANSI color codes in preformatted blocks - see #59
|
|
||||||
if viper.GetBool("a-general.color") && viper.GetBool("a-general.ansi") {
|
|
||||||
buf = cview.TranslateANSI(buf)
|
|
||||||
} else {
|
|
||||||
buf = ansiRegex.ReplaceAllString(buf, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
rendered += fmt.Sprintf("[%s]", config.GetColorString("preformatted_text")) +
|
|
||||||
buf + "[-]"
|
|
||||||
} else {
|
} else {
|
||||||
// Not preformatted, regular text
|
// Not preformatted, regular text
|
||||||
|
processRegular()
|
||||||
// ANSI not allowed in regular text - see #59
|
|
||||||
buf = ansiRegex.ReplaceAllString(buf, "")
|
|
||||||
|
|
||||||
ren, lks := convertRegularGemini(buf, len(links), width, proxied)
|
|
||||||
links = append(links, lks...)
|
|
||||||
rendered += ren
|
|
||||||
}
|
}
|
||||||
buf = "" // Clear buffer for next block
|
buf = "" // Clear buffer for next block
|
||||||
pre = !pre
|
pre = !pre
|
||||||
@ -324,24 +346,10 @@ func RenderGemini(s string, width, leftMargin int, proxied bool) (string, []stri
|
|||||||
// Gone through all the lines, but there still is likely a block in the buffer
|
// Gone through all the lines, but there still is likely a block in the buffer
|
||||||
if pre {
|
if pre {
|
||||||
// File ended without closing the preformatted block
|
// File ended without closing the preformatted block
|
||||||
// Same code as in the loop above
|
processPre()
|
||||||
|
|
||||||
if viper.GetBool("a-general.color") && viper.GetBool("a-general.ansi") {
|
|
||||||
buf = cview.TranslateANSI(buf)
|
|
||||||
} else {
|
|
||||||
buf = ansiRegex.ReplaceAllString(buf, "")
|
|
||||||
}
|
|
||||||
rendered += fmt.Sprintf("[%s]", config.GetColorString("preformatted_text")) +
|
|
||||||
buf + "[-]"
|
|
||||||
} else {
|
} else {
|
||||||
// Not preformatted, regular text
|
// Not preformatted, regular text
|
||||||
// Same code as in the loop above
|
processRegular()
|
||||||
|
|
||||||
buf = ansiRegex.ReplaceAllString(buf, "")
|
|
||||||
|
|
||||||
ren, lks := convertRegularGemini(buf, len(links), width, proxied)
|
|
||||||
links = append(links, lks...)
|
|
||||||
rendered += ren
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if leftMargin > 0 {
|
if leftMargin > 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user