#tui #ui #text-based

dreg

A simple text-based user interface library

5 releases

0.2.2 Oct 18, 2024
0.2.1 Oct 17, 2024
0.2.0 Oct 14, 2024
0.1.1 Aug 12, 2024
0.1.0 Aug 7, 2024

#369 in Command-line interface

Download history 103/week @ 2024-08-03 121/week @ 2024-08-10 9/week @ 2024-08-17 20/week @ 2024-09-14 11/week @ 2024-09-21 3/week @ 2024-09-28 1/week @ 2024-10-05 385/week @ 2024-10-12 82/week @ 2024-10-19 2/week @ 2024-10-26 12/week @ 2024-11-02

481 downloads per month

MIT license

76KB
1.5K SLoC

Table of Contents


Crate Badge Docs Badge License Badge

Dreg

A simple text-based user interface library that will run on just about anything.

Examples

Terminal

use dreg::prelude::*;

fn main() -> Result<()> {
    let program = MyProgram {
        should_quit: false,
    };
    let platform = CrosstermPlatform::new()?;

    run_program(program, platform)?;

    Ok(())
}

struct MyProgram {
    should_quit: bool,
}

impl Program for MyProgram {
    fn update(&mut self, frame: Frame) {
        // When the user pressed `q`, the program safely exits.
        if frame.context.keys_down().contains(&Scancode::Q) {
            self.should_quit = true;
            return; // No need to render anything past this point.
        }
        frame.buffer.set_string(
            1, // Column index.
            1, // Row index.
            format!("KEYS DOWN: {:?}", frame.context.keys_down()),
            Style::new(), // No styling.
        );
    }

    fn should_exit(&self) -> bool {
        self.should_quit
    }
}

Overview

Design Philosophy

The design of Dreg has been radical simplicity from the very start.

Features

  • Runs on anything[^1].

Limitations

  • No support for variable width fonts; even on platforms that do support them.

Acknowledgments

  • ratatui & tui-rs, for the original inspiration for the project.

License

MIT

[^1]: It's not gonna run on your toaster, but it might run on your smart fridge.

Dependencies

~2–10MB
~116K SLoC