viewport

package
v0.0.0-...-4a904d8 Latest Latest
Warning

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

Go to latest
Published: May 8, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ViewDown

func ViewDown(m Viewport, 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 Viewport, 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 Viewport

type Viewport struct {
	Width  int
	Height int
	KeyMap keymap.KeyMap

	// Whether or not to respond to the mouse. The mouse must be enabled in
	// Bubble Tea for this to work. For details, see the Bubble Tea docs.
	MouseWheelEnabled bool

	// The number of lines the mouse wheel will scroll. By default, this is 3.
	MouseWheelDelta 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 only.
	YPosition int

	// Style applies a lipgloss style to the viewport. Realistically, it's most
	// useful for setting borders, margins and padding.
	Style lipgloss.Style
	// contains filtered or unexported fields
}

Viewport is the Bubble Tea model for this viewport element.

func NewViewport

func NewViewport(width, height int) (m Viewport)

New returns a new model with the given width and height as well as default keymappings.

func (Viewport) AtBottom

func (m Viewport) AtBottom() bool

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

func (Viewport) AtTop

func (m Viewport) AtTop() bool

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

func (*Viewport) GotoBottom

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

GotoBottom sets the viewport to the bottom position.

func (*Viewport) GotoTop

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

GotoTop sets the viewport to the top position.

func (*Viewport) HalfViewDown

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

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

func (*Viewport) HalfViewUp

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

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

func (Viewport) Init

func (m Viewport) Init() tea.Cmd

Init exists to satisfy the tea.Model interface for composability purposes.

func (*Viewport) LineDown

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

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

func (*Viewport) LineUp

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

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

func (Viewport) PastBottom

func (m Viewport) PastBottom() bool

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

func (Viewport) ScrollPercent

func (m Viewport) ScrollPercent() float64

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

func (*Viewport) SetContent

func (m *Viewport) SetContent(s string)

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

func (*Viewport) SetYOffset

func (m *Viewport) SetYOffset(n int)

SetYOffset sets the Y offset.

func (Viewport) Update

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

Update handles standard message-based viewport updates.

func (Viewport) View

func (m Viewport) View() string

View renders the viewport into a string.

func (*Viewport) ViewDown

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

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

func (*Viewport) ViewUp

func (m *Viewport) 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