Crates.io | bevy_term |
lib.rs | bevy_term |
version | |
source | src |
created_at | 2024-12-05 16:13:58.894185 |
updated_at | 2024-12-05 16:13:58.894185 |
description | Easy terminal event handling and rendering with Bevy! |
homepage | |
repository | https://git.sr.ht/~sntx/bevy_term |
max_upload_size | |
id | 1473361 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Easy terminal event handling and rendering with Bevy!
This crate primarily provides the TerminalPlugin
for Bevy.
It allows for easily rendering to the terminal and handling terminal events.
Check out the examples directory!
fn main() -> AppExit {
App::new()
.add_plugins(TerminalPlugin)
// ...
.run()
}
fn main() -> AppExit {
App::new()
.add_systems(PostUpdate, render)
// ...
.run()
}
fn render(mut terminal: ResMut<Terminal>) {
terminal
.0
.draw(|frame| {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Percentage(49), Constraint::Min(1)].as_ref())
.split(frame.area());
frame.render_widget(
Paragraph::new("Hellow World!\nPress `ESC` or `C-d` to exit.")
.alignment(Alignment::Center),
chunks[1],
);
})
.unwrap();
}
fn main() -> AppExit {
App::new()
.add_systems(PreUpdate, handler)
// ...
.run()
}
fn handler(
mut terminal_events: EventReader<bevy_term::Event>,
mut tui_state: ResMut<bevy_term::State>,
) {
for terminal_event in terminal_events.read() {
if let Event::Key(key_event) = terminal_event.0 {
if key_event.code == KeyCode::Esc {
*tui_state = bevy_term::State::Exit
}
}
}
}