From fdaf6312aba7c58d267479a969d77cb1db710867 Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Thu, 19 Sep 2019 20:29:17 -0700 Subject: [PATCH] Adds a terminal mode change to disallow line wrapping by the terminal, also fixes a resize scroll issue and disallows escape characters in text files --- client.go | 21 +++++++++++++-------- cui/cui.go | 1 + main.go | 1 + page.go | 7 +++---- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/client.go b/client.go index 6d3aa28..544cf56 100644 --- a/client.go +++ b/client.go @@ -73,7 +73,7 @@ func (c *client) GetSize() { if h != c.Height || w != c.Width { c.Height = h c.Width = w - c.Draw() + c.Scroll(0) } time.Sleep(500 * time.Millisecond) @@ -732,13 +732,18 @@ func (c *client) Visit(url string) { } switch capsule.Status { case 2: - pg := MakePage(u, capsule.Content, capsule.Links) - pg.WrapContent(c.Width) - c.PageState.Add(pg) - c.Scroll(0) - c.ClearMessage() - c.SetHeaderUrl() - c.Draw() + if capsule.MimeMaj == "text" { + pg := MakePage(u, capsule.Content, capsule.Links) + pg.WrapContent(c.Width) + c.PageState.Add(pg) + c.Scroll(0) + c.ClearMessage() + c.SetHeaderUrl() + c.Draw() + } else { + c.SetMessage("Still mulling how to handle binary files... come back soon", false) + c.DrawMessage() + } case 3: c.SetMessage("[3] Redirect. Follow redirect? y or any other key for no", false) c.DrawMessage() diff --git a/cui/cui.go b/cui/cui.go index e6cfb1c..deb69ea 100644 --- a/cui/cui.go +++ b/cui/cui.go @@ -65,6 +65,7 @@ func Exit() { fmt.Print("\n") fmt.Print("\033[?25h") + HandleAlternateScreen("smam") HandleAlternateScreen("rmcup") os.Exit(0) } diff --git a/main.go b/main.go index f87b4d8..b738899 100644 --- a/main.go +++ b/main.go @@ -94,6 +94,7 @@ func initClient() error { } func main() { + cui.HandleAlternateScreen("rmam") cui.HandleAlternateScreen("smcup") defer cui.Exit() err := initClient() diff --git a/page.go b/page.go index 20514b6..ee8b68c 100644 --- a/page.go +++ b/page.go @@ -46,7 +46,7 @@ func (p *Page) WrapContent(width int) { counter := 0 var content strings.Builder content.Grow(len(p.RawContent)) - for _, ch := range p.RawContent { + for _, ch := range []rune(p.RawContent) { if ch == '\n' { content.WriteRune(ch) counter = 0 @@ -58,9 +58,8 @@ func (p *Page) WrapContent(width int) { content.WriteRune('\n') counter = 0 } - } else if ch == '\r' { - // This handles non-linux line endings... - // to some degree... + } else if ch == '\r' || ch == '\v' || ch == '\b' || ch == '\f' || ch == 27 { + // Get rid of control characters we dont want continue } else { if counter < width {