Skip to main content

rusty_bubbletea/
exec.rs

1//! Cleanroom Rust port of upstream Go source file: `exec.go`
2//! Upstream Target Tag / Version: `v2.0.8`
3//!
4//! <public-docs>
5//! # Process Execution
6//!
7//! External process execution commands (`exec_process`) for spawning sub-shells and editors in Bubble Tea v2.0.8.
8//! </public-docs>
9
10use crate::model::{Cmd, Msg};
11
12/// Callback function type for ExecProcess.
13pub type ExecCallback = fn(Result<(), std::io::Error>) -> Option<Box<dyn Msg>>;
14
15/// ExecMsg is sent internally to trigger command execution.
16#[derive(Debug)]
17pub struct ExecMsg {
18    /// Command name.
19    pub cmd: String,
20    /// Command arguments.
21    pub args: Vec<String>,
22}
23
24/// ExecProcess spawns an external process (e.g. vim, htop) while pausing raw mode.
25pub fn exec_process(cmd: &str, args: &[&str]) -> Cmd {
26    let name = cmd.to_string();
27    let argv = args.iter().map(|s| s.to_string()).collect();
28    Some(Box::new(move || {
29        Some(Box::new(ExecMsg {
30            cmd: name,
31            args: argv,
32        }))
33    }))
34}