Struct EasyCurses

Source
pub struct EasyCurses {
    pub win: Window,
    pub auto_resize: bool,
    /* private fields */
}
Expand description

This is a handle to all your fun curses functionality.

EasyCurses will automatically restore the terminal when you drop it, so you don’t need to worry about any manual cleanup. Automatic cleanup will happen even if your program panics and unwinds, but it will not happen if your program panics and aborts (obviously). So, don’t abort the program while curses is active, or your terminal session will just be ruined.

Except in the case of is_color_terminal, all EasyCurses methods that return a Option<()> use it to indicate if the requested operation was successful or not. Unfortunately, the curses library doesn’t provide any more info than that, so a Option<()> is all you get.

Fields§

§win: Window

This is the inner pancurses Window that the EasyCurses type wraps over.

This is only intended to be used as a last resort, if you really want to call something that’s not here. Under normal circumstances you shouldn’t need to touch this field at all. It’s not “unsafe” to use in the rust/memory sense, but if you access this field and then cause a bug in EasyCurses, well that’s your own fault.

§auto_resize: bool

Determines if the window will automatically resize itself when KeyResize comes in through the input channel. Defaults to true. If you disable this and then don’t call resize yourself then KeyResize comes in you’ll have a bad time.

Implementations§

Source§

impl EasyCurses

Source

pub fn initialize_system() -> Option<Self>

Initializes the curses system so that you can begin using curses.

The name is long to remind you of the seriousness of attempting to turn on curses: If the C layer encounters an error while trying to initialize the user’s terminal into curses mode it will “helpfully” print an error message and exit the process on its own. There’s no way to prevent this from happening at the Rust level.

If the terminal supports colors, they are automatically activated and ColorPair values are initialized for all color foreground and background combinations.

§Errors

Curses must not be double-initialized. This is tracked by easycurses with an AtomicBool being flipped on and off. If it is on when you call this method you get None back instead.

Examples found in repository?
examples/hello.rs (line 14)
12fn main() {
13  // Initialize the system
14  let mut easy = EasyCurses::initialize_system().unwrap();
15
16  // don't show the cursor
17  easy.set_cursor_visibility(CursorVisibility::Invisible);
18
19  // don't echo the user's input
20  easy.set_echo(false);
21
22  // we'll print this in green text.
23  easy.set_color_pair(colorpair!(Green on Black));
24
25  // Print this string from the current position. The default cursor position
26  // is rc(0,0)
27  easy.print("Hello world.");
28
29  // Ensure that the user has the latest view of things.
30  easy.refresh();
31
32  // Get one input from the user. This is just so that they have a chance to
33  // see the message and press a key, otherwise the program would end faster
34  // than they could read it.
35  easy.get_input();
36}
More examples
Hide additional examples
examples/bounds.rs (line 10)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
examples/acs.rs (line 10)
9fn main() {
10    let mut easy = EasyCurses::initialize_system().unwrap();
11
12    easy.set_echo(false);
13
14    easy.set_color_pair(colorpair!(Green on Black));
15
16    easy.move_rc(0, 0);
17
18    easy.insert_char(acs::llcorner());
19    easy.insert_char(acs::lrcorner());
20    easy.insert_char(acs::ulcorner());
21    easy.insert_char(acs::urcorner());
22    easy.insert_char(acs::btee());
23    easy.insert_char(acs::hline());
24    easy.insert_char(acs::ltee());
25    easy.insert_char(acs::plus());
26    easy.insert_char(acs::rtee());
27    easy.insert_char(acs::ttee());
28    easy.insert_char(acs::vline());
29    easy.insert_char(acs::s1());
30    easy.insert_char(acs::s9());
31
32    easy.move_rc(1, 0);
33
34    easy.insert_char(acs::bullet());
35    easy.insert_char(acs::ckboard());
36    easy.insert_char(acs::degree());
37    easy.insert_char(acs::diamond());
38    easy.insert_char(acs::plminus());
39    easy.insert_char(acs::block());
40    easy.insert_char(acs::board());
41    easy.insert_char(acs::darrow());
42    easy.insert_char(acs::lantern());
43    easy.insert_char(acs::larrow());
44    easy.insert_char(acs::rarrow());
45    easy.insert_char(acs::uarrow());
46    easy.insert_char(acs::s3());
47
48    easy.move_rc(2, 0);
49
50    easy.insert_char(acs::s7());
51    easy.insert_char(acs::gequal());
52    easy.insert_char(acs::lequal());
53    easy.insert_char(acs::nequal());
54    easy.insert_char(acs::pi());
55    easy.insert_char(acs::sterling());
56    easy.insert_char(acs::bbss());
57    easy.insert_char(acs::bssb());
58    easy.insert_char(acs::sbbs());
59    easy.insert_char(acs::sbss());
60    easy.insert_char(acs::ssbb());
61    easy.insert_char(acs::ssbs());
62    easy.insert_char(acs::sssb());
63    easy.insert_char(acs::bsbs());
64    easy.insert_char(acs::bsss());
65    easy.insert_char(acs::sbsb());
66    easy.insert_char(acs::ssss());
67
68    easy.refresh();
69
70    easy.get_input();
71}
examples/60fps.rs (line 12)
10fn main() {
11  // Normal setup
12  let mut easy = EasyCurses::initialize_system().unwrap();
13  easy.set_cursor_visibility(CursorVisibility::Invisible);
14  easy.set_echo(false);
15  easy.set_keypad_enabled(true);
16  easy.set_input_mode(InputMode::Character);
17  easy.set_input_timeout(TimeoutMode::Immediate);
18  easy.set_scrolling(true);
19
20  // We need to know how wide our screen is.
21  let (_, mut col_count) = easy.get_row_col_count();
22
23  // Sadly we can't make this const since it has to unwrap and all that, but
24  // ideally this could be a const. You could use lazy_static I guess if you
25  // really cared, but it's not a huge deal.
26  let frame_target_duration = Duration::new(1, 0).checked_div(60).expect("failed when rhs!=0, what?");
27
28  // We start at an arbitrary position.
29  let mut position = 5;
30  loop {
31    let top_of_loop = Instant::now();
32    // Gather/process any pending input
33    while let Some(input) = easy.get_input() {
34      match input {
35        Input::KeyLeft => position = max(0, position - 1),
36        Input::KeyRight => position = min(col_count - 1, position + 1),
37        Input::KeyResize => {
38          col_count = easy.get_row_col_count().1;
39          position = min(col_count - 1, position);
40        }
41        other => println!("Unknown: {:?}", other),
42      }
43    }
44    // Compute what we'll display.
45    let output = repeat('#').take(position as usize).collect::<String>();
46
47    // Sleep a bit if we need to. This actually sleeps a little longer than
48    // just the right time because it doesn't account for the display time
49    // we'll use up after the sleep happens. However, curses doesn't really
50    // demand perfect animation anyway.
51    let elapsed_this_frame = top_of_loop.elapsed();
52    if let Some(frame_remaining) = frame_target_duration.checked_sub(elapsed_this_frame) {
53      sleep(frame_remaining);
54    }
55
56    // Display
57    easy.print("\n");
58    easy.print(&output);
59    easy.refresh();
60  }
61}
Source

pub fn set_title_win32(&mut self, title: &str)

On Win32 systems this allows you to set the title of the PDcurses window. On other systems this does nothing at all.

Source

pub fn set_cursor_visibility( &mut self, vis: CursorVisibility, ) -> Option<CursorVisibility>

Attempts to assign a new cursor visibility. If this is successful you get a Some back with the old setting inside. If this fails you get a None back. For more info see curs_set

