Crate yacurses[][src]

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.

Structs

Attributes

Attributes that can be applied to a character’s cell (a bitflag value).

ColorID

Names a color within curses.

ColorPair

Names a foreground / background color pairing within curses.

Curses

Handle to the terminal’s curses interface.

CursesGlyph

A single ascii value to draw to the screen, along with color and attributes.

CursesShell

While you hold this, the terminal is in shell mode.

Position

A position on the screen.

TerminalSize

Used to return info about the upper bounds of the screen.

Enums

CursesKey

The types of input keys that ncurses can generate.

CursorVisibility

Use with set_cursor_visibility