viewport

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sync

func Sync(m Model) tea.Cmd

Sync tells the renderer where the viewport will be located and requests a render of the current state of the viewport. It should be called for the first render and after a window resize.

For high performance rendering only.

func ViewDown

func ViewDown(m Model, lines []string) tea.Cmd

ViewDown is a high performance command that moves the viewport up by a given numer of lines. Use Model.ViewDown to get the lines that should be rendered. For example:

lines := model.ViewDown(1)
cmd := ViewDown(m, lines)

func ViewUp

func ViewUp(m Model, lines []string) tea.Cmd

ViewUp is a high performance command the moves the viewport down by a given number of lines height. Use Model.ViewUp to get the lines that should be rendered.

Types

type Model

type Model struct {
	Width  int
	Height int

	// YOffset is the vertical scroll position.
	YOffset int

	// YPosition is the position of the viewport in relation to the terminal
	// window. It's used in high performance rendering.
	YPosition int

	// HighPerformanceRendering bypasses the normal Bubble Tea renderer to
	// provide higher performance rendering. Most of the time the normal Bubble
	// Tea rendering methods will suffice, but if you're passing content with
	// a lot of ANSI escape codes you may see improved rendering in certain
	// terminals with this enabled.
	//
	// This should only be used in program occupying the entire terminal,
	// which is usually via the alternate screen buffer.
	HighPerformanceRendering bool
	// contains filtered or unexported fields
}

func (Model) AtBottom

func (m Model) AtBottom() bool

AtBottom returns whether or not the viewport is at or past the very bottom position.

func (Model) AtTop

func (m Model) AtTop() bool

AtTop returns whether or not the viewport is in the very top position.

func (*Model) GotoBottom

func (m *Model) GotoBottom() (lines []string)

GotoTop sets the viewport to the bottom position.

func (*Model) GotoTop

func (m *Model) GotoTop() (lines []string)

GotoTop sets the viewport to the top position.

func (*Model) HalfViewDown

func (m *Model) HalfViewDown() (lines []string)

HalfViewDown moves the view down by half the height of the viewport.

func (*Model) HalfViewUp

func (m *Model) HalfViewUp() (lines []string)

HalfViewUp moves the view up by half the height of the viewport.

func (*Model) LineDown

func (m *Model) LineDown(n int) (lines []string)

LineDown moves the view down by the given number of lines.

func (*Model) LineUp

func (m *Model) LineUp(n int) (lines []string)

LineUp moves the view down by the given number of lines. Returns the new lines to show.

func (Model) PastBottom

func (m Model) PastBottom() bool

PastBottom returns whether or not the viewport is scrolled beyond the last line. This can happen when adjusting the viewport height.

func (Model) ScrollPercent

func (m Model) ScrollPercent() float64

Scrollpercent returns the amount scrolled as a float between 0 and 1.

func (*Model) SetContent

func (m *Model) SetContent(s string)

SetContent set the pager's text content. For high performance rendering the Sync command should also be called.

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update runs the update loop with default keybindings similar to popular pagers. To define your own keybindings use the methods on Model (i.e. Model.LineDown()) and define your own update function.

func (Model) View

func (m Model) View() string

View renders the viewport into a string.

func (*Model) ViewDown

func (m *Model) ViewDown() []string

ViewDown moves the view down by the number of lines in the viewport. Basically, "page down".

func (*Model) ViewUp

func (m *Model) ViewUp() []string

ViewUp moves the view up by one height of the viewport. Basically, "page up".

Jump to

Keyboard shortcuts

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