par_term/terminal/
spawn.rs1use super::TerminalManager;
2use anyhow::Result;
3
4impl TerminalManager {
5 #[allow(dead_code)]
7 pub fn spawn_shell(&mut self) -> Result<()> {
8 log::info!("Spawning shell in PTY");
9 let mut pty = self.pty_session.lock();
10 pty.spawn_shell()
11 .map_err(|e| anyhow::anyhow!("Failed to spawn shell: {}", e))?;
12 Ok(())
13 }
14
15 #[allow(dead_code)]
20 pub fn spawn_custom_shell(&mut self, command: &str) -> Result<()> {
21 log::info!("Spawning custom shell: {}", command);
22 let mut pty = self.pty_session.lock();
23 let args: Vec<&str> = Vec::new();
24 pty.spawn(command, &args)
25 .map_err(|e| anyhow::anyhow!("Failed to spawn custom shell: {}", e))?;
26 Ok(())
27 }
28
29 #[allow(dead_code)]
35 pub fn spawn_custom_shell_with_args(&mut self, command: &str, args: &[String]) -> Result<()> {
36 log::info!("Spawning custom shell: {} with args: {:?}", command, args);
37 let mut pty = self.pty_session.lock();
38 let args_refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
39 pty.spawn(command, &args_refs)
40 .map_err(|e| anyhow::anyhow!("Failed to spawn custom shell: {}", e))?;
41 Ok(())
42 }
43
44 #[allow(dead_code)]
50 pub fn spawn_shell_with_dir(
51 &mut self,
52 working_dir: Option<&str>,
53 env_vars: Option<&std::collections::HashMap<String, String>>,
54 ) -> Result<()> {
55 log::info!(
56 "Spawning shell with dir: {:?}, env: {:?}",
57 working_dir,
58 env_vars
59 );
60 let mut pty = self.pty_session.lock();
61 pty.spawn_shell_with_env(env_vars, working_dir)
62 .map_err(|e| anyhow::anyhow!("Failed to spawn shell with env: {}", e))
63 }
64
65 pub fn spawn_custom_shell_with_dir(
73 &mut self,
74 command: &str,
75 args: Option<&[String]>,
76 working_dir: Option<&str>,
77 env_vars: Option<&std::collections::HashMap<String, String>>,
78 ) -> Result<()> {
79 log::info!(
80 "Spawning custom shell: {} with dir: {:?}, env: {:?}",
81 command,
82 working_dir,
83 env_vars
84 );
85
86 let args_refs: Vec<&str> = args
87 .map(|a| a.iter().map(|s| s.as_str()).collect())
88 .unwrap_or_default();
89
90 let mut pty = self.pty_session.lock();
91 pty.spawn_with_env(command, &args_refs, env_vars, working_dir)
92 .map_err(|e| anyhow::anyhow!("Failed to spawn custom shell with env: {}", e))
93 }
94}