Updates escape code handling to be safer plus renders literally in local scheme

This commit is contained in:
sloumdrone 2019-12-13 20:19:50 -08:00
parent 021678d9da
commit f3f406260e
1 changed files with 16 additions and 4 deletions

20
page.go
View File

@ -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 {