Examples found in repository?
examples/hello.rs (line 17)
12fn main() {
13  // Initialize the system
14  let mut easy = EasyCurses::initialize_system().unwrap();
15
16  // don't show the cursor
17  easy.set_cursor_visibility(CursorVisibility::Invisible);
18
19  // don't echo the user's input
20  easy.set_echo(false);
21
22  // we'll print this in green text.
23  easy.set_color_pair(colorpair!(Green on Black));
24
25  // Print this string from the current position. The default cursor position
26  // is rc(0,0)
27  easy.print("Hello world.");
28
29  // Ensure that the user has the latest view of things.
30  easy.refresh();
31
32  // Get one input from the user. This is just so that they have a chance to
33  // see the message and press a key, otherwise the program would end faster
34  // than they could read it.
35  easy.get_input();
36}
More examples
Hide additional examples
examples/preserve_panic_message.rs (line 11)
6fn main() {
7    // We wrap all our use of curses with this function.
8    preserve_panic_message(|easy| {
9        // In here we get an initialized EasyCurses handle and then proceed to
10        // use it exactly like we normally would use it.
11        easy.set_cursor_visibility(CursorVisibility::Invisible);
12        easy.set_echo(false);
13        easy.print("Hello world.");
14        easy.refresh();
15        easy.get_input();
16        panic!("oh no");
17    }).unwrap_or_else(|e| match e {
18        // This block only runs if there was an error. We might or might not
19        // have been able to recover an error message. You technically can pass
20        // any value into a panic, but we only get an error message if the panic
21        // value was a `String` or `&str`.
22        Some(errmsg) => println!("Error Occurred: {}", errmsg),
23        None => println!("There was an error, but no error message."),
24    });
25}
examples/bounds.rs (line 11)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
examples/60fps.rs (line 13)
10fn main() {
11  // Normal setup
12  let mut easy = EasyCurses::initialize_system().unwrap();
13  easy.set_cursor_visibility(CursorVisibility::Invisible);
14  easy.set_echo(false);
15  easy.set_keypad_enabled(true);
16  easy.set_input_mode(InputMode::Character);
17  easy.set_input_timeout(TimeoutMode::Immediate);
18  easy.set_scrolling(true);
19
20  // We need to know how wide our screen is.
21  let (_, mut col_count) = easy.get_row_col_count();
22
23  // Sadly we can't make this const since it has to unwrap and all that, but
24  // ideally this could be a const. You could use lazy_static I guess if you
25  // really cared, but it's not a huge deal.
26  let frame_target_duration = Duration::new(1, 0).checked_div(60).expect("failed when rhs!=0, what?");
27
28  // We start at an arbitrary position.
29  let mut position = 5;
30  loop {
31    let top_of_loop = Instant::now();
32    // Gather/process any pending input
33    while let Some(input) = easy.get_input() {
34      match input {
35        Input::KeyLeft => position = max(0, position - 1),
36        Input::KeyRight => position = min(col_count - 1, position + 1),
37        Input::KeyResize => {
38          col_count = easy.get_row_col_count().1;
39          position = min(col_count - 1, position);
40        }
41        other => println!("Unknown: {:?}", other),
42      }
43    }
44    // Compute what we'll display.
45    let output = repeat('#').take(position as usize).collect::<String>();
46
47    // Sleep a bit if we need to. This actually sleeps a little longer than
48    // just the right time because it doesn't account for the display time
49    // we'll use up after the sleep happens. However, curses doesn't really
50    // demand perfect animation anyway.
51    let elapsed_this_frame = top_of_loop.elapsed();
52    if let Some(frame_remaining) = frame_target_duration.checked_sub(elapsed_this_frame) {
53      sleep(frame_remaining);
54    }
55
56    // Display
57    easy.print("\n");
58    easy.print(&output);
59    easy.refresh();
60  }
61}
Source

pub fn set_input_mode(&mut self, mode: InputMode) -> Option<()>

The terminal gets input from the user. Then it’s sometimes buffered up. At some point it’s passed into the program’s input buffer, and then get_input gets things out of that buffer.

  • Character: Input is passed in 1 character at a time, but special characters (such as Ctrl+C and Ctrl+S) are automatically processed for you by the terminal.
  • Cooked: Input is passed in 1 line at a time, with the special character processing mentioned above enabled.
  • RawCharacter: Input is passed in 1 character at a time, and special character sequences are not processed automatically.
  • RawCooked: Input is passed in 1 line at a time, and special character sequences are not processed automatically.

The default mode is inherited from the terminal that started the program (usually Cooked), so you should always set the desired mode explicitly at the start of your program.

See also the Input Mode section of the curses documentation.

Examples found in repository?
examples/60fps.rs (line 16)
10fn main() {
11  // Normal setup
12  let mut easy = EasyCurses::initialize_system().unwrap();
13  easy.set_cursor_visibility(CursorVisibility::Invisible);
14  easy.set_echo(false);
15  easy.set_keypad_enabled(true);
16  easy.set_input_mode(InputMode::Character);
17  easy.set_input_timeout(TimeoutMode::Immediate);
18  easy.set_scrolling(true);
19
20  // We need to know how wide our screen is.
21  let (_, mut col_count) = easy.get_row_col_count();
22
23  // Sadly we can't make this const since it has to unwrap and all that, but
24  // ideally this could be a const. You could use lazy_static I guess if you
25  // really cared, but it's not a huge deal.
26  let frame_target_duration = Duration::new(1, 0).checked_div(60).expect("failed when rhs!=0, what?");
27
28  // We start at an arbitrary position.
29  let mut position = 5;
30  loop {
31    let top_of_loop = Instant::now();
32    // Gather/process any pending input
33    while let Some(input) = easy.get_input() {
34      match input {
35        Input::KeyLeft => position = max(0, position - 1),
36        Input::KeyRight => position = min(col_count - 1, position + 1),
37        Input::KeyResize => {
38          col_count = easy.get_row_col_count().1;
39          position = min(col_count - 1, position);
40        }
41        other => println!("Unknown: {:?}", other),
42      }
43    }
44    // Compute what we'll display.
45    let output = repeat('#').take(position as usize).collect::<String>();
46
47    // Sleep a bit if we need to. This actually sleeps a little longer than
48    // just the right time because it doesn't account for the display time
49    // we'll use up after the sleep happens. However, curses doesn't really
50    // demand perfect animation anyway.
51    let elapsed_this_frame = top_of_loop.elapsed();
52    if let Some(frame_remaining) = frame_target_duration.checked_sub(elapsed_this_frame) {
53      sleep(frame_remaining);
54    }
55
56    // Display
57    easy.print("\n");
58    easy.print(&output);
59    easy.refresh();
60  }
61}
Source

pub fn set_input_timeout(&mut self, mode: TimeoutMode)

This controls how long get_input will wait before returning a None value.

The default mode is an unlimited wait.

The WaitUpTo value is measured in milliseconds, and any negative value is treated as 0 (the same as an immediate timeout).

See also: The notimeout curses function.

