Pancake

Struct Pancake 

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

Central data structure.

Implementations§

Source§

impl Pancake

Source

pub fn render_panel(&self, panel: &Panel)

Renders a panel to the terminal buffer.

Examples found in repository?
examples/getting_started.rs (line 35)
7fn main() {
8    // cook pancake and init colors
9    let pancake = FryingPan::default()
10        .hide_cursor(true)
11        .no_delay(true)
12        .color(true)
13        .build()
14        .unwrap();
15    init_pair(BLUE_WHITE, COLOR_BLUE, COLOR_WHITE);
16
17    // make panel,                   position v   v size
18    let mut panel = Panel::new(Point::from(1, 1), 10, 30);
19    panel.draw_box();
20
21    // printing does not move the cursor
22    panel.mv_print(Point::from(1, 0), "╴pancakes╶");
23    panel.mv_print(Point::from(1, 1), "hello");
24
25    // the cursor will be within bounds, unwrap is fine
26    panel.attr_on(A_ITALIC).unwrap();
27    panel.attr_on(color_pair(BLUE_WHITE)).unwrap();
28
29    loop {
30        if let Some(Input::Character('q')) = pancake.get_char() {
31            break;
32        }
33
34        pancake.erase();
35        pancake.render_panel(&panel);
36        pancake.refresh();
37
38        sleep(SLEEP_TIME);
39    }
40
41    pancake.quit();
42}
Source

pub fn get_char(&self) -> Option<Input>

Read a single character from the terminal. In no_delay mode and if no key is pressed, returns None.

Examples found in repository?
examples/getting_started.rs (line 30)
7fn main() {
8    // cook pancake and init colors
9    let pancake = FryingPan::default()
10        .hide_cursor(true)
11        .no_delay(true)
12        .color(true)
13        .build()
14        .unwrap();
15    init_pair(BLUE_WHITE, COLOR_BLUE, COLOR_WHITE);
16
17    // make panel,                   position v   v size
18    let mut panel = Panel::new(Point::from(1, 1), 10, 30);
19    panel.draw_box();
20
21    // printing does not move the cursor
22    panel.mv_print(Point::from(1, 0), "╴pancakes╶");
23    panel.mv_print(Point::from(1, 1), "hello");
24
25    // the cursor will be within bounds, unwrap is fine
26    panel.attr_on(A_ITALIC).unwrap();
27    panel.attr_on(color_pair(BLUE_WHITE)).unwrap();
28
29    loop {
30        if let Some(Input::Character('q')) = pancake.get_char() {
31            break;
32        }
33
34        pancake.erase();
35        pancake.render_panel(&panel);
36        pancake.refresh();
37
38        sleep(SLEEP_TIME);
39    }
40
41    pancake.quit();
42}
Source

pub fn erase(&self)

Erase the terminal buffer. Call before rendering.

Examples found in repository?
examples/getting_started.rs (line 34)
7fn main() {
8    // cook pancake and init colors
9    let pancake = FryingPan::default()
10        .hide_cursor(true)
11        .no_delay(true)
12        .color(true)
13        .build()
14        .unwrap();
15    init_pair(BLUE_WHITE, COLOR_BLUE, COLOR_WHITE);
16
17    // make panel,                   position v   v size
18    let mut panel = Panel::new(Point::from(1, 1), 10, 30);
19    panel.draw_box();
20
21    // printing does not move the cursor
22    panel.mv_print(Point::from(1, 0), "╴pancakes╶");
23    panel.mv_print(Point::from(1, 1), "hello");
24
25    // the cursor will be within bounds, unwrap is fine
26    panel.attr_on(A_ITALIC).unwrap();
27    panel.attr_on(color_pair(BLUE_WHITE)).unwrap();
28
29    loop {
30        if let Some(Input::Character('q')) = pancake.get_char() {
31            break;
32        }
33
34        pancake.erase();
35        pancake.render_panel(&panel);
36        pancake.refresh();
37
38        sleep(SLEEP_TIME);
39    }
40
41    pancake.quit();
42}
Source

pub fn refresh(&self)

Copy the terminal buffer to the terminal. Call after rendering.

Examples found in repository?
examples/getting_started.rs (line 36)
7fn main() {
8    // cook pancake and init colors
9    let pancake = FryingPan::default()
10        .hide_cursor(true)
11        .no_delay(true)
12        .color(true)
13        .build()
14        .unwrap();
15    init_pair(BLUE_WHITE, COLOR_BLUE, COLOR_WHITE);
16
17    // make panel,                   position v   v size
18    let mut panel = Panel::new(Point::from(1, 1), 10, 30);
19    panel.draw_box();
20
21    // printing does not move the cursor
22    panel.mv_print(Point::from(1, 0), "╴pancakes╶");
23    panel.mv_print(Point::from(1, 1), "hello");
24
25    // the cursor will be within bounds, unwrap is fine
26    panel.attr_on(A_ITALIC).unwrap();
27    panel.attr_on(color_pair(BLUE_WHITE)).unwrap();
28
29    loop {
30        if let Some(Input::Character('q')) = pancake.get_char() {
31            break;
32        }
33
34        pancake.erase();
35        pancake.render_panel(&panel);
36        pancake.refresh();
37
38        sleep(SLEEP_TIME);
39    }
40
41    pancake.quit();
42}
Source

pub fn quit(&self)

Gracefully shutdown and return terminal to default state.

Examples found in repository?
examples/getting_started.rs (line 41)
7fn main() {
8    // cook pancake and init colors
9    let pancake = FryingPan::default()
10        .hide_cursor(true)
11        .no_delay(true)
12        .color(true)
13        .build()
14        .unwrap();
15    init_pair(BLUE_WHITE, COLOR_BLUE, COLOR_WHITE);
16
17    // make panel,                   position v   v size
18    let mut panel = Panel::new(Point::from(1, 1), 10, 30);
19    panel.draw_box();
20
21    // printing does not move the cursor
22    panel.mv_print(Point::from(1, 0), "╴pancakes╶");
23    panel.mv_print(Point::from(1, 1), "hello");
24
25    // the cursor will be within bounds, unwrap is fine
26    panel.attr_on(A_ITALIC).unwrap();
27    panel.attr_on(color_pair(BLUE_WHITE)).unwrap();
28
29    loop {
30        if let Some(Input::Character('q')) = pancake.get_char() {
31            break;
32        }
33
34        pancake.erase();
35        pancake.render_panel(&panel);
36        pancake.refresh();
37
38        sleep(SLEEP_TIME);
39    }
40
41    pancake.quit();
42}

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.