[][src]Struct xterm_js_sys::crossterm_support::XtermJsCrosstermBackend

pub struct XtermJsCrosstermBackend<'a> {
    pub terminal: &'a Terminal,
    buffer: Cell<Vec<u8>>,
}
This is supported on feature="crossterm-support" only.

Wrapper for the xterm.js terminal for use with crossterm.

Fields

terminal: &'a Terminal
This is supported on feature="crossterm-support" only.

The xterm.js terminal that this struct instance wraps.

buffer: Cell<Vec<u8>>
This is supported on feature="crossterm-support" only.

Internal buffer for data to write to the terminal.

This lets us make one big call to Terminal::write with a batch of commands rather than many small calls.

Implementations

impl<'a> XtermJsCrosstermBackend<'a>[src]

#[must_use]pub fn new(terminal: &'a Terminal) -> Self[src]

This is supported on feature="crossterm-support" only.

Constructor for the wrapper type.

#[must_use]pub fn new_with_capacity(terminal: &'a Terminal, capacity: usize) -> Self[src]

This is supported on feature="crossterm-support" only.

Like new except it also takes an estimate for the size of the internal buffer.

This is useful if you have a good guess about how many bytes the commands you're going to send will need.

pub fn write_immediately(&mut self, commands: String) -> IoResult<()>[src]

This is supported on feature="crossterm-support" only.

Writes a String directly to the underlying terminal, bypassing the buffer.

This is useful for situations in which the commands being sent are already buffered and the extra copy is undesired. Note that this will flush the buffer first to preserve the order of commands.

Errors

This should never actually error. For consistency with the Write calls it results an io::Result

fn flush_immutable(&self) -> IoResult<()>[src]

This is supported on feature="crossterm-support" only.

A version of flush that takes an immutable reference instead of a mutable one.

This exists because we want to flush the buffer in the Deref impl.

Methods from Deref<Target = Terminal>

pub fn buffer(&self) -> BufferNamespace[src]

[EXPERIMENTAL] The terminal’s current buffer, this might be either the normal buffer or the alt buffer depending on what’s running in the terminal.

pub fn cols(&self) -> u16[src]

The number of columns in the terminal’s viewport. Use TerminalOptions::cols to set this in the constructor and Terminal::resize for when the terminal exists.

pub fn element(&self) -> Option<Element>[src]

The element containing the terminal.

pub fn markers(&self) -> ReadOnlyArray<Marker>[src]

[EXPERIMENTAL] Get all markers registered against the buffer.

If the alt buffer is active this will always return [] (an empty array).

pub fn on_binary(&self, listener: &Closure<dyn FnMut(Str)>) -> Disposable[src]

Adds an event listener for when a binary event fires.

This is used to enable non UTF-8 conformant binary messages to be sent to the backend. Currently this is only used for a certain type of mouse reports that happen to be not UTF-8 compatible. The event value is a String, pass it to the underlying pty as binary data, e.g. pty.write(Buffer.from(data, 'binary')).

Returns a Disposable to stop listening.

See attach_binary_event_listener (if the ext feature is enabled) for a friendlier version of this function.

pub fn on_cursor_move(&self, listener: &Closure<dyn FnMut()>) -> Disposable[src]

Adds an event listener for the cursor moves.

Returns a Disposable to stop listening.

See attach_cursor_move_event_listener (if the ext feature is enabled) for a friendlier version of this function.

pub fn on_data(&self, listener: &Closure<dyn FnMut(Str)>) -> Disposable[src]

Adds an event listener for when a data event fires.

This happens, for example, when the user types or pastes into the terminal. The event value is whatever String results; in a typical setup, this should be passed on to the backing pty.

Returns a Disposable to stop listening.

See attach_data_event_listener (if the ext feature is enabled) for a friendlier version of this function.

pub fn on_key(&self, listener: &Closure<dyn FnMut(KeyEventData)>) -> Disposable[src]

Adds an event listener for when a key is pressed.

The event value (KeyEventData) contains the string that will be sent in the data event as well as the DOM event that triggered it.

Returns a Disposable to stop listening.

See attach_key_event_listener (if the ext feature is enabled) for a friendlier version of this function.

pub fn on_line_feed(&self, listener: &Closure<dyn FnMut()>) -> Disposable[src]

