From f3f406260ea4cc26c0bd5485c4021d02ad7a7636 Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Fri, 13 Dec 2019 20:19:50 -0800 Subject: [PATCH] Updates escape code handling to be safer plus renders literally in local scheme --- page.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/page.go b/page.go index fe65387..6ef719e 100644 --- a/page.go +++ b/page.go @@ -50,15 +50,20 @@ func (p *Page) ScrollPositionRange(termHeight int) (int, int) { func (p *Page) WrapContent(width int, color bool) { counter := 0 var content strings.Builder + var esc strings.Builder escape := false content.Grow(len(p.RawContent)) for _, ch := range []rune(p.RawContent) { if escape { + if color { + esc.WriteRune(ch) + } if (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') { escape = false - } - if color { - content.WriteRune(ch) + if ch == 'm' { + content.WriteString(esc.String()) + esc.Reset() + } } continue } @@ -77,9 +82,16 @@ func (p *Page) WrapContent(width int, color bool) { // Get rid of control characters we dont want continue } else if ch == 27 { + if p.Location.Scheme == "local" { + if counter+4 >= width { + content.WriteRune('\n') + } + content.WriteString("\\033") + continue + } escape = true if color { - content.WriteRune(ch) + esc.WriteRune(ch) } continue } else {