1
0
mirror of https://github.com/makew0rld/amfora.git synced 2025-01-03 14:56:27 -05:00

Consistent receiver name

This commit is contained in:
makeworld 2021-03-04 20:14:56 -05:00
parent fedc1fd11a
commit d136c8a9f8
2 changed files with 27 additions and 27 deletions

View File

@ -72,9 +72,9 @@ func NewGemtextRenderer(width int, proxied bool) *GemtextRenderer {
// renderLine handles all lines except preformatted markings. The input line // renderLine handles all lines except preformatted markings. The input line
// should not end with any line delimiters, but the output line does. // should not end with any line delimiters, but the output line does.
func (r *GemtextRenderer) renderLine(line string) string { func (ren *GemtextRenderer) renderLine(line string) string {
if r.pre { if ren.pre {
if r.ansiEnabled { if ren.ansiEnabled {
line = cview.TranslateANSI(line) line = cview.TranslateANSI(line)
// The TranslateANSI function injects tags like [-:-:-] // The TranslateANSI function injects tags like [-:-:-]
// but this will reset the background to use the user's terminal color. // but this will reset the background to use the user's terminal color.
@ -113,10 +113,10 @@ func (r *GemtextRenderer) renderLine(line string) string {
} else if strings.HasPrefix(line, "#") { } else if strings.HasPrefix(line, "#") {
tag = fmt.Sprintf("[%s::b]", config.GetColorString("hdg_1")) tag = fmt.Sprintf("[%s::b]", config.GetColorString("hdg_1"))
} }
wrappedLines = append(wrappedLines, wrapLine(line, r.width, tag, "[-::-]", true)...) wrappedLines = append(wrappedLines, wrapLine(line, ren.width, tag, "[-::-]", true)...)
} else { } else {
// Just bold, no colors // Just bold, no colors
wrappedLines = append(wrappedLines, wrapLine(line, r.width, "[::b]", "[-::-]", true)...) wrappedLines = append(wrappedLines, wrapLine(line, ren.width, "[::b]", "[-::-]", true)...)
} }
// Links // Links
@ -146,9 +146,9 @@ func (r *GemtextRenderer) renderLine(line string) string {
return "=>\n" return "=>\n"
} }
r.links <- url ren.links <- url
r.numLinks++ ren.numLinks++
num := r.numLinks // Visible link number, one-indexed num := ren.numLinks // Visible link number, one-indexed
var indent int var indent int
if num > 99 { if num > 99 {
@ -178,13 +178,13 @@ func (r *GemtextRenderer) renderLine(line string) string {
if viper.GetBool("a-general.color") { if viper.GetBool("a-general.color") {
pU, err := urlPkg.Parse(url) pU, err := urlPkg.Parse(url)
if !r.proxied && err == nil && if !ren.proxied && err == nil &&
(pU.Scheme == "" || pU.Scheme == "gemini" || pU.Scheme == "about") { (pU.Scheme == "" || pU.Scheme == "gemini" || pU.Scheme == "about") {
// A gemini link // A gemini link
// Add the link text in blue (in a region), and a gray link number to the left of it // Add the link text in blue (in a region), and a gray link number to the left of it
// Those are the default colors, anyway // Those are the default colors, anyway
wrappedLink = wrapLine(linkText, r.width, wrappedLink = wrapLine(linkText, ren.width,
strings.Repeat(" ", indent)+ strings.Repeat(" ", indent)+
`["`+strconv.Itoa(num-1)+`"][`+config.GetColorString("amfora_link")+`]`, `["`+strconv.Itoa(num-1)+`"][`+config.GetColorString("amfora_link")+`]`,
`[-][""]`, `[-][""]`,
@ -199,7 +199,7 @@ func (r *GemtextRenderer) renderLine(line string) string {
} else { } else {
// Not a gemini link // Not a gemini link
wrappedLink = wrapLine(linkText, r.width, wrappedLink = wrapLine(linkText, ren.width,
strings.Repeat(" ", indent)+ strings.Repeat(" ", indent)+
`["`+strconv.Itoa(num-1)+`"][`+config.GetColorString("foreign_link")+`]`, `["`+strconv.Itoa(num-1)+`"][`+config.GetColorString("foreign_link")+`]`,
`[-][""]`, `[-][""]`,
@ -214,7 +214,7 @@ func (r *GemtextRenderer) renderLine(line string) string {
} else { } else {
// No colors allowed // No colors allowed
wrappedLink = wrapLine(linkText, r.width, wrappedLink = wrapLine(linkText, ren.width,
strings.Repeat(" ", len(strconv.Itoa(num))+4)+ // +4 for spaces and brackets strings.Repeat(" ", len(strconv.Itoa(num))+4)+ // +4 for spaces and brackets
`["`+strconv.Itoa(num-1)+`"]`, `["`+strconv.Itoa(num-1)+`"]`,
`[""]`, `[""]`,
@ -232,7 +232,7 @@ func (r *GemtextRenderer) renderLine(line string) string {
} else if strings.HasPrefix(line, "* ") { } else if strings.HasPrefix(line, "* ") {
if viper.GetBool("a-general.bullets") { if viper.GetBool("a-general.bullets") {
// Wrap list item, and indent wrapped lines past the bullet // Wrap list item, and indent wrapped lines past the bullet
wrappedItem := wrapLine(line[1:], r.width, wrappedItem := wrapLine(line[1:], ren.width,
fmt.Sprintf(" [%s]", config.GetColorString("list_text")), fmt.Sprintf(" [%s]", config.GetColorString("list_text")),
"[-]", false) "[-]", false)
// Add bullet // Add bullet
@ -252,7 +252,7 @@ func (r *GemtextRenderer) renderLine(line string) string {
line = strings.TrimPrefix(line, ">") line = strings.TrimPrefix(line, ">")
line = strings.TrimPrefix(line, " ") line = strings.TrimPrefix(line, " ")
wrappedLines = append(wrappedLines, wrappedLines = append(wrappedLines,
wrapLine(line, r.width, fmt.Sprintf("[%s::i]> ", config.GetColorString("quote_text")), wrapLine(line, ren.width, fmt.Sprintf("[%s::i]> ", config.GetColorString("quote_text")),
"[-::-]", true)..., "[-::-]", true)...,
) )
} }
@ -262,7 +262,7 @@ func (r *GemtextRenderer) renderLine(line string) string {
wrappedLines = append(wrappedLines, "") wrappedLines = append(wrappedLines, "")
} else { } else {
// Regular line, just wrap it // Regular line, just wrap it
wrappedLines = append(wrappedLines, wrapLine(line, r.width, wrappedLines = append(wrappedLines, wrapLine(line, ren.width,
fmt.Sprintf("[%s]", config.GetColorString("regular_text")), fmt.Sprintf("[%s]", config.GetColorString("regular_text")),
"[-]", true)...) "[-]", true)...)
} }
@ -299,17 +299,17 @@ func (ren *GemtextRenderer) ReadFrom(r io.Reader) (int64, error) {
} }
// Write will panic, use ReadFrom instead. // Write will panic, use ReadFrom instead.
func (r *GemtextRenderer) Write(p []byte) (n int, err error) { func (ren *GemtextRenderer) Write(p []byte) (n int, err error) {
// This renderer is line based, and so it can't process arbitrary bytes. // This renderer is line based, and so it can't process arbitrary bytes.
// One solution would be to handle rendering on the other end of the pipe, // One solution would be to handle rendering on the other end of the pipe,
// the Read call, but it's simpler to just implement ReadFrom. // the Read call, but it's simpler to just implement ReadFrom.
panic("func Write not allowed for GemtextRenderer") panic("func Write not allowed for GemtextRenderer")
} }
func (r *GemtextRenderer) Read(p []byte) (n int, err error) { func (ren *GemtextRenderer) Read(p []byte) (n int, err error) {
return r.r.Read(p) return ren.r.Read(p)
} }
func (r *GemtextRenderer) Links() <-chan string { func (ren *GemtextRenderer) Links() <-chan string {
return r.links return r.links
} }

View File

@ -78,18 +78,18 @@ func (ren *PlaintextRenderer) ReadFrom(r io.Reader) (int64, error) {
} }
// Write will panic, use ReadFrom instead. // Write will panic, use ReadFrom instead.
func (r *PlaintextRenderer) Write(p []byte) (n int, err error) { func (ren *PlaintextRenderer) Write(p []byte) (n int, err error) {
// This function would normally use cview.EscapeBytes // This function would normally use cview.EscapeBytes
// But the escaping will fail if the Write bytes end in the middle of a tag // But the escaping will fail if the Write bytes end in the middle of a tag
// So instead it just panics, because it should never be used. // So instead it just panics, because it should never be used.
panic("func Write not allowed for PlaintextRenderer") panic("func Write not allowed for PlaintextRenderer")
} }
func (r *PlaintextRenderer) Read(p []byte) (n int, err error) { func (ren *PlaintextRenderer) Read(p []byte) (n int, err error) {
return r.r.Read(p) return ren.r.Read(p)
} }
func (r *PlaintextRenderer) Links() <-chan string { func (ren *PlaintextRenderer) Links() <-chan string {
ch := make(chan string) ch := make(chan string)
close(ch) close(ch)
return ch return ch
@ -118,7 +118,7 @@ func NewANSIRenderer() *ANSIRenderer {
} }
// Write will panic, use ReadFrom instead. // Write will panic, use ReadFrom instead.
func (r *ANSIRenderer) Write(p []byte) (n int, err error) { func (ren *ANSIRenderer) Write(p []byte) (n int, err error) {
// This function would normally use cview.EscapeBytes among other things. // This function would normally use cview.EscapeBytes among other things.
// But the escaping will fail if the Write bytes end in the middle of a tag // But the escaping will fail if the Write bytes end in the middle of a tag
// So instead it just panics, because it should never be used. // So instead it just panics, because it should never be used.
@ -165,11 +165,11 @@ func (ren *ANSIRenderer) ReadFrom(r io.Reader) (int64, error) {
return n, scanner.Err() return n, scanner.Err()
} }
func (r *ANSIRenderer) Read(p []byte) (n int, err error) { func (ren *ANSIRenderer) Read(p []byte) (n int, err error) {
return r.r.Read(p) return ren.r.Read(p)
} }
func (r *ANSIRenderer) Links() <-chan string { func (ren *ANSIRenderer) Links() <-chan string {
ch := make(chan string) ch := make(chan string)
close(ch) close(ch)
return ch return ch