3 releases

0.2.2 Oct 18, 2024
0.2.1 Oct 17, 2024
0.2.0 Oct 14, 2024

#682 in GUI

29 downloads per month
Used in dreg

MIT license

86KB
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

Simple Terminal-Only Application
use dreg::prelude::*;

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

    run_program(program, platform)?;

    Ok(())
}

struct MyProgram {
    should_quit: bool,
    latest_input: Input,
}

impl Program for MyProgram {
    fn update(&mut self, frame: Frame) {
        // When the user presses `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 (x-coordinate).
            1, // Row index (y-coordinate).
            format!("LATEST INPUT: {:?}", self.latest_input),
            Style::new(), // No styling, cells will default to the user's terminal foreground color.
        );
    }

    fn on_input(&mut self, input: Input) {
        self.latest_input = input;
    }

    fn on_platform_request(&self, request: &str) -> Option<&str> {
        // Terminals do not perform requests.
        None
    }

    fn should_exit(&self) -> bool {
        // This function is called every frame.
        self.should_quit
    }
}

Overview

Features

Runs on just about anything.
Platform Support
Terminal ✔ Full support
Web ✔ Mostly supported
Native ✖ In progress

Limitations

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

Design Philosophy

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

Acknowledgments

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

License

MIT


lib.rs:

Crossterm Platform

Dependencies

~4–12MB
~159K SLoC