Trait WebRenderer

Source
pub trait WebRenderer {
    // Required method
    fn draw_web<F>(self, render_callback: F)
       where F: FnMut(&mut Frame<'_>) + 'static;

    // Provided methods
    fn on_key_event<F>(&self, callback: F)
       where F: FnMut(KeyEvent) + 'static { ... }
    fn request_animation_frame(f: &Closure<dyn FnMut()>) { ... }
}
Expand description

Trait for rendering on the web.

It provides all the necessary methods to render the terminal on the web and also interact with the browser such as handling key events.

Required Methods§

Source

fn draw_web<F>(self, render_callback: F)
where F: FnMut(&mut Frame<'_>) + 'static,

Renders the terminal on the web.

This method takes a closure that will be called on every update that the browser makes during requestAnimationFrame calls.

TODO: Clarify and validate this.

Provided Methods§

Source

fn on_key_event<F>(&self, callback: F)
where F: FnMut(KeyEvent) + 'static,

Handles key events.

This method takes a closure that will be called on every keydown event.

Source

fn request_animation_frame(f: &Closure<dyn FnMut()>)

Requests an animation frame.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> WebRenderer for Terminal<T>
where T: Backend + 'static,

Implement WebRenderer for Ratatui’s Terminal.

This implementation creates a loop that calls the Terminal::draw method.

Source§

fn draw_web<F>(self, render_callback: F)
where F: FnMut(&mut Frame<'_>) + 'static,

Implementors§