Adds a max width of 100, anything more gets weird to read. Also adds a slight optimization.

This commit is contained in:
sloum 2020-05-15 22:19:09 -07:00
parent a23e0026fa
commit 322002ba66
1 changed files with 9 additions and 1 deletions

10
page.go
View File

@ -66,11 +66,13 @@ func (p *Page) RenderImage(width int) {
// of the Page struct width a string slice // of the Page struct width a string slice
// of the wrapped data // of the wrapped data
func (p *Page) WrapContent(width int, color bool) { func (p *Page) WrapContent(width int, color bool) {
width = min(width, 100)
if p.FileType == "image" { if p.FileType == "image" {
p.RenderImage(width) p.RenderImage(width)
return return
} }
counter := 0 counter := 0
spacer := " "
var content strings.Builder var content strings.Builder
var esc strings.Builder var esc strings.Builder
escape := false escape := false
@ -124,7 +126,6 @@ func (p *Page) WrapContent(width int, color bool) {
content.WriteRune('\n') content.WriteRune('\n')
counter = 0 counter = 0
if p.Location.Mime == "1" { if p.Location.Mime == "1" {
spacer := " "
content.WriteString(spacer) content.WriteString(spacer)
counter += len(spacer) counter += len(spacer)
} }
@ -188,3 +189,10 @@ func MakePage(url Url, content string, links []string) Page {
p := Page{make([]string, 0), content, links, url, 0, make([]int, 0), "", 0, "", 40, false} p := Page{make([]string, 0), content, links, url, 0, make([]int, 0), "", 0, "", 40, false}
return p return p
} }
func min(a, b int) int {
if a < b {
return a
}
return b
}