From 8c42748432874c7ac83c2f50fbbaf4caf82279ff Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Thu, 19 Sep 2019 21:29:52 -0700 Subject: [PATCH] Fixes issue where percent read was incorrect when moving through history --- client.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 544cf56..da0a40f 100644 --- a/client.go +++ b/client.go @@ -101,6 +101,7 @@ func (c *client) Draw() { } else { screen.WriteString(fmt.Sprintf("%-*.*s", contentWidth, contentWidth, " ")) } + screen.WriteString("\033[500C\033[39D") } if c.Options["theme"] == "inverse" && !c.BookMarks.IsFocused { @@ -125,7 +126,7 @@ func (c *client) Draw() { screen.WriteString(fmt.Sprintf("%-*.*s", c.Width, c.Width, pageContent[i])) screen.WriteString("\n") } else { - screen.WriteString(fmt.Sprintf("%*s", c.Width, " ")) + screen.WriteString(fmt.Sprintf("%*.*s", c.Width, c.Width, " ")) screen.WriteString("\n") } } @@ -182,6 +183,7 @@ func (c *client) TakeControlInput() { c.DrawMessage() } else { c.SetHeaderUrl() + c.SetPercentRead() c.Draw() } case 'B': @@ -197,6 +199,7 @@ func (c *client) TakeControlInput() { c.DrawMessage() } else { c.SetHeaderUrl() + c.SetPercentRead() c.Draw() } case '\t': @@ -610,6 +613,17 @@ func (c *client) Scroll(amount int) { } } +func (c *client) SetPercentRead() { + page := c.PageState.History[c.PageState.Position] + var percentRead int + if len(page.WrappedContent) < c.Height - 3 { + percentRead = 100 + } else { + percentRead = int(float32(page.ScrollPosition + c.Height - 3) / float32(len(page.WrappedContent)) * 100.0) + } + c.FootBar.SetPercentRead(percentRead) +} + func (c *client) displayConfigValue(setting string) { if val, ok := c.Options[setting]; ok { c.SetMessage(fmt.Sprintf("%s is set to: %q", setting, val), false)