Adds an event listener for when a line feed is added.

Returns a Disposable to stop listening.

See attach_line_feed_event_listener (if the ext feature is enabled) for a friendlier version of this function.

pub fn on_render(
    &self,
    listener: &Closure<dyn FnMut(RenderEventData)>
) -> Disposable
[src]

Adds an event listener for when rows are rendered.

The event value (RenderEventData) contains the start row and end row of the rendered area (ranges from 0 to [Terminal::rows] - 1).

Returns a Disposable to stop listening.

See attach_render_event_listener (if the ext feature is enabled) for a friendlier version of this function.

pub fn on_resize(
    &self,
    listener: &Closure<dyn FnMut(ResizeEventData)>
) -> Disposable
[src]

Adds an event listener for when the terminal is resized.

The event value (ResizeEventData) contains the new size.

Returns a Disposable to stop listening.

See attach_resize_event_listener (if the ext feature is enabled) for a friendlier version of this function.

pub fn on_scroll(&self, listener: &Closure<dyn FnMut(u32)>) -> Disposable[src]

Adds an event listener for when a event listener for when a scroll occurs.

The event value is the new position of the viewport.

Returns a Disposable to stop listening.

See attach_scroll_event_listener (if the ext feature is enabled) for a friendlier version of this function.

pub fn on_selection_change(&self, listener: &Closure<dyn FnMut()>) -> Disposable[src]

Adds an event listener for when a selection change occurs.

Returns a Disposable to stop listening.

See attach_selection_change_event_listener (if the ext feature is enabled) for a friendlier version of this function.

pub fn on_title_change(&self, listener: &Closure<dyn FnMut(Str)>) -> Disposable[src]

Adds an event listener for when an OSC 0 or OSC 2 title change occurs.

The event value is the new title.

Returns a Disposable to stop listening.

See attach_title_change_event_listener (if the ext feature is enabled) for a friendlier version of this function.

pub fn parser(&self) -> Parser[src]

[EXPERIMENTAL] Get the parser interface to register custom escape sequence handlers.

pub fn rows(&self) -> u16[src]

The number of rows in the terminal’s viewport. Use TerminalOptions.rows to set this in the constructor and Terminal::resize for when the terminal exists.

pub fn textarea(&self) -> Option<HtmlTextAreaElement>[src]

The textarea that accepts input for the terminal.

pub fn unicode(&self) -> UnicodeHandling[src]

[EXPERIMENTAL] Get the Unicode handling interface.

This can be used to register Unicode versions and switch the active Unicode version.

pub fn strings(&self) -> LocalizableStrings[src]

Natural language strings that can be localized.

pub fn blur(&self)[src]

Unfocus the terminal.

pub fn clear(&self)[src]

Clear the entire buffer, making the prompt line the new first line.

pub fn clear_selection(&self)[src]

Clears the current terminal selection.

pub fn focus(&self)[src]

Focus the terminal.

pub fn get_selection(&self) -> Str[src]

Gets the terminal’s current selection; this is useful for implementing copy behavior outside of xterm.js.

pub fn get_selection_position(&self) -> Option<SelectionPosition>[src]

Gets the selection position or None if there is no selection.

pub fn has_selection(&self) -> bool[src]

Gets whether the terminal has an active selection.

pub fn load_addon(&self, addon: TerminalAddon)[src]

Loads an addon into this instance of the xterm.js Terminal.

Takes:

  • addon: The addon to load.

See load_xterm_addon (if the ext feature is enabled) for a friendlier version of this function.

pub fn open(&self, parent: Element)[src]

Opens the terminal within an element.

Takes:

  • parent: The element to create the terminal within. This element must be visible (have dimensions) when open is called as several DOM-based measurements need to be performed when this function is called.

pub fn paste(&self, data: Str)[src]

Writes text to the terminal, performing the necessary transformations for pasted text.

Takes:

  • data: The text to write to the terminal.

pub fn refresh(&self, start: u16, end: u16)[src]

Tells the renderer to refresh terminal content between two rows (inclusive) at the next opportunity.

Takes:

  • start: The row to start from (between 0 and [Terminal::rows] - 1).
  • end: The row to end at (between start and [Terminal::rows] - 1).

