viewport

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2020 License: MIT Imports: 3 Imported by: 734

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HalfViewDown added in v0.3.0

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

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

func HalfViewUp added in v0.3.0

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

HalfViewUp is a high performance command the moves the viewport up by half of the height of the viewport. Use Model.HalfViewUp to get the lines that should be rendered.

func LineDown added in v0.3.0

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

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

func LineUp added in v0.3.0

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

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

func Sync added in v0.3.0

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 View

func View(m Model) string

View renders the viewport into a string.

func ViewDown added in v0.3.0

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

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

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

func ViewUp added in v0.3.0

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

ViewUp is a high performance command the moves the viewport down by one viewport height. Use Model.ViewDown 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 NewModel

func NewModel(width, height int) Model

TODO: do we really need this?

func Update

func Update(msg tea.Msg, m Model) (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) AtBottom added in v0.3.0

func (m Model) AtBottom() bool

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

func (Model) AtTop added in v0.3.0

func (m Model) AtTop() bool

AtTop returns whether or not the viewport is in the very 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 up 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) 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) SetSize added in v0.3.0

func (m Model) SetSize(yPos, width, height int)

TODO: do we really need this?

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