2 releases

0.0.3 Jan 29, 2023
0.0.2 Jan 15, 2023
0.0.1 Jan 15, 2023

#615 in Command-line interface

45 downloads per month

MIT license

41KB
994 lines

Termix is a framework for building TUI application inspired by bubbletea. Termix's interfaces are very similar to it.

See example

cargo run --example <simple | views>

WIP

  • Mouse support
  • Some useful plugins
  • More customizable interface
  • Windows support and more

References

Termix borrows ideas from lots of other projects:

  • bubbletea
    • Architecture and interface inspiration.
    • How to render.
  • tuikit
    • How to enter the raw mode.
    • Part of the keycode parsing logic.
    • Also inspired by termion, rustyline.

lib.rs:

Termix

Termix is a framework to build TUI application with simplicity. This framework is inspired by bubbletea.

For now, this framework is beta version and WIP.

Usage

In your Cargo.toml add the following:

[dependencies]
termix = "0.1.0"

Here is an example:

use std::time::Duration;

use termix::{
    color::{Color, StyledText},
    event::Event,
    model::{ModelAct, Updater},
    Program,
};

struct Model(usize);

#[derive(Debug)]
struct Tick {}

impl ModelAct<Model, Tick> for Model {
    fn update(&self, event: &Event<Tick>) -> Updater<Model, Tick> {
        match event {
            Event::Init => (Some(Box::new(Model(self.0))), Some(tick)),
            Event::Custom(_) => {
                if self.0 - 1 == 0 {
                    return (Some(Box::new(Model(self.0 - 1))), Some(|| Event::Quit));
                }
                (Some(Box::new(Model(self.0 - 1))), Some(tick))
            }
            Event::Keyboard(..) => (None, Some(|| Event::Quit)),
            _ => (None, None),
        }
    }
    fn view(&self) -> String {
        StyledText::new(
            &format!(
                "Hi. This program will exit in {} seconds. To quit sooner press any key.\n",
                self.0
            ),
            Some(Color::Ansi256(212)),
            None,
            None,
            None,
            None,
        )
        .text()
    }
}

fn tick() -> Event<Tick> {
    let one_sec = Duration::from_secs(1);
    std::thread::sleep(one_sec);
    Event::Custom(Tick {})
}

fn main() {
    Program::new(Box::new(Model(5))).run();
}

To know how to use termix practically, you can look at the examples

Dependencies

~2.5MB
~55K SLoC