pub fn reset(&self)[src]

Perform a full reset (RIS, aka ‘\x1bc’).

pub fn resize(&self, columns: u16, rows: u16)[src]

Resizes the terminal.

It’s best practice to debounce calls to resize, this will help ensure that the pty can respond to the resize event before another one occurs.

pub fn scroll_lines(&self, amount: i32)[src]

Scroll the display of the terminal.

Takes:

  • amount: The number of lines to scroll down (negative scrolls up).

pub fn scroll_pages(&self, page_count: i32)[src]

Scroll the display of the terminal by a number of pages.

Takes:

  • page_count: The number of pages to scroll (negative scrolls up).

pub fn scroll_to_bottom(&self)[src]

Scrolls the display of the terminal to the bottom.

pub fn scroll_to_line(&self, line: u32)[src]

Scrolls to a line within the buffer.

Takes:

  • line: The 0-based line index to scroll to.

pub fn scroll_to_top(&self)[src]

Scrolls the display of the terminal to the top.

pub fn select(&self, column: u16, row: u32, length: u32)[src]

Selects text within the terminal.

Takes:

  • column: The column the selection starts at.
  • row: The row the selection starts at.
  • length: The length of the selection.

pub fn select_all(&self)[src]

Selects all text within the terminal.

pub fn select_lines(&self, start: u32, end: u32)[src]

Selects text in the buffer between 2 lines.

Takes:

  • start: The 0-based line index to select from (inclusive).
  • end: The 0-based line index to select to (inclusive).

pub fn write(&self, data: Str)[src]

Writes data to the terminal.

Takes:

  • data: The data to write to the terminal. The actual API allows for this to be either raw bytes given as Uint8Array from the pty or a string (raw bytes will always be treated as UTF-8 encoded, string data as UTF-16). For simplicity, we just take a String; this shouldn't cause problems (going from UTF-8 encoded Rust Strings to UTF-16 JS strings) and just makes things simpler.

pub fn write_with_callback(&self, data: Str, callback: &Closure<dyn FnMut()>)[src]

Writes data to the terminal and takes a callback.

This identical to write except it also takes a callback.

Takes:

  • data: The data to write to the terminal. The actual API allows for this to be either raw bytes given as Uint8Array from the pty or a string (raw bytes will always be treated as UTF-8 encoded, string data as UTF-16). For simplicity, we just take a String; this shouldn't cause problems (going from UTF-8 encoded Rust Strings to UTF-16 JS strings) and just makes things simpler.
  • callback: Callback that fires when the data was processed by the parser.

pub fn load_xterm_addon<A: IntoJsInterface<TerminalAddon>>(&self, addon: &A)[src]

This is supported on feature="ext" only.

Loads an addon into this instance of the xterm.js Terminal.

This supports Rust defined addons as well as JS defined addons and is otherwise identical to Terminal::load_addon.

pub fn attach_binary_event_listener<F>(
    &self,
    listener: F
) -> DisposableWrapper<Disposable> where
    F: FnMut(Str),
    F: 'static, 
[src]

This is supported on feature="ext" only.

Attaches a binary event listener and returns a DisposableWrapper that can be dropped to make xterm.js stop sending the event listener events. This is sugar for Terminal::on_binary.

We assume event listener closures are going to be long-lived, so we leak the closure that is produced here!

pub fn attach_cursor_move_event_listener<F>(
    &self,
    listener: F
) -> DisposableWrapper<Disposable> where
    F: FnMut(),
    F: 'static, 
[src]

This is supported on feature="ext" only.

Attaches a cursor move event listener and returns a DisposableWrapper that can be dropped to make xterm.js stop sending the event listener events. This is sugar for Terminal::on_cursor_move.

We assume event listener closures are going to be long-lived, so we leak the closure that is produced here!

pub fn attach_data_event_listener<F>(
    &self,
    listener: F
) -> DisposableWrapper<Disposable> where
    F: FnMut(Str),
    F: 'static, 
[src]

This is supported on feature="ext" only.

Attaches a data event listener and returns a DisposableWrapper that can be dropped to make xterm.js stop sending the event listener events. This is sugar for Terminal::on_data.

We assume event listener closures are going to be long-lived, so we leak the closure that is produced here!

