Skip to main content

Model

Struct Model 

Source
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: KeyMap

The key mappings for the viewport.

§soft_wrap: bool

Whether or not to wrap text. If false, it’ll allow horizontal scrolling instead.

§fill_height: bool

Whether or not to fill to the height of the viewport with empty lines.

§mouse_wheel_enabled: bool

Whether or not to respond to the mouse. The mouse must be enabled in Bubble Tea for this to work.

§mouse_wheel_delta: usize

The number of lines the mouse wheel will scroll. By default, this is 3.

§y_position: usize

YPosition is the position of the viewport in relation to the terminal window. It’s used in high performance rendering only.

§style: Style

Style 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: Style

HighlightStyle highlights the ranges set with set_highlights.

§selected_highlight_style: Style

SelectedHighlightStyle 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

Source

pub fn height(&self) -> usize

Height returns the height of the viewport.

Source

pub fn set_height(&mut self, h: usize)

SetHeight sets the height of the viewport.

Source

pub fn width(&self) -> usize

Width returns the width of the viewport.

Source

pub fn set_width(&mut self, w: usize)

SetWidth sets the width of the viewport.

Source

pub fn at_top(&self) -> bool

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

Source

pub fn at_bottom(&self) -> bool

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

Source

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.

Source

pub fn scroll_percent(&self) -> f64

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

Source

pub fn horizontal_scroll_percent(&self) -> f64

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

Source

pub fn set_content(&mut self, s: &str)

SetContent set the pager’s text content. Line endings will be normalized to ‘\n’.

Source

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.

Source

pub fn get_content(&self) -> String

GetContent returns the entire content as a single string. Line endings are normalized to ‘\n’.

Source

pub fn set_y_offset(&mut self, n: usize)

SetYOffset sets the Y offset.

Source

pub fn y_offset(&self) -> usize

YOffset returns the current Y offset - the vertical scroll position.

Source

pub fn ensure_visible(&mut self, line: usize, colstart: usize, colend: usize)

EnsureVisible ensures that the given line and column are in the viewport.

Source

pub fn page_down(&mut self)

PageDown moves the view down by the number of lines in the viewport.

Source

pub fn page_up(&mut self)

PageUp moves the view up by one height of the viewport.

Source

pub fn half_page_down(&mut self)

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

Source

pub fn half_page_up(&mut self)

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

Source

pub fn scroll_down(&mut self, n: usize)

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

Source

pub fn scroll_up(&mut self, n: usize)

ScrollUp moves the view up by the given number of lines.

Source

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.

Source

pub fn x_offset(&self) -> usize

XOffset returns the current X offset - the horizontal scroll position.

Source

pub fn set_x_offset(&mut self, n: usize)

SetXOffset sets the X offset. No-op when soft wrap is enabled.

Source

pub fn scroll_left(&mut self, n: usize)

ScrollLeft moves the viewport to the left by the given number of columns.

Source

pub fn scroll_right(&mut self, n: usize)

ScrollRight moves viewport to the right by the given number of columns.

Source

pub fn total_line_count(&self) -> usize

TotalLineCount returns the total number of lines (both hidden and visible) within the viewport.

Source

pub fn visible_line_count(&self) -> usize

VisibleLineCount returns the number of the visible lines within the viewport.

Source

pub fn goto_top(&mut self) -> Vec<String>

GotoTop sets the viewport to the top position.

Source

pub fn goto_bottom(&mut self) -> Vec<String>

GotoBottom sets the viewport to the bottom position.

Source

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.

Source

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.

Source

pub fn clear_highlights(&mut self)

ClearHighlights clears previously set highlights.

Source

pub fn highlight_next(&mut self)

HighlightNext highlights the next match.

Source

pub fn highlight_previous(&mut self)

HighlightPrevious highlights the previous match.

Source

pub fn update(&mut self, msg: &dyn Msg) -> Cmd

Update handles standard message-based viewport updates.

Source

pub fn view(&self) -> String

View renders the viewport into a string.

Trait Implementations§

Source§

impl Clone for Model

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Model

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Model

§

impl !UnwindSafe for Model

§

impl Freeze for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnsafeUnpin for Model

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Msg for T
where T: Any + Send + Sync + Debug,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Helper to downcast to Any.
Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Consumes the boxed message and returns it as a Box<dyn Any>, so the program can move the concrete message out of the trait object (used to dispatch the commands carried by BatchMsg/SequenceMsg).
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.