[][src]Crate newt

newt-rs

Rust bindings for the Newt console UI library.

This crate provides bindings to Red Hat, Inc.'s Newt console UI library. Newt is a small and simple to use UI library providing widgets and basic stacked window management for console applications.

The majority, if not all of Newt's functionality has been implemented. Although some features currently require the nightly build of the Rust compiler.

Example

extern crate newt;
use newt::prelude::*;

pub fn main() {
    newt::init().unwrap();
    newt::cls();
    newt::centered_window(20, 5, Some("Greetings")).unwrap();

    let mut form = Form::new(None, 0);
    let mut text = Textbox::new(4, 1, 12, 1, 0);
    let mut ok = CompactButton::new(7, 3, "Ok");

    text.set_text("Hello World!");
    form.add_components(&mut [&mut text, &mut ok]).unwrap();
    let reason = form.run().unwrap();
    newt::finished();

    match reason {
        ExitReason::HotKey(key) => // F12 is the default HotKey
            println!("Execution stopped due to HotKey: {}", key),
        ExitReason::Component(co) =>
            println!("Execution stopped due to Component: {:p}", co.co()),
        _ =>
            println!("Execution stopped due to other reason...")
    }
}

Features

  • asm - Allows building of the Grid module and the windows::win_entries and windows::win_menu functions. These require the inline assembly feature of Rust which is only available in nightly builds. This feature is also only available on x86/x86_64 architectures.

  • static - Builds and links newt-sys statically against its included libraries rather than linking dynamically against available system libraries. This is done automatically if the required system libraries are unavailable.

Deprecation Warning

As of newt-rs 0.5.4 module organization has been refactored. Items have been re-exported under their previous names and modules for compatability, but these re-exports are likely to be removed in the future. The following changes have been made:

  • The newt::components module has been renamed to newt::widgets.

  • The newt::components::Component trait has been renamed to newt::component::Component.

  • The newt::components::ComponentFuncs trait has been renamed to newt::widgets::WidgetFns.

  • The newt::grid::GridTrait trait has been renamed to newt::grid::GridFns.

Bugs

A Form can be destroyed before the Components they contain are dropped, causing the newtComponent pointers they reference to become invalid. Any functions called on these Components may return invalid values or even cause segmentation faults. Do NOT allocate Forms within a more limited scope than the Components they contain. An example of this issue can be found here.

Re-exports

pub use self::component::Component;
pub use self::widgets::WidgetFns;
pub use self::callbacks::Callback;
pub use self::windows::win_message;
pub use self::windows::win_choice;
pub use self::windows::win_ternary;
pub use self::windows::win_menu;
pub use self::windows::win_entries;

Modules

callbacks

Callbacks and filters.

component

Trait implemented by Widget and Grid types.

componentsDeprecated

Deprecated module re-exported for backwards compatibility.

constants

Constants used by the newt library.

grid

Methods for easily arranging component placement.

prelude

Convenient imports.

widgets

newt UI widgets.

windows

Convenient windowing functions.

Structs

Colors

A struct containing the color sets for all components.

Functions

bell

Issue a terminal beep.

centered_window

Open a window in the center of the screen.

clear_key_buffer

Clear the key buffer.

cls

Clear the screen.

cursor_off

Turn the cursor visibility off.

cursor_on

Turn the cursor visibility on.

delay

Wait for a specified amount of time.

draw_root_text

Draw text directly to the root window.

finished

Close down the newt library and reset the terminal.

get_screen_size

Get the terminal screen size.

init

Initialize the newt library.

open_window

Open a window at the specified location.

pop_help_line

Remove the help line.

pop_window

Close the most recently opened window.

pop_window_no_refresh

Close the most recently opened window without redrawing the screen.

push_help_line

Display a help string on the bottom of the screen.

redraw_help_line

Redraw the help line.

reflow_text

Reflow text according to the provided specifications.

refresh

Redraw the screen.

resize_screen

Notify newt of a screen resize.

resume

Resume running the newt library.

set_color

Set a specific color set.

set_colors

Set the colors used by the newt library.

suspend

Temporarily suspend the newt library and reset the terminal.

wait_for_key

Wait until a key is pressed.