Struct Chaos

Source
pub struct Chaos<'a> { /* private fields */ }
Expand description

The primary struct of chaos-engine.

This struct must be instantiated once to start using chaos-engine and its features.

§Examples

use chaos_engine::{Chaos, ChaosOptions};

let stdout = std::io::stdout();
let options = ChaosOptions::default();

let mut chaos = Chaos::new(stdout, options);

Implementations§

Source§

impl<'a> Chaos<'a>

Source

pub fn new(stdout: Stdout, options: ChaosOptions<'a>) -> Self

Instantiate the chaos engine with specified options.

It enables raw mode where input must be handled manually.

Source

pub fn clear_terminal(&mut self)

Completely clears the terminal screen of any visible text.

§Panics

Panics in the case of a terminal error.

Source

pub fn get_input(&mut self, page: &mut Page) -> Result<String, Error>

Gets input from the user.

It takes a page to resize in the event of a terminal resize, then writes the input prompt on the last line of the terminal, overwriting anything on that line.

§Examples
use chaos_engine::{Chaos, ChaosOptions, Page};

let mut page = Page::new();
let mut chaos = Chaos::new(std::io::stdout(), ChaosOptions::default());

loop {
    chaos.clear_terminal();
    chaos.print(&mut page);

    let input = chaos.get_input(&mut page).unwrap();
    if input == "exit" {
        chaos.alternate_screen(false);
        break;
    }

    // do stuff here
}
§Panics

This can panic when it fails to read the terminal events.

Source

pub fn move_cursor(&mut self, x: u16, y: u16)

Moves the cursor to the specified X and Y positions.

§Panics

Panics in the case of a terminal error.

Source

pub fn alternate_screen(&mut self, on: bool)

Enables and disables the terminal’s alternate screen.

An alternate screen is a separate buffer. On entering an alternate screen, the terminal gets completely cleared to allow for program output, and once the screen is disabled, the original buffer is restored.

§Panics

Panics in the case of a terminal error.

Source

pub fn print(&mut self, page: &mut Page)

Prints the given Page onto the screen, respecting the paddings and word wrapping.

Calls Page::align() on the given Page to apply the word wrapping before printing it to the output.

Source

pub fn position(&self) -> &Vector2<u16>

Returns the last stored position of the cursor.

Source

pub fn dimensions(&self) -> &Vector2<u16>

Returns the last stored dimensions of the terminal.

Source

pub fn paddings(&self) -> &ChaosPaddings

Returns the current paddings.

Source

pub fn update_paddings( &mut self, padding: PaddingType, new_padding: Vector2<u16>, )

Updates the paddings to new values. Any active page must be printed again to take effect.

Auto Trait Implementations§

§

impl<'a> Freeze for Chaos<'a>

§

impl<'a> RefUnwindSafe for Chaos<'a>

§

impl<'a> Send for Chaos<'a>

§

impl<'a> Sync for Chaos<'a>

§

impl<'a> Unpin for Chaos<'a>

§

impl<'a> UnwindSafe for Chaos<'a>

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.