Examples found in repository?
examples/60fps.rs (line 17)
10fn main() {
11  // Normal setup
12  let mut easy = EasyCurses::initialize_system().unwrap();
13  easy.set_cursor_visibility(CursorVisibility::Invisible);
14  easy.set_echo(false);
15  easy.set_keypad_enabled(true);
16  easy.set_input_mode(InputMode::Character);
17  easy.set_input_timeout(TimeoutMode::Immediate);
18  easy.set_scrolling(true);
19
20  // We need to know how wide our screen is.
21  let (_, mut col_count) = easy.get_row_col_count();
22
23  // Sadly we can't make this const since it has to unwrap and all that, but
24  // ideally this could be a const. You could use lazy_static I guess if you
25  // really cared, but it's not a huge deal.
26  let frame_target_duration = Duration::new(1, 0).checked_div(60).expect("failed when rhs!=0, what?");
27
28  // We start at an arbitrary position.
29  let mut position = 5;
30  loop {
31    let top_of_loop = Instant::now();
32    // Gather/process any pending input
33    while let Some(input) = easy.get_input() {
34      match input {
35        Input::KeyLeft => position = max(0, position - 1),
36        Input::KeyRight => position = min(col_count - 1, position + 1),
37        Input::KeyResize => {
38          col_count = easy.get_row_col_count().1;
39          position = min(col_count - 1, position);
40        }
41        other => println!("Unknown: {:?}", other),
42      }
43    }
44    // Compute what we'll display.
45    let output = repeat('#').take(position as usize).collect::<String>();
46
47    // Sleep a bit if we need to. This actually sleeps a little longer than
48    // just the right time because it doesn't account for the display time
49    // we'll use up after the sleep happens. However, curses doesn't really
50    // demand perfect animation anyway.
51    let elapsed_this_frame = top_of_loop.elapsed();
52    if let Some(frame_remaining) = frame_target_duration.checked_sub(elapsed_this_frame) {
53      sleep(frame_remaining);
54    }
55
56    // Display
57    easy.print("\n");
58    easy.print(&output);
59    easy.refresh();
60  }
61}
Source

pub fn set_keypad_enabled(&mut self, use_keypad: bool) -> Option<()>

Enables special key processing from buttons such as the keypad and arrow keys. This defaults to false. You probably want to set it to true. If it’s not on and the user presses a special key then get_key will return will do nothing or give ERR.

Examples found in repository?
examples/bounds.rs (line 13)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
More examples
Hide additional examples
examples/60fps.rs (line 15)
10fn main() {
11  // Normal setup
12  let mut easy = EasyCurses::initialize_system().unwrap();
13  easy.set_cursor_visibility(CursorVisibility::Invisible);
14  easy.set_echo(false);
15  easy.set_keypad_enabled(true);
16  easy.set_input_mode(InputMode::Character);
17  easy.set_input_timeout(TimeoutMode::Immediate);
18  easy.set_scrolling(true);
19
20  // We need to know how wide our screen is.
21  let (_, mut col_count) = easy.get_row_col_count();
22
23  // Sadly we can't make this const since it has to unwrap and all that, but
24  // ideally this could be a const. You could use lazy_static I guess if you
25  // really cared, but it's not a huge deal.
26  let frame_target_duration = Duration::new(1, 0).checked_div(60).expect("failed when rhs!=0, what?");
27
28  // We start at an arbitrary position.
29  let mut position = 5;
30  loop {
31    let top_of_loop = Instant::now();
32    // Gather/process any pending input
33    while let Some(input) = easy.get_input() {
34      match input {
35        Input::KeyLeft => position = max(0, position - 1),
36        Input::KeyRight => position = min(col_count - 1, position + 1),
37        Input::KeyResize => {
38          col_count = easy.get_row_col_count().1;
39          position = min(col_count - 1, position);
40        }
41        other => println!("Unknown: {:?}", other),
42      }
43    }
44    // Compute what we'll display.
45    let output = repeat('#').take(position as usize).collect::<String>();
46
47    // Sleep a bit if we need to. This actually sleeps a little longer than
48    // just the right time because it doesn't account for the display time
49    // we'll use up after the sleep happens. However, curses doesn't really
50    // demand perfect animation anyway.
51    let elapsed_this_frame = top_of_loop.elapsed();
52    if let Some(frame_remaining) = frame_target_duration.checked_sub(elapsed_this_frame) {
53      sleep(frame_remaining);
54    }
55
56    // Display
57    easy.print("\n");
58    easy.print(&output);
59    easy.refresh();
60  }
61}
Source

pub fn set_echo(&mut self, echoing: bool) -> Option<()>

Enables or disables the automatic echoing of input into the window as the user types. Default to on, but you probably want it to be off most of the time.

Examples found in repository?
examples/hello.rs (line 20)
12fn main() {
13  // Initialize the system
14  let mut easy = EasyCurses::initialize_system().unwrap();
15
16  // don't show the cursor
17  easy.set_cursor_visibility(CursorVisibility::Invisible);
18
19  // don't echo the user's input
20  easy.set_echo(false);
21
22  // we'll print this in green text.
23  easy.set_color_pair(colorpair!(Green on Black));
24
25  // Print this string from the current position. The default cursor position
26  // is rc(0,0)
27  easy.print("Hello world.");
28
29  // Ensure that the user has the latest view of things.
30  easy.refresh();
31
32  // Get one input from the user. This is just so that they have a chance to
33  // see the message and press a key, otherwise the program would end faster
34  // than they could read it.
35  easy.get_input();
36}
More examples
Hide additional examples
examples/preserve_panic_message.rs (line 12)
6fn main() {
7    // We wrap all our use of curses with this function.
8    preserve_panic_message(|easy| {
9        // In here we get an initialized EasyCurses handle and then proceed to
10        // use it exactly like we normally would use it.
11        easy.set_cursor_visibility(CursorVisibility::Invisible);
12        easy.set_echo(false);
13        easy.print("Hello world.");
14        easy.refresh();
15        easy.get_input();
16        panic!("oh no");
17    }).unwrap_or_else(|e| match e {
18        // This block only runs if there was an error. We might or might not
19        // have been able to recover an error message. You technically can pass
20        // any value into a panic, but we only get an error message if the panic
21        // value was a `String` or `&str`.
22        Some(errmsg) => println!("Error Occurred: {}", errmsg),
23        None => println!("There was an error, but no error message."),
24    });
25}
examples/bounds.rs (line 12)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
examples/acs.rs (line 12)
9fn main() {
10    let mut easy = EasyCurses::initialize_system().unwrap();
11
12    easy.set_echo(false);
13
14    easy.set_color_pair(colorpair!(Green on Black));
15
16    easy.move_rc(0, 0);
17
18    easy.insert_char(acs::llcorner());
19    easy.insert_char(acs::lrcorner());
20    easy.insert_char(acs::ulcorner());
21    easy.insert_char(acs::urcorner());
22    easy.insert_char(acs::btee());
23    easy.insert_char(acs::hline());
24    easy.insert_char(acs::ltee());
25    easy.insert_char(acs::plus());
26    easy.insert_char(acs::rtee());
27    easy.insert_char(acs::ttee());
28    easy.insert_char(acs::vline());
29    easy.insert_char(acs::s1());
30    easy.insert_char(acs::s9());
31
32    easy.move_rc(1, 0);
33
34    easy.insert_char(acs::bullet());
35    easy.insert_char(acs::ckboard());
36    easy.insert_char(acs::degree());
37    easy.insert_char(acs::diamond());
38    easy.insert_char(acs::plminus());
39    easy.insert_char(acs::block());
40    easy.insert_char(acs::board());
41    easy.insert_char(acs::darrow());
42    easy.insert_char(acs::lantern());
43    easy.insert_char(acs::larrow());
44    easy.insert_char(acs::rarrow());
45    easy.insert_char(acs::uarrow());
46    easy.insert_char(acs::s3());
47
48    easy.move_rc(2, 0);
49
50    easy.insert_char(acs::s7());
51    easy.insert_char(acs::gequal());
52    easy.insert_char(acs::lequal());
53    easy.insert_char(acs::nequal());
54    easy.insert_char(acs::pi());
55    easy.insert_char(acs::sterling());
56    easy.insert_char(acs::bbss());
57    easy.insert_char(acs::bssb());
58    easy.insert_char(acs::sbbs());
59    easy.insert_char(acs::sbss());
60    easy.insert_char(acs::ssbb());
61    easy.insert_char(acs::ssbs());
62    easy.insert_char(acs::sssb());
63    easy.insert_char(acs::bsbs());
64    easy.insert_char(acs::bsss());
65    easy.insert_char(acs::sbsb());
66    easy.insert_char(acs::ssss());
67
68    easy.refresh();
69
70    easy.get_input();
71}
examples/60fps.rs (line 14)
10fn main() {
11  // Normal setup
12  let mut easy = EasyCurses::initialize_system().unwrap();
13  easy.set_cursor_visibility(CursorVisibility::Invisible);
14  easy.set_echo(false);
15  easy.set_keypad_enabled(true);
16  easy.set_input_mode(InputMode::Character);
17  easy.set_input_timeout(TimeoutMode::Immediate);
18  easy.set_scrolling(true);
19
20  // We need to know how wide our screen is.
21  let (_, mut col_count) = easy.get_row_col_count();
22
23  // Sadly we can't make this const since it has to unwrap and all that, but
24  // ideally this could be a const. You could use lazy_static I guess if you
25  // really cared, but it's not a huge deal.
26  let frame_target_duration = Duration::new(1, 0).checked_div(60).expect("failed when rhs!=0, what?");
27
28  // We start at an arbitrary position.
29  let mut position = 5;
30  loop {
31    let top_of_loop = Instant::now();
32    // Gather/process any pending input
33    while let Some(input) = easy.get_input() {
34      match input {
35        Input::KeyLeft => position = max(0, position - 1),
36        Input::KeyRight => position = min(col_count - 1, position + 1),
37        Input::KeyResize => {
38          col_count = easy.get_row_col_count().1;
39          position = min(col_count - 1, position);
40        }
41        other => println!("Unknown: {:?}", other),
42      }
43    }
44    // Compute what we'll display.
45    let output = repeat('#').take(position as usize).collect::<String>();
46
47    // Sleep a bit if we need to. This actually sleeps a little longer than
48    // just the right time because it doesn't account for the display time
49    // we'll use up after the sleep happens. However, curses doesn't really
50    // demand perfect animation anyway.
51    let elapsed_this_frame = top_of_loop.elapsed();
52    if let Some(frame_remaining) = frame_target_duration.checked_sub(elapsed_this_frame) {
53      sleep(frame_remaining);
54    }
55
56    // Display
57    easy.print("\n");
58    easy.print(&output);
59    easy.refresh();
60  }
61}
Source

