Documentation
¶
Overview ¶
Package viewport provides a component for rendering a viewport in a Bubble Tea.
Index ¶
- func Sync(m Model) tea.Cmddeprecated
- func ViewDown(m Model, lines []string) tea.Cmddeprecated
- func ViewUp(m Model, lines []string) tea.Cmddeprecated
- type KeyMap
- type Model
- func (m Model) AtBottom() bool
- func (m Model) AtTop() bool
- func (m *Model) GotoBottom() (lines []string)
- func (m *Model) GotoTop() (lines []string)
- func (m *Model) HalfPageDown() (lines []string)
- func (m *Model) HalfPageUp() (lines []string)
- func (m *Model) HalfViewDown() (lines []string)deprecated
- func (m *Model) HalfViewUp() (lines []string)deprecated
- func (m Model) HorizontalScrollPercent() float64
- func (m Model) Init() tea.Cmd
- func (m *Model) LineDown(n int) (lines []string)deprecated
- func (m *Model) LineUp(n int) (lines []string)deprecated
- func (m *Model) PageDown() []string
- func (m *Model) PageUp() []string
- func (m Model) PastBottom() bool
- func (m *Model) ScrollDown(n int) (lines []string)
- func (m *Model) ScrollLeft(n int)
- func (m Model) ScrollPercent() float64
- func (m *Model) ScrollRight(n int)
- func (m *Model) ScrollUp(n int) (lines []string)
- func (m *Model) SetContent(s string)
- func (m *Model) SetHorizontalStep(n int)
- func (m *Model) SetXOffset(n int)
- func (m *Model) SetYOffset(n int)
- func (m Model) TotalLineCount() int
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) View() string
- func (m *Model) ViewDown() []stringdeprecated
- func (m *Model) ViewUp() []stringdeprecated
- func (m Model) VisibleLineCount() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sync
deprecated
added in
v0.3.0
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.
Deprecated: high performance rendering is deprecated in Bubble Tea.
func ViewDown
deprecated
added in
v0.3.0
ViewDown is a high performance command that moves the viewport up by a given number of lines. Use Model.ViewDown to get the lines that should be rendered. For example:
lines := model.ViewDown(1) cmd := ViewDown(m, lines)
Deprecated: high performance rendering is deprecated in Bubble Tea.
func ViewUp
deprecated
added in
v0.3.0
Types ¶
type KeyMap ¶ added in v0.10.0
type KeyMap struct { PageDown key.Binding PageUp key.Binding HalfPageUp key.Binding HalfPageDown key.Binding Down key.Binding Up key.Binding Left key.Binding Right key.Binding }
KeyMap defines the keybindings for the viewport. Note that you don't necessary need to use keybindings at all; the viewport can be controlled programmatically with methods like Model.LineDown(1). See the GoDocs for details.
func DefaultKeyMap ¶ added in v0.10.0
func DefaultKeyMap() KeyMap
DefaultKeyMap returns a set of pager-like default keybindings.
type Model ¶
type Model struct { Width int Height int 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 // 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. // // Deprecated: high performance rendering is now deprecated in Bubble Tea. HighPerformanceRendering bool // contains filtered or unexported fields }
Model is the Bubble Tea model for this viewport element.
func New ¶ added in v0.10.0
New returns a new model with the given width and height as well as default key mappings.
func (Model) AtBottom ¶ added in v0.3.0
AtBottom returns whether or not the viewport is at or past the very bottom position.
func (Model) AtTop ¶ added in v0.3.0
AtTop returns whether or not the viewport is at the very top position.
func (*Model) GotoBottom ¶ added in v0.4.1
GotoBottom sets the viewport to the bottom position.
func (*Model) HalfPageDown ¶ added in v0.21.0
HalfPageDown moves the view down by half the height of the viewport.
func (*Model) HalfPageUp ¶ added in v0.21.0
HalfPageUp moves the view up by half the height of the viewport.
func (*Model) HalfViewDown
deprecated
HalfViewDown moves the view down by half the height of the viewport.
Deprecated: use Model.HalfPageDown instead.
func (*Model) HalfViewUp
deprecated
HalfViewUp moves the view up by half the height of the viewport.
Deprecated: use Model.HalfPageUp instead.
func (Model) HorizontalScrollPercent ¶ added in v0.21.0
HorizontalScrollPercent returns the amount horizontally scrolled as a float between 0 and 1.
func (Model) Init ¶ added in v0.10.0
Init exists to satisfy the tea.Model interface for composability purposes.
func (*Model) LineDown
deprecated
LineDown moves the view down by the given number of lines.
Deprecated: use Model.ScrollDown instead.
func (*Model) LineUp
deprecated
LineUp moves the view down by the given number of lines. Returns the new lines to show.
Deprecated: use Model.ScrollUp instead.
func (*Model) PageDown ¶ added in v0.21.0
PageDown moves the view down by the number of lines in the viewport.
func (Model) PastBottom ¶ added in v0.4.1
PastBottom returns whether or not the viewport is scrolled beyond the last line. This can happen when adjusting the viewport height.
func (*Model) ScrollDown ¶ added in v0.21.0
ScrollDown moves the view down by the given number of lines.
func (*Model) ScrollLeft ¶ added in v0.21.0
ScrollLeft moves the viewport to the left by the given number of columns.
func (Model) ScrollPercent ¶
ScrollPercent returns the amount scrolled as a float between 0 and 1.
func (*Model) ScrollRight ¶ added in v0.21.0
ScrollRight moves viewport to the right by the given number of columns.
func (*Model) ScrollUp ¶ added in v0.21.0
ScrollUp moves the view down by the given number of lines. Returns the new lines to show.
func (*Model) SetContent ¶
SetContent set the pager's text content.
func (*Model) SetHorizontalStep ¶ added in v0.21.0
SetHorizontalStep sets the default amount of columns to scroll left or right with the default viewport key map.
If set to 0 or less, horizontal scrolling is disabled.
On v1, horizontal scrolling is disabled by default.
func (*Model) SetXOffset ¶ added in v0.21.0
SetXOffset sets the X offset.
func (*Model) SetYOffset ¶ added in v0.10.0
SetYOffset sets the Y offset.
func (Model) TotalLineCount ¶ added in v0.15.0
TotalLineCount returns the total number of lines (both hidden and visible) within the viewport.
func (*Model) ViewDown
deprecated
ViewDown moves the view down by the number of lines in the viewport. Basically, "page down".
Deprecated: use Model.PageDown instead.
func (*Model) ViewUp
deprecated
ViewUp moves the view up by one height of the viewport. Basically, "page up".
Deprecated: use Model.PageUp instead.
func (Model) VisibleLineCount ¶ added in v0.15.0
VisibleLineCount returns the number of the visible lines within the viewport.