5 releases

Uses old Rust 2015

0.2.0 Jan 6, 2019
0.1.3 Jan 27, 2018
0.1.2 Jan 22, 2018
0.1.1 Jul 11, 2017
0.1.0 Jul 11, 2017

#637 in Command-line interface

24 downloads per month

MIT license

32KB
759 lines

termfest

Build Status

termfest is a thread-safe TUI library that provides simple APIs to render texts in terminal, heavily inspired by nsf/termbox-go. Currently, termfest doesn't support windows because of my poor windows experience.

termfest has internal buffer for efficient rendering. Applications can render everything to the buffer every time, and termfest flushes the buffer and renders only the difference between the terminal state and the buffer.

use termfest::{Termfest, Event};
use termfest::attr::*;
use termfest::key::*;

// first, initialize termfest.
let (fest, events) = Termfest::hold().unwrap();

let mut y = 0;

// events is a receiver of a channel that accepts terminal events like key input.
for ev in events.iter() {
    {
        // lock the screen.
        let mut screen = fest.lock_screen();
        // clear the buffer. you can render everything every time.
        // termfest can provide efficient rendering.
        screen.clear();
        // write to the buffer.
        let attr = Attribute { fg: Color::Red, ..Attribute::default() };
        screen.print(0, y, "Hello, world!", attr);
        // when the screen lock is released, the buffer is flushed.
        // (you can flush the buffer with explicit `flush` call.)
    }
    match ev {
        Event::Key(ESC) | Event::Char('q') => break,
        Event::Key(ArrowUp) => if y > 0 { y -= 1; },
        Event::Key(ArrowDown) => y += 1,
        _ => {}
    }
}

See examples for more detail.

Dependencies

~3MB
~58K SLoC