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

This commit is contained in:
sloumdrone 2019-09-19 20:29:17 -07:00
parent 0879592015
commit fdaf6312ab
4 changed files with 18 additions and 12 deletions

View File

@ -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()

View File

@ -65,6 +65,7 @@ func Exit() {
fmt.Print("\n")
fmt.Print("\033[?25h")
HandleAlternateScreen("smam")
HandleAlternateScreen("rmcup")
os.Exit(0)
}

View File

@ -94,6 +94,7 @@ func initClient() error {
}
func main() {
cui.HandleAlternateScreen("rmam")
cui.HandleAlternateScreen("smcup")
defer cui.Exit()
err := initClient()

View File

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