Removes ascii escape codes from remote content

This commit is contained in:
sloumdrone 2019-11-02 19:45:55 -07:00
parent 20d2c706b4
commit 65101563d9
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)