pub fn is_color_terminal(&self) -> bool

Checks if the current terminal supports the use of colors.

Source

pub fn set_color_pair(&mut self, pair: ColorPair)

Sets the current color pair of the window. Output at any location will use this pair until a new pair is set. Does nothing if the terminal does not support colors in the first place.

Examples found in repository?
examples/hello.rs (line 23)
12fn main() {
13  // Initialize the system
14  let mut easy = EasyCurses::initialize_system().unwrap();
15
16  // don't show the cursor
17  easy.set_cursor_visibility(CursorVisibility::Invisible);
18
19  // don't echo the user's input
20  easy.set_echo(false);
21
22  // we'll print this in green text.
23  easy.set_color_pair(colorpair!(Green on Black));
24
25  // Print this string from the current position. The default cursor position
26  // is rc(0,0)
27  easy.print("Hello world.");
28
29  // Ensure that the user has the latest view of things.
30  easy.refresh();
31
32  // Get one input from the user. This is just so that they have a chance to
33  // see the message and press a key, otherwise the program would end faster
34  // than they could read it.
35  easy.get_input();
36}
More examples
Hide additional examples
examples/acs.rs (line 14)
9fn main() {
10    let mut easy = EasyCurses::initialize_system().unwrap();
11
12    easy.set_echo(false);
13
14    easy.set_color_pair(colorpair!(Green on Black));
15
16    easy.move_rc(0, 0);
17
18    easy.insert_char(acs::llcorner());
19    easy.insert_char(acs::lrcorner());
20    easy.insert_char(acs::ulcorner());
21    easy.insert_char(acs::urcorner());
22    easy.insert_char(acs::btee());
23    easy.insert_char(acs::hline());
24    easy.insert_char(acs::ltee());
25    easy.insert_char(acs::plus());
26    easy.insert_char(acs::rtee());
27    easy.insert_char(acs::ttee());
28    easy.insert_char(acs::vline());
29    easy.insert_char(acs::s1());
30    easy.insert_char(acs::s9());
31
32    easy.move_rc(1, 0);
33
34    easy.insert_char(acs::bullet());
35    easy.insert_char(acs::ckboard());
36    easy.insert_char(acs::degree());
37    easy.insert_char(acs::diamond());
38    easy.insert_char(acs::plminus());
39    easy.insert_char(acs::block());
40    easy.insert_char(acs::board());
41    easy.insert_char(acs::darrow());
42    easy.insert_char(acs::lantern());
43    easy.insert_char(acs::larrow());
44    easy.insert_char(acs::rarrow());
45    easy.insert_char(acs::uarrow());
46    easy.insert_char(acs::s3());
47
48    easy.move_rc(2, 0);
49
50    easy.insert_char(acs::s7());
51    easy.insert_char(acs::gequal());
52    easy.insert_char(acs::lequal());
53    easy.insert_char(acs::nequal());
54    easy.insert_char(acs::pi());
55    easy.insert_char(acs::sterling());
56    easy.insert_char(acs::bbss());
57    easy.insert_char(acs::bssb());
58    easy.insert_char(acs::sbbs());
59    easy.insert_char(acs::sbss());
60    easy.insert_char(acs::ssbb());
61    easy.insert_char(acs::ssbs());
62    easy.insert_char(acs::sssb());
63    easy.insert_char(acs::bsbs());
64    easy.insert_char(acs::bsss());
65    easy.insert_char(acs::sbsb());
66    easy.insert_char(acs::ssss());
67
68    easy.refresh();
69
70    easy.get_input();
71}
Source

pub fn set_bold(&mut self, bold_on: bool) -> Option<()>

Enables or disables bold text for all future input.

Source

pub fn set_underline(&mut self, underline_on: bool) -> Option<()>

Enables or disables underlined text for all future input.

Source

pub fn get_row_col_count(&self) -> (i32, i32)

Returns the number of rows and columns available in the window. Each of these are the number of locations in that dimension, but the rows and cols (as well as the Xs and Ys if you care to use that coordinate space) use 0-based indexing, so the actual addressable locations are numbered 0 to N-1, similar to with slices, .len(), and indexing. Fortunately, the normal rust Range type already handles this for us. If you wanted to iterate every cell of the window you’d probably use a loop like this:

