Skip to main content

TerminaBackend

Struct TerminaBackend 

Source
pub struct TerminaBackend<T>
where T: Terminal,
{ /* private fields */ }
Expand description

A Backend implementation that renders through a termina::Terminal.

TerminaBackend writes typed Termina escape sequences for drawing, cursor control, clearing, and terminal-size queries.

This backend does not automatically enable raw mode or switch to the alternate screen. Use Termina’s terminal APIs and typed escape sequences to configure those application-level modes before drawing.

§Example

use ratatui::Terminal;
use ratatui::backend::TerminaBackend;
use ratatui::termina::{PlatformTerminal, Terminal as _};

let mut output = PlatformTerminal::new()?;
output.enter_raw_mode()?;

let backend = TerminaBackend::new(output);
let mut terminal = Terminal::new(backend)?;

terminal.draw(|frame| {
    // -- snip --
})?;

Implementations§

Source§

impl<T> TerminaBackend<T>
where T: Terminal,

Source

pub const fn new(terminal: T) -> Self

Creates a backend that writes to the given Termina terminal.

Source

pub const fn terminal(&self) -> &T

Available on crate feature unstable-backend-writer only.

Returns the wrapped terminal.

§Stability

This API is marked as unstable and is only available when the unstable-backend-writer crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time. The tracking issue is: https://github.com/ratatui/ratatui/pull/991.

Source

pub const fn terminal_mut(&mut self) -> &mut T

Available on crate feature unstable-backend-writer only.

Returns the wrapped terminal as a mutable reference.

Direct writes can desynchronize Ratatui’s diffing buffers from the visible terminal. Clear the terminal or force a full redraw before relying on Ratatui’s next diff.

§Stability

This API is marked as unstable and is only available when the unstable-backend-writer crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time. The tracking issue is: https://github.com/ratatui/ratatui/pull/991.

Trait Implementations§

Source§

impl<T> Backend for TerminaBackend<T>
where T: Terminal,

Source§

type Error = Error

Error type associated with this Backend.
Source§

fn draw<'a, I>(&mut self, content: I) -> Result<()>
where I: Iterator<Item = (u16, u16, &'a Cell)>,

Draw the given content to the terminal screen. Read more
Source§

fn hide_cursor(&mut self) -> Result<()>

Hide the cursor on the terminal screen. Read more
Source§

fn show_cursor(&mut self) -> Result<()>

Show the cursor on the terminal screen. Read more
Source§

fn get_cursor_position(&mut self) -> Result<Position>

Get the current cursor position on the terminal screen. Read more
Source§

fn set_cursor_position<P: Into<Position>>(&mut self, position: P) -> Result<()>

Set the cursor position on the terminal screen to the given x and y coordinates. Read more
Source§

fn clear(&mut self) -> Result<()>

Clears all character cells in the terminal’s visible display area. Read more
Source§

fn clear_region(&mut self, clear_type: ClearType) -> Result<()>

Clears a specific region of the terminal’s visible display area, as defined by ClearType. Read more
Source§

fn append_lines(&mut self, n: u16) -> Result<()>

Insert n line breaks to the terminal screen. Read more
Source§

fn size(&self) -> Result<Size>

Get the size of the terminal screen in columns/rows as a Size. Read more
Source§

fn window_size(&mut self) -> Result<WindowSize>

Get the size of the terminal screen in columns/rows and pixels as a WindowSize. Read more
Source§

fn flush(&mut self) -> Result<()>

Flush any backend-buffered output to the terminal screen. Read more
Source§

fn scroll_region_up(&mut self, region: Range<u16>, amount: u16) -> Result<()>

Available on crate feature scrolling-regions only.
Scroll a region of the screen upwards, where a region is specified by a (half-open) range of rows. Read more
Source§

fn scroll_region_down(&mut self, region: Range<u16>, amount: u16) -> Result<()>

Available on crate feature scrolling-regions only.
Scroll a region of the screen downwards, where a region is specified by a (half-open) range of rows. Read more
Source§

fn get_cursor(&mut self) -> Result<(u16, u16), Self::Error>

👎Deprecated:

use get_cursor_position() instead which returns Result<Position>

Get the current cursor position on the terminal screen. Read more
Source§

fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), Self::Error>

👎Deprecated:

use set_cursor_position((x, y)) instead which takes impl Into<Position>

Set the cursor position on the terminal screen to the given x and y coordinates. Read more
Source§

impl<T> Debug for TerminaBackend<T>
where T: Terminal + Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Write for TerminaBackend<T>
where T: Terminal,

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

§

impl<T> Freeze for TerminaBackend<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for TerminaBackend<T>
where T: RefUnwindSafe,

§

impl<T> Send for TerminaBackend<T>
where T: Send,

§

impl<T> Sync for TerminaBackend<T>
where T: Sync,

§

impl<T> Unpin for TerminaBackend<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for TerminaBackend<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for TerminaBackend<T>
where T: UnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.