pub fn attach_key_event_listener<F>(
    &self,
    listener: F
) -> DisposableWrapper<Disposable> where
    F: FnMut(KeyEventData),
    F: 'static, 
[src]

This is supported on feature="ext" only.

Attaches a key event event listener and returns a DisposableWrapper that can be dropped to make xterm.js stop sending the event listener events. This is sugar for Terminal::on_key.

We assume event listener closures are going to be long-lived, so we leak the closure that is produced here!

pub fn attach_line_feed_event_listener<F>(
    &self,
    listener: F
) -> DisposableWrapper<Disposable> where
    F: FnMut(),
    F: 'static, 
[src]

This is supported on feature="ext" only.

Attaches a line feed event listener and returns a DisposableWrapper that can be dropped to make xterm.js stop sending the event listener events. This is sugar for Terminal::on_line_feed.

We assume event listener closures are going to be long-lived, so we leak the closure that is produced here!

pub fn attach_render_event_listener<F>(
    &self,
    listener: F
) -> DisposableWrapper<Disposable> where
    F: FnMut(RenderEventData),
    F: 'static, 
[src]

This is supported on feature="ext" only.

Attaches a render event listener and returns a DisposableWrapper that can be dropped to make xterm.js stop sending the event listener events. This is sugar for Terminal::on_render.

We assume event listener closures are going to be long-lived, so we leak the closure that is produced here!

pub fn attach_resize_event_listener<F>(
    &self,
    listener: F
) -> DisposableWrapper<Disposable> where
    F: FnMut(ResizeEventData),
    F: 'static, 
[src]

This is supported on feature="ext" only.

Attaches a resize event listener and returns a DisposableWrapper that can be dropped to make xterm.js stop sending the event listener events. This is sugar for Terminal::on_resize.

We assume event listener closures are going to be long-lived, so we leak the closure that is produced here!

pub fn attach_scroll_event_listener<F>(
    &self,
    listener: F
) -> DisposableWrapper<Disposable> where
    F: FnMut(u32),
    F: 'static, 
[src]

This is supported on feature="ext" only.

Attaches a scroll event listener and returns a DisposableWrapper that can be dropped to make xterm.js stop sending the event listener events. This is sugar for Terminal::on_scroll.

We assume event listener closures are going to be long-lived, so we leak the closure that is produced here!

pub fn attach_selection_change_event_listener<F>(
    &self,
    listener: F
) -> DisposableWrapper<Disposable> where
    F: FnMut(),
    F: 'static, 
[src]

This is supported on feature="ext" only.

Attaches a selection change event listener and returns a DisposableWrapper that can be dropped to make xterm.js stop sending the event listener events. This is sugar for Terminal::on_selection_change.

We assume event listener closures are going to be long-lived, so we leak the closure that is produced here!

pub fn attach_title_change_event_listener<F>(
    &self,
    listener: F
) -> DisposableWrapper<Disposable> where
    F: FnMut(Str),
    F: 'static, 
[src]

This is supported on feature="ext" only.

Attaches a title change event listener and returns a DisposableWrapper that can be dropped to make xterm.js stop sending the event listener events. This is sugar for Terminal::on_title_change.

We assume event listener closures are going to be long-lived, so we leak the closure that is produced here!

Trait Implementations

impl<'a> Debug for XtermJsCrosstermBackend<'a>[src]

impl<'a> Deref for XtermJsCrosstermBackend<'a>[src]

type Target = Terminal

The resulting type after dereferencing.

fn deref(&self) -> &Terminal[src]

This will flush the internal buffer before providing the reference to make sure that the order of operations is preserved.

impl<'a> Drop for XtermJsCrosstermBackend<'a>[src]

impl<'a> From<&'a Terminal> for XtermJsCrosstermBackend<'a>[src]

impl<'a> Write for XtermJsCrosstermBackend<'a>[src]

Auto Trait Implementations

impl<'a> !RefUnwindSafe for XtermJsCrosstermBackend<'a>

impl<'a> !Send for XtermJsCrosstermBackend<'a>

impl<'a> !Sync for XtermJsCrosstermBackend<'a>

impl<'a> Unpin for XtermJsCrosstermBackend<'a>

impl<'a> UnwindSafe for XtermJsCrosstermBackend<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.