15 releases (4 breaking)
0.5.0 | Feb 18, 2024 |
---|---|
0.4.1 | Feb 12, 2024 |
0.4.0 | Jan 14, 2024 |
0.3.0 | Jan 9, 2024 |
0.1.4 | Dec 22, 2023 |
#244 in Game dev
272 downloads per month
44KB
312 lines
Bevy Local Commands
Bevy plugin to manage local shell commands.
Usage
Add the plugin:
// ...
.add_plugins(BevyLocalCommandsPlugin)
// ...
Run shell commands:
fn run_command(mut commands: Commands) {
commands.spawn(LocalCommand::new("bash").args(["-c", "sleep 1 && echo slept"]));
}
See commands started and kill running commands:
fn kill_started_command(mut active_processes: Query<&mut Process>) {
for mut process in active_processes.iter_mut() {
warn!("Killing process {}", process.id());
process.kill().unwrap();
}
}
Receive command output:
fn get_command_output(mut process_output_event: EventReader<ProcessOutput>) {
for output in process_output_event.read() {
info!("Output for command {:?}", output.entity);
for line in output.lines() {
info!("Line Output: {}", line);
}
}
}
Send command input:
fn send_command_input(
mut process_output_event: EventReader<ProcessOutput>,
mut active_processes: Query<&mut Process>,
) {
for output in process_output_event.read() {
for line in output.lines() {
if line.ends_with("Prompt String: ") {
let mut process = active_processes.get_mut(output.entity).unwrap();
process.println("Text to send").expect("Failed to write to process");
}
}
}
}
See commands completed:
fn get_completed(mut process_completed_event: EventReader<ProcessCompleted>) {
for completed in process_completed_event.read() {
info!(
"Command completed (Entity - {}, Success - {})",
completed.entity,
completed.exit_status.success()
);
}
}
Customize commands behaviour:
fn cleanup_on_completion(mut commands: Commands) {
commands.spawn((
LocalCommand::new("bash").args(["-c", "sleep 1 && echo slept"]),
// Also, Cleanup::RemoveComponent to remove Process and Cleanup components upon completion.
Cleanup::DespawnEntity
));
}
Todo
- Mac testing (not sure if it works yet)
Bevy Compatilibity
bevy | bevy_local_commands |
---|---|
0.13 | 0.5 |
0.12 | 0.4 |
0.11 | 0.1 |
Dependencies
~39–81MB
~1M SLoC