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 { if h != c.Height || w != c.Width {
c.Height = h c.Height = h
c.Width = w c.Width = w
c.Draw() c.Scroll(0)
} }
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
@ -732,13 +732,18 @@ func (c *client) Visit(url string) {
} }
switch capsule.Status { switch capsule.Status {
case 2: case 2:
pg := MakePage(u, capsule.Content, capsule.Links) if capsule.MimeMaj == "text" {
pg.WrapContent(c.Width) pg := MakePage(u, capsule.Content, capsule.Links)
c.PageState.Add(pg) pg.WrapContent(c.Width)
c.Scroll(0) c.PageState.Add(pg)
c.ClearMessage() c.Scroll(0)
c.SetHeaderUrl() c.ClearMessage()
c.Draw() c.SetHeaderUrl()
c.Draw()
} else {
c.SetMessage("Still mulling how to handle binary files... come back soon", false)
c.DrawMessage()
}
case 3: case 3:
c.SetMessage("[3] Redirect. Follow redirect? y or any other key for no", false) c.SetMessage("[3] Redirect. Follow redirect? y or any other key for no", false)
c.DrawMessage() c.DrawMessage()

View File

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

View File

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

View File

@ -46,7 +46,7 @@ func (p *Page) WrapContent(width int) {
counter := 0 counter := 0
var content strings.Builder var content strings.Builder
content.Grow(len(p.RawContent)) content.Grow(len(p.RawContent))
for _, ch := range p.RawContent { for _, ch := range []rune(p.RawContent) {
if ch == '\n' { if ch == '\n' {
content.WriteRune(ch) content.WriteRune(ch)
counter = 0 counter = 0
@ -58,9 +58,8 @@ func (p *Page) WrapContent(width int) {
content.WriteRune('\n') content.WriteRune('\n')
counter = 0 counter = 0
} }
} else if ch == '\r' { } else if ch == '\r' || ch == '\v' || ch == '\b' || ch == '\f' || ch == 27 {
// This handles non-linux line endings... // Get rid of control characters we dont want
// to some degree...
continue continue
} else { } else {
if counter < width { if counter < width {