pub struct Model {
pub key_map: KeyMap,
pub soft_wrap: bool,
pub fill_height: bool,
pub mouse_wheel_enabled: bool,
pub mouse_wheel_delta: usize,
pub y_position: usize,
pub style: Style,
pub left_gutter_func: Option<GutterFunc>,
pub highlight_style: Style,
pub selected_highlight_style: Style,
pub style_line_func: Option<Box<dyn Fn(usize) -> Style + Send + Sync>>,
/* private fields */
}Expand description
Model is the Bubble Tea model for this viewport element.
Fields§
§key_map: KeyMapThe key mappings for the viewport.
soft_wrap: boolWhether or not to wrap text. If false, it’ll allow horizontal scrolling instead.
fill_height: boolWhether or not to fill to the height of the viewport with empty lines.
mouse_wheel_enabled: boolWhether or not to respond to the mouse. The mouse must be enabled in Bubble Tea for this to work.
mouse_wheel_delta: usizeThe number of lines the mouse wheel will scroll. By default, this is 3.
y_position: usizeYPosition is the position of the viewport in relation to the terminal window. It’s used in high performance rendering only.
style: StyleStyle applies a lipgloss style to the viewport. Realistically, it’s most useful for setting borders, margins and padding.
left_gutter_func: Option<GutterFunc>LeftGutterFunc allows to define a GutterFunc that adds a column
into the left of the viewport, which is kept when horizontal
scrolling.
highlight_style: StyleHighlightStyle highlights the ranges set with set_highlights.
selected_highlight_style: StyleSelectedHighlightStyle highlights the highlight range focused during navigation.
style_line_func: Option<Box<dyn Fn(usize) -> Style + Send + Sync>>StyleLineFunc allows to return a Style for each line. The
argument is the line index.
Implementations§
Source§impl Model
impl Model
Sourcepub fn set_height(&mut self, h: usize)
pub fn set_height(&mut self, h: usize)
SetHeight sets the height of the viewport.
Sourcepub fn at_top(&self) -> bool
pub fn at_top(&self) -> bool
AtTop returns whether or not the viewport is at the very top position.
Sourcepub fn at_bottom(&self) -> bool
pub fn at_bottom(&self) -> bool
AtBottom returns whether or not the viewport is at or past the very bottom position.
Sourcepub fn past_bottom(&self) -> bool
pub fn past_bottom(&self) -> bool
PastBottom returns whether or not the viewport is scrolled beyond the last line. This can happen when adjusting the viewport height.
Sourcepub fn scroll_percent(&self) -> f64
pub fn scroll_percent(&self) -> f64
ScrollPercent returns the amount scrolled as a float between 0 and 1.
Sourcepub fn horizontal_scroll_percent(&self) -> f64
pub fn horizontal_scroll_percent(&self) -> f64
HorizontalScrollPercent returns the amount horizontally scrolled as a float between 0 and 1.
Sourcepub fn set_content(&mut self, s: &str)
pub fn set_content(&mut self, s: &str)
SetContent set the pager’s text content. Line endings will be normalized to ‘\n’.
Sourcepub fn set_content_lines(&mut self, lines: &[String])
pub fn set_content_lines(&mut self, lines: &[String])
SetContentLines allows to set the lines to be shown instead of the
content. If a given line has a \n in it, it will still be split into
multiple lines similar to that of set_content.
Sourcepub fn get_content(&self) -> String
pub fn get_content(&self) -> String
GetContent returns the entire content as a single string. Line endings are normalized to ‘\n’.
Sourcepub fn set_y_offset(&mut self, n: usize)
pub fn set_y_offset(&mut self, n: usize)
SetYOffset sets the Y offset.
Sourcepub fn y_offset(&self) -> usize
pub fn y_offset(&self) -> usize
YOffset returns the current Y offset - the vertical scroll position.
Sourcepub fn ensure_visible(&mut self, line: usize, colstart: usize, colend: usize)
pub fn ensure_visible(&mut self, line: usize, colstart: usize, colend: usize)
EnsureVisible ensures that the given line and column are in the viewport.
Sourcepub fn page_down(&mut self)
pub fn page_down(&mut self)
PageDown moves the view down by the number of lines in the viewport.
Sourcepub fn half_page_down(&mut self)
pub fn half_page_down(&mut self)
HalfPageDown moves the view down by half the height of the viewport.
Sourcepub fn half_page_up(&mut self)
pub fn half_page_up(&mut self)
HalfPageUp moves the view up by half the height of the viewport.
Sourcepub fn scroll_down(&mut self, n: usize)
pub fn scroll_down(&mut self, n: usize)
ScrollDown moves the view down by the given number of lines.
Sourcepub fn set_horizontal_step(&mut self, n: usize)
pub fn set_horizontal_step(&mut self, n: usize)
SetHorizontalStep sets the amount of cells that the viewport moves in the default viewport keymapping. If set to 0 or less, horizontal scrolling is disabled.
Sourcepub fn x_offset(&self) -> usize
pub fn x_offset(&self) -> usize
XOffset returns the current X offset - the horizontal scroll position.
Sourcepub fn set_x_offset(&mut self, n: usize)
pub fn set_x_offset(&mut self, n: usize)
SetXOffset sets the X offset. No-op when soft wrap is enabled.
Sourcepub fn scroll_left(&mut self, n: usize)
pub fn scroll_left(&mut self, n: usize)
ScrollLeft moves the viewport to the left by the given number of columns.
Sourcepub fn scroll_right(&mut self, n: usize)
pub fn scroll_right(&mut self, n: usize)
ScrollRight moves viewport to the right by the given number of columns.
Sourcepub fn total_line_count(&self) -> usize
pub fn total_line_count(&self) -> usize
TotalLineCount returns the total number of lines (both hidden and visible) within the viewport.
Sourcepub fn visible_line_count(&self) -> usize
pub fn visible_line_count(&self) -> usize
VisibleLineCount returns the number of the visible lines within the viewport.
Sourcepub fn goto_bottom(&mut self) -> Vec<String>
pub fn goto_bottom(&mut self) -> Vec<String>
GotoBottom sets the viewport to the bottom position.
Sourcepub fn set_highlights(&mut self, matches: &[Vec<usize>])
pub fn set_highlights(&mut self, matches: &[Vec<usize>])
SetHighlights sets ranges of characters to highlight.
For instance, [[2, 10], [20, 30]] will highlight characters 2 to 10
and 20 to 30.
Note that highlights are not expected to transpose each other, and
are also expected to be in order.
Sourcepub fn highlights(&self) -> &[HighlightInfo]
pub fn highlights(&self) -> &[HighlightInfo]
Highlights returns the currently set highlight ranges.
This is exposed so integration tests can assert on highlight ranges the same way the upstream in-package tests do.
Sourcepub fn clear_highlights(&mut self)
pub fn clear_highlights(&mut self)
ClearHighlights clears previously set highlights.
Sourcepub fn highlight_next(&mut self)
pub fn highlight_next(&mut self)
HighlightNext highlights the next match.
Sourcepub fn highlight_previous(&mut self)
pub fn highlight_previous(&mut self)
HighlightPrevious highlights the previous match.