Skip to main content

Editor

Struct Editor 

Source
pub struct Editor {
    pub theme: Theme,
    /* private fields */
}

Fields§

§theme: Theme

Implementations§

Source§

impl Editor

Source

pub fn render(&mut self, buffer: &mut RenderBuffer) -> Result<()>

The main render function for updating the terminal

§Arguments
  • buffer: The buffer to render
§Errors

Can return an IoError

Source

pub fn render_diff(&mut self, change_set: Vec<Change<'_>>) -> Result<()>

Renders new changes to the terminal

§Arguments
  • change_set: A vector of changes to render
§Errors

Can return an IoError

§Panics

This function will panic if draw_cursor panics

Source

pub fn draw_status_line(&mut self, buffer: &mut RenderBuffer)

Draws the status line at the bottom of the editor view

§Arguments
  • buffer: The buffer containing the status line
§Panics

This function may panic if the lengths of the mode and position strings exceed u16::MAX, which is currently impossible for the mode string but is not necessarily impossible for the position string

Source

pub fn draw_cursor(&mut self) -> Result<()>

Draws the cursor based on current style and position

§Errors

Can return an error if set_cursor_style fails or if the stdout queue fails to move the cursor

§Panics

This function might panic if the numeric values of the cursor’s target (x, y) position exceed u16::MAX

Source§

impl Editor

Source

pub fn with_size( width: usize, height: usize, config: Config, theme: Theme, buffers: Vec<Buffer>, ) -> Result<Self>

Creates a new editor with a given size

§Arguments
  • width: The desired width of the editor viewport
  • height: The desired height of the editor viewport
  • config: A configuration constructed from a parsed config file
  • theme: A theme for coloring, styling, and decorating the editor
  • buffers: A buffer which will contain the contents of the file being edited
§Errors

Can return errors if width and height are larger than u16::MAX or if creating a new Highlighter with the provided theme fails

§Panics

This function may panic if width and height are larger than u16::MAX

Source

pub fn new(config: Config, theme: Theme, buffers: Vec<Buffer>) -> Result<Self>

Creates a new editor with a configuration, theme, and buffer

§Arguments
  • config: A configuration constructed from a parsed config file
  • theme: A theme for coloring, styling, and decorating the editor
  • buffers: A buffer which will contain the contents of the file being edited
§Errors

Can return an IoError if the call to query the terminal’s size fails

Source

pub fn vwidth(&self) -> usize

Source

pub fn vheight(&self) -> usize

Source

pub fn window_to_terminal_x(&self, window: &Window, x: usize) -> usize

Source

pub fn window_to_terminal_y(&self, window: &Window, y: usize) -> usize

Source

pub fn buffer_to_window_coords( &self, window: &Window, buf_x: usize, buf_y: usize, ) -> Option<(usize, usize)>

Source

pub fn window_vwidth(&self, window: &Window) -> usize

Source

pub fn window_vheight(&self, window: &Window) -> usize

Source

pub fn cursor_position(&self) -> (usize, usize)

Source

pub fn highlight(&mut self, code: &str) -> Result<Vec<StyleInfo>>

Wrapper for the editor’s highlighter functionality

§Arguments
  • code: The contents of a file represented as a string and assumed to be “code”, i.e., pertaining to a programming language supported by the tree sitter
§Errors

Could potentially return an error if the highlighter throws an error

Source

pub async fn run(&mut self) -> Result<()>

Executes the primary run loop for the application

§Errors

Can return an error if any failures occur with enabling raw mode in the terminal or executing some command to stdout

Source

pub fn cleanup(&mut self) -> Result<()>

Safely cleans up the terminal before exiting

§Errors

Can return an error if any of the subfunctions fail

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.