Help us shape the future of Go! Take the 2026 Go Developer Survey

pager

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package pager is the pantheon suite's shared scroll state for read-only screens: a Pager owns the scroll offset over a block of text and renders it through porticus.Styles.Page, handling the suite's navigation keys and the mouse wheel. It is the line-scroll analogue of browse.Cursor (which owns item selection) — drop one into any tool that shows a markdown preview, a changelog, or a long answer, and scrolling behaves identically everywhere.

Presentation + interaction only: depends on bubbletea, porticus/keys, and the porticus chrome — never on the data spine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pager

type Pager struct {
	// contains filtered or unexported fields
}

Pager holds the scroll offset over a body of text. The zero value is an empty, top-of-page pager ready for SetContent. It remembers the last viewport height it was given (by Handle or View) so the mouse wheel — which carries no height — can still clamp to the bottom.

func (*Pager) Handle

func (p *Pager) Handle(msg tea.KeyMsg, km keys.Map, height int) bool

Handle applies a navigation key and reports whether the offset moved: j/k step a line, ctrl+d/ctrl+u a half page, g/G jump to top/bottom. height is the page height so the half-page step and the bottom stop match what View renders. Keys it doesn't recognise leave the pager unchanged and return false, so the caller can route them.

func (*Pager) HandleMouse

func (p *Pager) HandleMouse(msg tea.MouseMsg) bool

HandleMouse scrolls one line per wheel notch and reports whether it moved. Other mouse events return false. It clamps against the last height the pager saw (from Handle or View), mirroring browse.Cursor.HandleMouse.

func (*Pager) Scroll

func (p *Pager) Scroll() int

Scroll is the current offset (the first body row shown).

func (*Pager) SetContent

func (p *Pager) SetContent(body string)

SetContent replaces the text and clamps the offset to the new content, so a shorter body can't leave the page scrolled past its end. Use Top to jump back to the first row explicitly.

func (*Pager) Top

func (p *Pager) Top()

Top resets the scroll to the first row.

func (*Pager) View

func (p *Pager) View(s porticus.Styles, t porticus.Theme, label string, width, height int) string

View renders the page at the current offset through the standard read-only chrome (the header label over the ══ rule, the windowed body, a scroll hint when it overflows), filled to exactly width×height so the footer stays pinned. It records height so a later wheel event clamps correctly.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL