par_term_terminal/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)]
17 pub fn spawn_custom_shell(&mut self, command: &str) -> Result<()> {
18 log::info!("Spawning custom shell: {}", command);
19 let mut pty = self.pty_session.lock();
20 let args: Vec<&str> = Vec::new();
21 pty.spawn(command, &args)
22 .map_err(|e| anyhow::anyhow!("Failed to spawn custom shell: {}", e))?;
23 Ok(())
24 }
25
26 #[allow(dead_code)]
28 pub fn spawn_custom_shell_with_args(&mut self, command: &str, args: &[String]) -> Result<()> {
29 log::info!("Spawning custom shell: {} with args: {:?}", command, args);
30 let mut pty = self.pty_session.lock();
31 let args_refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
32 pty.spawn(command, &args_refs)
33 .map_err(|e| anyhow::anyhow!("Failed to spawn custom shell: {}", e))?;
34 Ok(())
35 }
36
37 #[allow(dead_code)]
39 pub fn spawn_shell_with_dir(
40 &mut self,
41 working_dir: Option<&str>,
42 env_vars: Option<&std::collections::HashMap<String, String>>,
43 ) -> Result<()> {
44 log::info!(
45 "Spawning shell with dir: {:?}, env: {:?}",
46 working_dir,
47 env_vars
48 );
49 let mut pty = self.pty_session.lock();
50 pty.spawn_shell_with_env(env_vars, working_dir)
51 .map_err(|e| anyhow::anyhow!("Failed to spawn shell with env: {}", e))
52 }
53
54 pub fn spawn_custom_shell_with_dir(
56 &mut self,
57 command: &str,
58 args: Option<&[String]>,
59 working_dir: Option<&str>,
60 env_vars: Option<&std::collections::HashMap<String, String>>,
61 ) -> Result<()> {
62 log::info!(
63 "Spawning custom shell: {} with dir: {:?}, env: {:?}",
64 command,
65 working_dir,
66 env_vars
67 );
68
69 let args_refs: Vec<&str> = args
70 .map(|a| a.iter().map(|s| s.as_str()).collect())
71 .unwrap_or_default();
72
73 let mut pty = self.pty_session.lock();
74 pty.spawn_with_env(command, &args_refs, env_vars, working_dir)
75 .map_err(|e| anyhow::anyhow!("Failed to spawn custom shell with env: {}", e))
76 }
77}