Skip to main content

Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

The main Flywheel engine.

This coordinates between the input and render actors, providing a simple interface for applications.

Implementations§

Source§

impl Engine

Source

pub fn new() -> Result<Self>

Create a new engine with default configuration.

§Errors

Returns an error if terminal setup fails (raw mode, alternate screen, etc.).

Source

pub fn with_config(config: EngineConfig) -> Result<Self>

Create a new engine with custom configuration.

§Errors

Returns an error if terminal setup fails.

Source

pub const fn width(&self) -> u16

Get the terminal width.

Source

pub const fn height(&self) -> u16

Get the terminal height.

Source

pub const fn buffer(&self) -> &Buffer

Get a reference to the buffer.

Source

pub const fn buffer_mut(&mut self) -> &mut Buffer

Get a mutable reference to the buffer.

Source

pub const fn input_receiver(&self) -> &Receiver<InputEvent>

Get the input receiver for event-driven loops.

Source

pub const fn is_running(&self) -> bool

Check if the engine is still running.

Source

pub const fn stop(&mut self)

Stop the engine.

Source

pub fn poll_input(&self) -> Option<InputEvent>

Poll for the next input event (non-blocking).

Returns None if no event is available.

Source

pub fn wait_input(&self, timeout: Duration) -> Option<InputEvent>

Wait for the next input event (blocking with timeout).

Source

pub fn drain_input(&self) -> Vec<InputEvent>

Drain all pending input events.

Source

pub fn request_redraw(&self)

Request a full redraw.

Source

pub fn request_update(&self)

Request a diff-based update.

Source

pub fn set_cursor(&self, x: Option<u16>, y: u16)

Set the cursor position (or hide it).

Source

pub fn write_raw(&self, bytes: Vec<u8>)

Write raw bytes to the output (Fast Path).

Source

pub fn handle_resize(&mut self, width: u16, height: u16)

Handle a resize event.

Source

pub fn begin_frame(&mut self)

Begin a new frame.

Call this at the start of your render loop.

Source

pub fn end_frame(&mut self)

End a frame and request update.

This will sleep if necessary to maintain the target FPS.

Source

pub const fn frame_count(&self) -> u64

Get the current frame count.

Source

pub fn set_cell(&mut self, x: u16, y: u16, cell: Cell)

Convenience: Set a cell in the buffer.

Source

pub fn set_grapheme( &mut self, x: u16, y: u16, grapheme: &str, fg: Rgb, bg: Rgb, ) -> u8

Convenience: Set a grapheme in the buffer.

Source

pub fn clear(&mut self)

Convenience: Clear the buffer.

Source

pub fn fill_rect(&mut self, rect: Rect, cell: Cell)

Convenience: Fill a rectangle.

Source

pub fn draw_text(&mut self, x: u16, y: u16, text: &str, fg: Rgb, bg: Rgb) -> u16

Draw text at a position.

Returns the number of columns used.

Trait Implementations§

Source§

impl Drop for Engine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Engine

§

impl !RefUnwindSafe for Engine

§

impl Send for Engine

§

impl Sync for Engine

§

impl Unpin for Engine

§

impl !UnwindSafe for Engine

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 = 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.