Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/Terminal/
OpenTerminal.rs

1//! Spawn a new PTY via `TerminalProvider::CreateTerminal`. Builds the
2//! options JSON `TerminalStateDTO::Create` expects (name + shellPath +
3//! shellArgs + cwd) and forwards through.
4
5use serde_json::json;
6use tonic::{Response, Status};
7use CommonLibrary::Terminal::TerminalProvider::TerminalProvider;
8
9use crate::{
10	RPC::CocoonService::CocoonServiceImpl,
11	Vine::Generated::{Empty, OpenTerminalRequest},
12	dev_log,
13};
14
15pub async fn Fn(Service:&CocoonServiceImpl, Request:OpenTerminalRequest) -> Result<Response<Empty>, Status> {
16	dev_log!("cocoon", "[CocoonService] Opening terminal: {}", Request.name);
17
18	let Options = json!({
19		"name": Request.name,
20		"shellPath": if Request.shell_path.is_empty() { serde_json::Value::Null } else { json!(Request.shell_path) },
21		"shellArgs": Request.shell_args,
22		"cwd": if Request.cwd.is_empty() { serde_json::Value::Null } else { json!(Request.cwd) },
23	});
24
25	match Service.environment.CreateTerminal(Options).await {
26		Ok(Info) => {
27			dev_log!("cocoon", "[CocoonService] Terminal created: {:?}", Info);
28
29			Ok(Response::new(Empty {}))
30		},
31
32		Err(Error) => {
33			dev_log!("cocoon", "error: [CocoonService] open_terminal failed: {}", Error);
34
35			Err(Status::internal(format!("open_terminal: {}", Error)))
36		},
37	}
38}