let mut easy = easycurses::EasyCurses::initialize_system().unwrap();
let (row_count,col_count) = easy.get_row_col_count();
// using RC coordinates.
for row in 0..row_count {
    for col in 0..col_count {
        easy.move_rc(row,col);
        let (actual_row,actual_col) = easy.get_cursor_rc();
        assert!(actual_row == row && actual_col == col);
    }
}
// using XY coordinates.
for y in 0..row_count {
    for x in 0..col_count {
        easy.move_xy(x,y);
        let (actual_x,actual_y) = easy.get_cursor_xy();
        assert!(actual_x == x && actual_y == y);
    }
}
Examples found in repository?
examples/bounds.rs (line 16)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
More examples
Hide additional examples
examples/60fps.rs (line 21)
10fn main() {
11  // Normal setup
12  let mut easy = EasyCurses::initialize_system().unwrap();
13  easy.set_cursor_visibility(CursorVisibility::Invisible);
14  easy.set_echo(false);
15  easy.set_keypad_enabled(true);
16  easy.set_input_mode(InputMode::Character);
17  easy.set_input_timeout(TimeoutMode::Immediate);
18  easy.set_scrolling(true);
19
20  // We need to know how wide our screen is.
21  let (_, mut col_count) = easy.get_row_col_count();
22
23  // Sadly we can't make this const since it has to unwrap and all that, but
24  // ideally this could be a const. You could use lazy_static I guess if you
25  // really cared, but it's not a huge deal.
26  let frame_target_duration = Duration::new(1, 0).checked_div(60).expect("failed when rhs!=0, what?");
27
28  // We start at an arbitrary position.
29  let mut position = 5;
30  loop {
31    let top_of_loop = Instant::now();
32    // Gather/process any pending input
33    while let Some(input) = easy.get_input() {
34      match input {
35        Input::KeyLeft => position = max(0, position - 1),
36        Input::KeyRight => position = min(col_count - 1, position + 1),
37        Input::KeyResize => {
38          col_count = easy.get_row_col_count().1;
39          position = min(col_count - 1, position);
40        }
41        other => println!("Unknown: {:?}", other),
42      }
43    }
44    // Compute what we'll display.
45    let output = repeat('#').take(position as usize).collect::<String>();
46
47    // Sleep a bit if we need to. This actually sleeps a little longer than
48    // just the right time because it doesn't account for the display time
49    // we'll use up after the sleep happens. However, curses doesn't really
50    // demand perfect animation anyway.
51    let elapsed_this_frame = top_of_loop.elapsed();
52    if let Some(frame_remaining) = frame_target_duration.checked_sub(elapsed_this_frame) {
53      sleep(frame_remaining);
54    }
55
56    // Display
57    easy.print("\n");
58    easy.print(&output);
59    easy.refresh();
60  }
61}
Source

pub fn move_rc(&mut self, row: i32, col: i32) -> Option<()>

Moves the virtual cursor to the row and column specified, relative to the top left (“notepad” space). Does not move the terminal’s displayed cursor (if any) until refresh is also called. Out of bounds locations cause this command to be ignored.

Examples found in repository?
examples/bounds.rs (line 19)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
More examples
Hide additional examples
examples/acs.rs (line 16)
9fn main() {
10    let mut easy = EasyCurses::initialize_system().unwrap();
11
12    easy.set_echo(false);
13
14    easy.set_color_pair(colorpair!(Green on Black));
15
16    easy.move_rc(0, 0);
17
18    easy.insert_char(acs::llcorner());
19    easy.insert_char(acs::lrcorner());
20    easy.insert_char(acs::ulcorner());
21    easy.insert_char(acs::urcorner());
22    easy.insert_char(acs::btee());
23    easy.insert_char(acs::hline());
24    easy.insert_char(acs::ltee());
25    easy.insert_char(acs::plus());
26    easy.insert_char(acs::rtee());
27    easy.insert_char(acs::ttee());
28    easy.insert_char(acs::vline());
29    easy.insert_char(acs::s1());
30    easy.insert_char(acs::s9());
31
32    easy.move_rc(1, 0);
33
34    easy.insert_char(acs::bullet());
35    easy.insert_char(acs::ckboard());
36    easy.insert_char(acs::degree());
37    easy.insert_char(acs::diamond());
38    easy.insert_char(acs::plminus());
39    easy.insert_char(acs::block());
40    easy.insert_char(acs::board());
41    easy.insert_char(acs::darrow());
42    easy.insert_char(acs::lantern());
43    easy.insert_char(acs::larrow());
44    easy.insert_char(acs::rarrow());
45    easy.insert_char(acs::uarrow());
46    easy.insert_char(acs::s3());
47
48    easy.move_rc(2, 0);
49
50    easy.insert_char(acs::s7());
51    easy.insert_char(acs::gequal());
52    easy.insert_char(acs::lequal());
53    easy.insert_char(acs::nequal());
54    easy.insert_char(acs::pi());
55    easy.insert_char(acs::sterling());
56    easy.insert_char(acs::bbss());
57    easy.insert_char(acs::bssb());
58    easy.insert_char(acs::sbbs());
59    easy.insert_char(acs::sbss());
60    easy.insert_char(acs::ssbb());
61    easy.insert_char(acs::ssbs());
62    easy.insert_char(acs::sssb());
63    easy.insert_char(acs::bsbs());
64    easy.insert_char(acs::bsss());
65    easy.insert_char(acs::sbsb());
66    easy.insert_char(acs::ssss());
67
68    easy.refresh();
69
70    easy.get_input();
71}
Source

pub fn get_cursor_rc(&self) -> (i32, i32)

Obtains the cursor’s current position using (R,C) coordinates relative to the top left corner.

Examples found in repository?
examples/bounds.rs (line 20)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
Source

pub fn move_xy(&mut self, x: i32, y: i32) -> Option<()>

Moves the virtual cursor to the x and y specified, relative to the bottom left (“cartesian” space). Does not move the terminal’s displayed cursor (if any) until refresh is also called. Out of bounds locations cause this command to be ignored.

Examples found in repository?
examples/bounds.rs (line 24)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
Source

pub fn get_cursor_xy(&self) -> (i32, i32)

Obtains the cursor’s current position using (X,Y) coordinates relative to the bottom left corner.

Examples found in repository?
examples/bounds.rs (line 25)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
Source

pub fn set_scrolling(&mut self, scrolling: bool) -> Option<()>

When scrolling is enabled, any attempt to move off the bottom margin will cause lines within the scrolling region to scroll up one line. If a scrolling region is set but scrolling is not enabled then attempts to go off the bottom will just print nothing instead. Use set_scroll_region to control the size of the scrolling region.

Examples found in repository?
examples/60fps.rs (line 18)
10fn main() {
11  // Normal setup
12  let mut easy = EasyCurses::initialize_system().unwrap();
13  easy.set_cursor_visibility(CursorVisibility::Invisible);
14  easy.set_echo(false);
15  easy.set_keypad_enabled(true);
16  easy.set_input_mode(InputMode::Character);
17  easy.set_input_timeout(TimeoutMode::Immediate);
18  easy.set_scrolling(true);
19
20  // We need to know how wide our screen is.
21  let (_, mut col_count) = easy.get_row_col_count();
22
23  // Sadly we can't make this const since it has to unwrap and all that, but
24  // ideally this could be a const. You could use lazy_static I guess if you
25  // really cared, but it's not a huge deal.
26  let frame_target_duration = Duration::new(1, 0).checked_div(60).expect("failed when rhs!=0, what?");
27
28  // We start at an arbitrary position.
29  let mut position = 5;
30  loop {
31    let top_of_loop = Instant::now();
32    // Gather/process any pending input
33    while let Some(input) = easy.get_input() {
34      match input {
35        Input::KeyLeft => position = max(0, position - 1),
36        Input::KeyRight => position = min(col_count - 1, position + 1),
37        Input::KeyResize => {
38          col_count = easy.get_row_col_count().1;
39          position = min(col_count - 1, position);
40        }
41        other => println!("Unknown: {:?}", other),
42      }
43    }
44    // Compute what we'll display.
45    let output = repeat('#').take(position as usize).collect::<String>();
46
47    // Sleep a bit if we need to. This actually sleeps a little longer than
48    // just the right time because it doesn't account for the display time
49    // we'll use up after the sleep happens. However, curses doesn't really
50    // demand perfect animation anyway.
51    let elapsed_this_frame = top_of_loop.elapsed();
52    if let Some(frame_remaining) = frame_target_duration.checked_sub(elapsed_this_frame) {
53      sleep(frame_remaining);
54    }
55
56    // Display
57    easy.print("\n");
58    easy.print(&output);
59    easy.refresh();
60  }
61}
Source

pub fn set_scroll_region(&mut self, top: i32, bottom: i32) -> Option<()>

Sets the top and bottom margins of the scrolling region. The inputs should be the line numbers (relative to the top of the screen) for the borders. Either border can be 0.

See also: setscrreg

Source

pub fn print<S: AsRef<str>>(&mut self, asref: S) -> Option<()>

