Removes ascii escape codes from remote content #69 #85

Manually merged
sloum merged 1 commits from remove-escapes into develop 2019-11-12 14:52:17 +00:00
1 changed files with 11 additions and 1 deletions

12
page.go
View File

@ -45,8 +45,15 @@ func (p *Page) ScrollPositionRange(termHeight int) (int, int) {
func (p *Page) WrapContent(width int) {
counter := 0
var content strings.Builder
escape := false
content.Grow(len(p.RawContent))
for _, ch := range []rune(p.RawContent) {
if escape {
if (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') {
escape = false
}
continue
}
if ch == '\n' {
content.WriteRune(ch)
counter = 0
@ -58,9 +65,12 @@ func (p *Page) WrapContent(width int) {
content.WriteRune('\n')
counter = 0
}
} else if ch == '\r' || ch == '\v' || ch == '\b' || ch == '\f' || ch == 27 {
} else if ch == '\r' || ch == '\v' || ch == '\b' || ch == '\f' {
// Get rid of control characters we dont want
continue
} else if ch == 27 {
escape = true
continue
} else {
if counter < width {
content.WriteRune(ch)