1
1
mirror of https://github.com/walles/moar.git synced 2024-11-30 02:34:13 +03:00

Initial attempt

This commit is contained in:
Johan Walles 2022-11-26 21:58:24 +01:00
parent 76f8c39100
commit 0c39d63aa0
2 changed files with 11 additions and 0 deletions

View File

@ -133,6 +133,10 @@ Source Code
Available at https://github.com/walles/moar/.
`)
func (pm _PagerMode) isViewing() bool {
return pm == _Viewing || pm == _NotFound
}
// NewPager creates a new Pager
func NewPager(r *Reader) *Pager {
var name string
@ -460,6 +464,9 @@ func (p *Pager) StartPaging(screen twin.Screen) {
case eventMoreLinesAvailable:
// Doing nothing here is fine; screen will be refreshed on the next
// iteration of the main loop.
if p.mode.isViewing() && p.scrollPosition.HasScrolledDown() && p.wasScrolledToEnd() {
p.scrollToEnd()
}
case eventSpinnerUpdate:
spinner = event.spinner

View File

@ -56,6 +56,10 @@ func canonicalFromPager(pager *Pager) scrollPositionCanonical {
}
}
func (s *scrollPosition) HasScrolledDown() bool {
return s.internalDontTouch.lineNumberOneBased > 1 || s.internalDontTouch.deltaScreenLines > 0
}
// Create a new position, scrolled towards the end of the file
func (s scrollPosition) PreviousLine(scrollDistance int) scrollPosition {
return scrollPosition{