forked from sloum/bombadillo
Uses asdf's suggestion to reduce HasPrefix overhead by setting the spacer at the beginning of the document wrap code
This commit is contained in:
parent
7d326eaba6
commit
2270dee513
18
page.go
18
page.go
|
@ -72,12 +72,17 @@ func (p *Page) WrapContent(width int, color bool) {
|
|||
}
|
||||
width = min(width, 100)
|
||||
counter := 0
|
||||
gopherspacer := " "
|
||||
geminispacer := " "
|
||||
spacer := ""
|
||||
var content strings.Builder
|
||||
var esc strings.Builder
|
||||
escape := false
|
||||
content.Grow(len(p.RawContent))
|
||||
|
||||
if p.Location.Mime == "1" { // gopher document
|
||||
spacer = " "
|
||||
} else if strings.HasSuffix(p.Location.Mime, "gemini") { //gemini document
|
||||
spacer = " "
|
||||
}
|
||||
for _, ch := range []rune(p.RawContent) {
|
||||
if escape {
|
||||
if color {
|
||||
|
@ -126,13 +131,8 @@ func (p *Page) WrapContent(width int, color bool) {
|
|||
} else {
|
||||
content.WriteRune('\n')
|
||||
counter = 0
|
||||
if p.Location.Mime == "1" {
|
||||
content.WriteString(gopherspacer)
|
||||
counter += len(gopherspacer)
|
||||
} else if strings.HasSuffix(p.Location.Mime, "gemini") {
|
||||
content.WriteString(geminispacer)
|
||||
counter += len(geminispacer)
|
||||
}
|
||||
content.WriteString(spacer)
|
||||
counter += len(spacer)
|
||||
content.WriteRune(ch)
|
||||
counter++
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue