From 322002ba66602f0c5fc8396f9b1f20eead51a1a3 Mon Sep 17 00:00:00 2001 From: sloum Date: Fri, 15 May 2020 22:19:09 -0700 Subject: [PATCH] Adds a max width of 100, anything more gets weird to read. Also adds a slight optimization. --- page.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/page.go b/page.go index 4ca0842..13cf641 100644 --- a/page.go +++ b/page.go @@ -66,11 +66,13 @@ func (p *Page) RenderImage(width int) { // of the Page struct width a string slice // of the wrapped data func (p *Page) WrapContent(width int, color bool) { + width = min(width, 100) if p.FileType == "image" { p.RenderImage(width) return } counter := 0 + spacer := " " var content strings.Builder var esc strings.Builder escape := false @@ -124,7 +126,6 @@ func (p *Page) WrapContent(width int, color bool) { content.WriteRune('\n') counter = 0 if p.Location.Mime == "1" { - spacer := " " content.WriteString(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} return p } + +func min(a, b int) int { + if a < b { + return a + } + return b +}