Crate termfest

source ·
Expand description

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.

Example

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,
        _ => {}
    }
}

Modules

This module provides rendering attributes like color or bold.
This module defines a variant of special keys and their aliases.

Structs

Cell is a cell of the terminal. It has a display character and an attribute (fg and bg color, effects).
ScreenLock is a locked screen buffer, created by Termfest::lock_screen. When it is dropped, the buffered state will be flushed to the terminal. All rendering manipulation is implemented in ScreenLock.
Termfest holds termfest states. It is created by Termfest::hold. When it is dropped, termfest finalizes and restores every terminal states.

Enums

Event is an event of termfest, that contains special key pressed, character input, and window resize.

Traits

DisplayWidth provides a way to determine display width of characters or strings.