Add method to pager model for getting percent scrolled

This commit is contained in:
Christian Rocha 2020-05-14 15:04:18 -04:00
parent db4600aeb2
commit 6176ad6f8e
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
1 changed files with 10 additions and 0 deletions

View File

@ -18,6 +18,16 @@ type Model struct {
lines []string lines []string
} }
func (m Model) ScrollPercent() float64 {
if m.Height >= len(m.lines) {
return 1.0
}
y := float64(m.Y)
h := float64(m.Height)
t := float64(len(m.lines))
return (y + h) / t
}
// Content set the pager's text content // Content set the pager's text content
func (m *Model) Content(s string) { func (m *Model) Content(s string) {
s = strings.TrimSpace(s) s = strings.TrimSpace(s)