Prints the given string-like value into the window by printing each individual character into the window. If there is any error encountered upon printing a character, that cancels the printing of the rest of the characters.

Examples found in repository?
examples/hello.rs (line 27)
12fn main() {
13  // Initialize the system
14  let mut easy = EasyCurses::initialize_system().unwrap();
15
16  // don't show the cursor
17  easy.set_cursor_visibility(CursorVisibility::Invisible);
18
19  // don't echo the user's input
20  easy.set_echo(false);
21
22  // we'll print this in green text.
23  easy.set_color_pair(colorpair!(Green on Black));
24
25  // Print this string from the current position. The default cursor position
26  // is rc(0,0)
27  easy.print("Hello world.");
28
29  // Ensure that the user has the latest view of things.
30  easy.refresh();
31
32  // Get one input from the user. This is just so that they have a chance to
33  // see the message and press a key, otherwise the program would end faster
34  // than they could read it.
35  easy.get_input();
36}
More examples
Hide additional examples
examples/preserve_panic_message.rs (line 13)
6fn main() {
7    // We wrap all our use of curses with this function.
8    preserve_panic_message(|easy| {
9        // In here we get an initialized EasyCurses handle and then proceed to
10        // use it exactly like we normally would use it.
11        easy.set_cursor_visibility(CursorVisibility::Invisible);
12        easy.set_echo(false);
13        easy.print("Hello world.");
14        easy.refresh();
15        easy.get_input();
16        panic!("oh no");
17    }).unwrap_or_else(|e| match e {
18        // This block only runs if there was an error. We might or might not
19        // have been able to recover an error message. You technically can pass
20        // any value into a panic, but we only get an error message if the panic
21        // value was a `String` or `&str`.
22        Some(errmsg) => println!("Error Occurred: {}", errmsg),
23        None => println!("There was an error, but no error message."),
24    });
25}
examples/bounds.rs (line 21)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
examples/60fps.rs (line 57)
10fn main() {
11  // Normal setup
12  let mut easy = EasyCurses::initialize_system().unwrap();
13  easy.set_cursor_visibility(CursorVisibility::Invisible);
14  easy.set_echo(false);
15  easy.set_keypad_enabled(true);
16  easy.set_input_mode(InputMode::Character);
17  easy.set_input_timeout(TimeoutMode::Immediate);
18  easy.set_scrolling(true);
19
20  // We need to know how wide our screen is.
21  let (_, mut col_count) = easy.get_row_col_count();
22
23  // Sadly we can't make this const since it has to unwrap and all that, but
24  // ideally this could be a const. You could use lazy_static I guess if you
25  // really cared, but it's not a huge deal.
26  let frame_target_duration = Duration::new(1, 0).checked_div(60).expect("failed when rhs!=0, what?");
27
28  // We start at an arbitrary position.
29  let mut position = 5;
30  loop {
31    let top_of_loop = Instant::now();
32    // Gather/process any pending input
33    while let Some(input) = easy.get_input() {
34      match input {
35        Input::KeyLeft => position = max(0, position - 1),
36        Input::KeyRight => position = min(col_count - 1, position + 1),
37        Input::KeyResize => {
38          col_count = easy.get_row_col_count().1;
39          position = min(col_count - 1, position);
40        }
41        other => println!("Unknown: {:?}", other),
42      }
43    }
44    // Compute what we'll display.
45    let output = repeat('#').take(position as usize).collect::<String>();
46
47    // Sleep a bit if we need to. This actually sleeps a little longer than
48    // just the right time because it doesn't account for the display time
49    // we'll use up after the sleep happens. However, curses doesn't really
50    // demand perfect animation anyway.
51    let elapsed_this_frame = top_of_loop.elapsed();
52    if let Some(frame_remaining) = frame_target_duration.checked_sub(elapsed_this_frame) {
53      sleep(frame_remaining);
54    }
55
56    // Display
57    easy.print("\n");
58    easy.print(&output);
59    easy.refresh();
60  }
61}
Source

pub fn print_char<T: ToChtype>(&mut self, character: T) -> Option<()>

Prints the given character into the window.

Examples found in repository?
examples/bounds.rs (line 30)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
Source

pub fn insert_char<T: ToChtype>(&mut self, character: T) -> Option<()>

Inserts the character desired at the current location, pushing the current character at that location (and all after it on the same line) one cell to the right.

Examples found in repository?
examples/acs.rs (line 18)
9fn main() {
10    let mut easy = EasyCurses::initialize_system().unwrap();
11
12    easy.set_echo(false);
13
14    easy.set_color_pair(colorpair!(Green on Black));
15
16    easy.move_rc(0, 0);
17
18    easy.insert_char(acs::llcorner());
19    easy.insert_char(acs::lrcorner());
20    easy.insert_char(acs::ulcorner());
21    easy.insert_char(acs::urcorner());
22    easy.insert_char(acs::btee());
23    easy.insert_char(acs::hline());
24    easy.insert_char(acs::ltee());
25    easy.insert_char(acs::plus());
26    easy.insert_char(acs::rtee());
27    easy.insert_char(acs::ttee());
28    easy.insert_char(acs::vline());
29    easy.insert_char(acs::s1());
30    easy.insert_char(acs::s9());
31
32    easy.move_rc(1, 0);
33
34    easy.insert_char(acs::bullet());
35    easy.insert_char(acs::ckboard());
36    easy.insert_char(acs::degree());
37    easy.insert_char(acs::diamond());
38    easy.insert_char(acs::plminus());
39    easy.insert_char(acs::block());
40    easy.insert_char(acs::board());
41    easy.insert_char(acs::darrow());
42    easy.insert_char(acs::lantern());
43    easy.insert_char(acs::larrow());
44    easy.insert_char(acs::rarrow());
45    easy.insert_char(acs::uarrow());
46    easy.insert_char(acs::s3());
47
48    easy.move_rc(2, 0);
49
50    easy.insert_char(acs::s7());
51    easy.insert_char(acs::gequal());
52    easy.insert_char(acs::lequal());
53    easy.insert_char(acs::nequal());
54    easy.insert_char(acs::pi());
55    easy.insert_char(acs::sterling());
56    easy.insert_char(acs::bbss());
57    easy.insert_char(acs::bssb());
58    easy.insert_char(acs::sbbs());
59    easy.insert_char(acs::sbss());
60    easy.insert_char(acs::ssbb());
61    easy.insert_char(acs::ssbs());
62    easy.insert_char(acs::sssb());
63    easy.insert_char(acs::bsbs());
64    easy.insert_char(acs::bsss());
65    easy.insert_char(acs::sbsb());
66    easy.insert_char(acs::ssss());
67
68    easy.refresh();
69
70    easy.get_input();
71}
Source

pub fn delete_char(&mut self) -> Option<()>

Deletes the character under the cursor. Characters after it on same the line are pulled left one position and the final character cell is left blank. The cursor position does not move.

Source

pub fn insert_line(&mut self) -> Option<()>

Inserts a line above the current line. The bottom line is lost.

Source

pub fn delete_line(&mut self) -> Option<()>

Deletes the line under the cursor. Lines below are moved up one line and the final line is left blank. The cursor position does not move.

Source

pub fn bulk_insert_delete_line(&mut self, n: i32) -> Option<()>

For positive n, insert n lines into the specified window above the current line. The n bottom lines are lost. For negative n, delete n lines (starting with the one under the cursor), and move the remaining lines up. The bottom n lines are cleared. The current cursor position remains the same.

Source

pub fn clear(&mut self) -> Option<()>

Clears the entire screen.

Note: This function can cause flickering of the output with PDCurses if you’re clearing the screen and then immediately writing to the whole screen before you end up calling refresh. The exact location of the flickering effect seems to vary from machine to machine. If you intend to simply replace the whole window with new content, just overwrite the previous values without calling clear and things will be fine.

