Skip to main content

EventBuilder

Struct EventBuilder 

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

Builder for constructing a sequence of input Events.

Chain calls to key, click, scroll_up, etc., then call build to get the final Vec<Event>.

§Example

use slt::EventBuilder;
use slt::KeyCode;

let events = EventBuilder::new()
    .key('a')
    .key_code(KeyCode::Enter)
    .build();
assert_eq!(events.len(), 2);

Implementations§

Source§

impl EventBuilder

Source

pub fn new() -> Self

Create an empty event builder.

Source

pub fn key(self, c: char) -> Self

Append a character key-press event.

Source

pub fn key_code(self, code: KeyCode) -> Self

Append a special key-press event (arrows, Enter, Esc, etc.).

Source

pub fn key_with(self, code: KeyCode, modifiers: KeyModifiers) -> Self

Append a key-press event with modifier keys (Ctrl, Shift, Alt).

Source

pub fn click(self, x: u32, y: u32) -> Self

Append a left mouse click at terminal position (x, y).

Source

pub fn scroll_up(self, x: u32, y: u32) -> Self

Append a scroll-up event at (x, y).

Source

pub fn scroll_down(self, x: u32, y: u32) -> Self

Append a scroll-down event at (x, y).

Source

pub fn paste(self, text: impl Into<String>) -> Self

Append a bracketed-paste event.

Source

pub fn resize(self, width: u32, height: u32) -> Self

Append a terminal resize event.

Source

pub fn build(self) -> Vec<Event>

Consume the builder and return the event sequence.

Trait Implementations§

Source§

impl Default for EventBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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