From 6176ad6f8ecb6556eb01cd968d8250144d6d4f3d Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 14 May 2020 15:04:18 -0400 Subject: [PATCH] Add method to pager model for getting percent scrolled --- pager/pager.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pager/pager.go b/pager/pager.go index 4047866..b09f9a2 100644 --- a/pager/pager.go +++ b/pager/pager.go @@ -18,6 +18,16 @@ type Model struct { 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 func (m *Model) Content(s string) { s = strings.TrimSpace(s)