Source

pub fn refresh(&mut self) -> Option<()>

Refreshes the window’s appearance on the screen. With some implementations you don’t need to call this, the screen will refresh itself on its own. However, for portability, you should call this at the end of each draw cycle.

Examples found in repository?
examples/hello.rs (line 30)
12fn main() {
13  // Initialize the system
14  let mut easy = EasyCurses::initialize_system().unwrap();
15
16  // don't show the cursor
17  easy.set_cursor_visibility(CursorVisibility::Invisible);
18
19  // don't echo the user's input
20  easy.set_echo(false);
21
22  // we'll print this in green text.
23  easy.set_color_pair(colorpair!(Green on Black));
24
25  // Print this string from the current position. The default cursor position
26  // is rc(0,0)
27  easy.print("Hello world.");
28
29  // Ensure that the user has the latest view of things.
30  easy.refresh();
31
32  // Get one input from the user. This is just so that they have a chance to
33  // see the message and press a key, otherwise the program would end faster
34  // than they could read it.
35  easy.get_input();
36}
More examples
Hide additional examples
examples/preserve_panic_message.rs (line 14)
6fn main() {
7    // We wrap all our use of curses with this function.
8    preserve_panic_message(|easy| {
9        // In here we get an initialized EasyCurses handle and then proceed to
10        // use it exactly like we normally would use it.
11        easy.set_cursor_visibility(CursorVisibility::Invisible);
12        easy.set_echo(false);
13        easy.print("Hello world.");
14        easy.refresh();
15        easy.get_input();
16        panic!("oh no");
17    }).unwrap_or_else(|e| match e {
18        // This block only runs if there was an error. We might or might not
19        // have been able to recover an error message. You technically can pass
20        // any value into a panic, but we only get an error message if the panic
21        // value was a `String` or `&str`.
22        Some(errmsg) => println!("Error Occurred: {}", errmsg),
23        None => println!("There was an error, but no error message."),
24    });
25}
examples/bounds.rs (line 42)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
examples/acs.rs (line 68)
9fn main() {
10    let mut easy = EasyCurses::initialize_system().unwrap();
11
12    easy.set_echo(false);
13
14    easy.set_color_pair(colorpair!(Green on Black));
15
16    easy.move_rc(0, 0);
17
18    easy.insert_char(acs::llcorner());
19    easy.insert_char(acs::lrcorner());
20    easy.insert_char(acs::ulcorner());
21    easy.insert_char(acs::urcorner());
22    easy.insert_char(acs::btee());
23    easy.insert_char(acs::hline());
24    easy.insert_char(acs::ltee());
25    easy.insert_char(acs::plus());
26    easy.insert_char(acs::rtee());
27    easy.insert_char(acs::ttee());
28    easy.insert_char(acs::vline());
29    easy.insert_char(acs::s1());
30    easy.insert_char(acs::s9());
31
32    easy.move_rc(1, 0);
33
34    easy.insert_char(acs::bullet());
35    easy.insert_char(acs::ckboard());
36    easy.insert_char(acs::degree());
37    easy.insert_char(acs::diamond());
38    easy.insert_char(acs::plminus());
39    easy.insert_char(acs::block());
40    easy.insert_char(acs::board());
41    easy.insert_char(acs::darrow());
42    easy.insert_char(acs::lantern());
43    easy.insert_char(acs::larrow());
44    easy.insert_char(acs::rarrow());
45    easy.insert_char(acs::uarrow());
46    easy.insert_char(acs::s3());
47
48    easy.move_rc(2, 0);
49
50    easy.insert_char(acs::s7());
51    easy.insert_char(acs::gequal());
52    easy.insert_char(acs::lequal());
53    easy.insert_char(acs::nequal());
54    easy.insert_char(acs::pi());
55    easy.insert_char(acs::sterling());
56    easy.insert_char(acs::bbss());
57    easy.insert_char(acs::bssb());
58    easy.insert_char(acs::sbbs());
59    easy.insert_char(acs::sbss());
60    easy.insert_char(acs::ssbb());
61    easy.insert_char(acs::ssbs());
62    easy.insert_char(acs::sssb());
63    easy.insert_char(acs::bsbs());
64    easy.insert_char(acs::bsss());
65    easy.insert_char(acs::sbsb());
66    easy.insert_char(acs::ssss());
67
68    easy.refresh();
69
70    easy.get_input();
71}
examples/60fps.rs (line 59)
10fn main() {
11  // Normal setup
12  let mut easy = EasyCurses::initialize_system().unwrap();
13  easy.set_cursor_visibility(CursorVisibility::Invisible);
14  easy.set_echo(false);
15  easy.set_keypad_enabled(true);
16  easy.set_input_mode(InputMode::Character);
17  easy.set_input_timeout(TimeoutMode::Immediate);
18  easy.set_scrolling(true);
19
20  // We need to know how wide our screen is.
21  let (_, mut col_count) = easy.get_row_col_count();
22
23  // Sadly we can't make this const since it has to unwrap and all that, but
24  // ideally this could be a const. You could use lazy_static I guess if you
25  // really cared, but it's not a huge deal.
26  let frame_target_duration = Duration::new(1, 0).checked_div(60).expect("failed when rhs!=0, what?");
27
28  // We start at an arbitrary position.
29  let mut position = 5;
30  loop {
31    let top_of_loop = Instant::now();
32    // Gather/process any pending input
33    while let Some(input) = easy.get_input() {
34      match input {
35        Input::KeyLeft => position = max(0, position - 1),
36        Input::KeyRight => position = min(col_count - 1, position + 1),
37        Input::KeyResize => {
38          col_count = easy.get_row_col_count().1;
39          position = min(col_count - 1, position);
40        }
41        other => println!("Unknown: {:?}", other),
42      }
43    }
44    // Compute what we'll display.
45    let output = repeat('#').take(position as usize).collect::<String>();
46
47    // Sleep a bit if we need to. This actually sleeps a little longer than
48    // just the right time because it doesn't account for the display time
49    // we'll use up after the sleep happens. However, curses doesn't really
50    // demand perfect animation anyway.
51    let elapsed_this_frame = top_of_loop.elapsed();
52    if let Some(frame_remaining) = frame_target_duration.checked_sub(elapsed_this_frame) {
53      sleep(frame_remaining);
54    }
55
56    // Display
57    easy.print("\n");
58    easy.print(&output);
59    easy.refresh();
60  }
61}
Source

pub fn beep(&mut self)

Plays an audible beep if possible, if not the screen is flashed. If neither is available then nothing happens.

Source

pub fn flash(&mut self)

Flashes the screen if possible, if not an audible beep is played. If neither is available then nothing happens.

Source

pub fn get_input(&mut self) -> Option<Input>

Gets an Input from the curses input buffer. This will block or not according to the input mode, see set_input_mode. If KeyResize is seen and auto_resize is enabled then the window will automatically update its size for you. In that case, KeyResize is still passed to you so that you can change anything else that might need to be updated.

