Expand description
§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
Modules§
- color
- Defines all colors and UI styling.
- event
- key
- Defines all the keys
termixrecognizes. - model
- Trait of model and useful types