9 releases
0.2.5 | Aug 15, 2024 |
---|---|
0.2.4 | Mar 2, 2021 |
0.2.3 | Feb 26, 2021 |
0.2.1 | Sep 7, 2020 |
0.0.1 | Aug 25, 2020 |
#219 in Command-line interface
516 downloads per month
405KB
8K
SLoC
yacurses
yet another curses lib
lib.rs
:
Yet another curses library.
This crate binds to either the system ncurses on Unix (MIT-X11 license), or a bundled copy of pdcurses on Windows (public domain). It then exposes a somewhat rustified interface on top of curses.
The interface offered is fully safe, but does not expose every single part of the curses API. For example, this only supports a single window, and it does not support any of the functions that print via format-string.
The interface offered should be useful for the majority of cases.
Usage
This crate is accessed through a Curses
handle (traditionally called
"win", for "window"). Use the init
method to start curses
mode. Dropping the struct will automatically end curses mode.
Caution: Curses mode is a global effect, and attempting to double-initialize curses will panic. Also, if curses fails to initialize, the curses library itself will print a message and abort your process.
use yacurses::*;
fn main() {
let mut win = Curses::init();
win.move_cursor(Position { x: 3, y: 2 });
win.print_str("demo message");
win.poll_events(); // by default, this blocks until an event comes in.
}
Panic Hook
The default panic hook will print the panic message and then unwind. If
this happens while curses mode is active, curses mode will just eat the
message and you won't see what went wrong. To resolve this, yacurses
installs a custom panic hook when you turn it on, and restores the previous
panic hook when it closes down. This all happens automatically.
A side effect of this is that if you also wanted to have your own panic hook going on, then there can end up being conflicts. Sorry about that, not much can be done there.