Examples found in repository?
examples/hello.rs (line 35)
12fn main() {
13  // Initialize the system
14  let mut easy = EasyCurses::initialize_system().unwrap();
15
16  // don't show the cursor
17  easy.set_cursor_visibility(CursorVisibility::Invisible);
18
19  // don't echo the user's input
20  easy.set_echo(false);
21
22  // we'll print this in green text.
23  easy.set_color_pair(colorpair!(Green on Black));
24
25  // Print this string from the current position. The default cursor position
26  // is rc(0,0)
27  easy.print("Hello world.");
28
29  // Ensure that the user has the latest view of things.
30  easy.refresh();
31
32  // Get one input from the user. This is just so that they have a chance to
33  // see the message and press a key, otherwise the program would end faster
34  // than they could read it.
35  easy.get_input();
36}
More examples
Hide additional examples
examples/preserve_panic_message.rs (line 15)
6fn main() {
7    // We wrap all our use of curses with this function.
8    preserve_panic_message(|easy| {
9        // In here we get an initialized EasyCurses handle and then proceed to
10        // use it exactly like we normally would use it.
11        easy.set_cursor_visibility(CursorVisibility::Invisible);
12        easy.set_echo(false);
13        easy.print("Hello world.");
14        easy.refresh();
15        easy.get_input();
16        panic!("oh no");
17    }).unwrap_or_else(|e| match e {
18        // This block only runs if there was an error. We might or might not
19        // have been able to recover an error message. You technically can pass
20        // any value into a panic, but we only get an error message if the panic
21        // value was a `String` or `&str`.
22        Some(errmsg) => println!("Error Occurred: {}", errmsg),
23        None => println!("There was an error, but no error message."),
24    });
25}
examples/bounds.rs (line 47)
8fn main() {
9    // Common startup
10    let mut easy = EasyCurses::initialize_system().unwrap();
11    easy.set_cursor_visibility(CursorVisibility::Invisible);
12    easy.set_echo(false);
13    easy.set_keypad_enabled(true);
14
15    // Check the size of the window.
16    let (row_count, col_count) = easy.get_row_col_count();
17
18    // A message using RC coordinates.
19    easy.move_rc(0, 0);
20    assert_eq!(easy.get_cursor_rc(), (0, 0));
21    easy.print("Hello from RC 0,0.");
22
23    // A message using XY coordinates.
24    easy.move_xy(1, 1);
25    assert_eq!(easy.get_cursor_xy(), (1, 1));
26    easy.print("Hello from XY 1,1.");
27
28    // Upper right corner has a '+'
29    easy.move_rc(0, col_count - 1);
30    easy.print_char('+');
31
32    // Lower left corner has a '-', note that the col_count based argument is
33    // the first argument now because we're using the xy coordinate system.
34    easy.move_xy(col_count - 1, 0);
35    easy.print_char('-');
36
37    // Middle of the screen (ish) has a '*'
38    easy.move_xy(col_count / 2, row_count / 2);
39    easy.print_char('*');
40
41    // Ensure that the user has the latest view of things.
42    easy.refresh();
43
44    // Get one input from the user. This is just so that they have a chance to
45    // see the message and press a key, otherwise the program would end faster
46    // than they could read it.
47    easy.get_input();
48}
examples/acs.rs (line 70)
9fn main() {
10    let mut easy = EasyCurses::initialize_system().unwrap();
11
12    easy.set_echo(false);
13
14    easy.set_color_pair(colorpair!(Green on Black));
15
16    easy.move_rc(0, 0);
17
18    easy.insert_char(acs::llcorner());
19    easy.insert_char(acs::lrcorner());
20    easy.insert_char(acs::ulcorner());
21    easy.insert_char(acs::urcorner());
22    easy.insert_char(acs::btee());
23    easy.insert_char(acs::hline());
24    easy.insert_char(acs::ltee());
25    easy.insert_char(acs::plus());
26    easy.insert_char(acs::rtee());
27    easy.insert_char(acs::ttee());
28    easy.insert_char(acs::vline());
29    easy.insert_char(acs::s1());
30    easy.insert_char(acs::s9());
31
32    easy.move_rc(1, 0);
33
34    easy.insert_char(acs::bullet());
35    easy.insert_char(acs::ckboard());
36    easy.insert_char(acs::degree());
37    easy.insert_char(acs::diamond());
38    easy.insert_char(acs::plminus());
39    easy.insert_char(acs::block());
40    easy.insert_char(acs::board());
41    easy.insert_char(acs::darrow());
42    easy.insert_char(acs::lantern());
43    easy.insert_char(acs::larrow());
44    easy.insert_char(acs::rarrow());
45    easy.insert_char(acs::uarrow());
46    easy.insert_char(acs::s3());
47
48    easy.move_rc(2, 0);
49
50    easy.insert_char(acs::s7());
51    easy.insert_char(acs::gequal());
52    easy.insert_char(acs::lequal());
53    easy.insert_char(acs::nequal());
54    easy.insert_char(acs::pi());
55    easy.insert_char(acs::sterling());
56    easy.insert_char(acs::bbss());
57    easy.insert_char(acs::bssb());
58    easy.insert_char(acs::sbbs());
59    easy.insert_char(acs::sbss());
60    easy.insert_char(acs::ssbb());
61    easy.insert_char(acs::ssbs());
62    easy.insert_char(acs::sssb());
63    easy.insert_char(acs::bsbs());
64    easy.insert_char(acs::bsss());
65    easy.insert_char(acs::sbsb());
66    easy.insert_char(acs::ssss());
67
68    easy.refresh();
69
70    easy.get_input();
71}
examples/60fps.rs (line 33)
10fn main() {
11  // Normal setup
12  let mut easy = EasyCurses::initialize_system().unwrap();
13  easy.set_cursor_visibility(CursorVisibility::Invisible);
14  easy.set_echo(false);
15  easy.set_keypad_enabled(true);
16  easy.set_input_mode(InputMode::Character);
17  easy.set_input_timeout(TimeoutMode::Immediate);
18  easy.set_scrolling(true);
19
20  // We need to know how wide our screen is.
21  let (_, mut col_count) = easy.get_row_col_count();
22
23  // Sadly we can't make this const since it has to unwrap and all that, but
24  // ideally this could be a const. You could use lazy_static I guess if you
25  // really cared, but it's not a huge deal.
26  let frame_target_duration = Duration::new(1, 0).checked_div(60).expect("failed when rhs!=0, what?");
27
28  // We start at an arbitrary position.
29  let mut position = 5;
30  loop {
31    let top_of_loop = Instant::now();
32    // Gather/process any pending input
33    while let Some(input) = easy.get_input() {
34      match input {
35        Input::KeyLeft => position = max(0, position - 1),
36        Input::KeyRight => position = min(col_count - 1, position + 1),
37        Input::KeyResize => {
38          col_count = easy.get_row_col_count().1;
39          position = min(col_count - 1, position);
40        }
41        other => println!("Unknown: {:?}", other),
42      }
43    }
44    // Compute what we'll display.
45    let output = repeat('#').take(position as usize).collect::<String>();
46
47    // Sleep a bit if we need to. This actually sleeps a little longer than
48    // just the right time because it doesn't account for the display time
49    // we'll use up after the sleep happens. However, curses doesn't really
50    // demand perfect animation anyway.
51    let elapsed_this_frame = top_of_loop.elapsed();
52    if let Some(frame_remaining) = frame_target_duration.checked_sub(elapsed_this_frame) {
53      sleep(frame_remaining);
54    }
55
56    // Display
57    easy.print("\n");
58    easy.print(&output);
59    easy.refresh();
60  }
61}
Source

pub fn flush_input(&mut self)

Discards all type-ahead that has been input by the user but not yet read by the program.

Source

pub fn un_get_input(&mut self, input: Input) -> Option<()>

Pushes an Input value into the input stack so that it will be returned by the next call to get_input. The return value is if the operation was successful.

Source

pub fn resize(&mut self, new_lines: i32, new_cols: i32) -> Option<()>

Sets the window to use the number of lines and columns specified. If you pass zero for both then this will make the window’s data structures attempt to match the current size of the window. This is done automatically for you when KeyResize comes in through the input buffer.

Trait Implementations§

Source§

impl Debug for EasyCurses

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for EasyCurses

Source§

fn drop(&mut self)

Dropping EasyCurses causes the endwin curses function to be called.

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.