Common/Terminal/
CreateTerminal.rs

1// File: Common/Source/Terminal/CreateTerminal.rs
2// Role: Defines the `CreateTerminal` ActionEffect.
3// Responsibilities:
4//   - Provide a declarative effect for creating a new integrated terminal
5//     instance.
6//   - This effect abstracts the "what" (create a terminal) from the "how" (the
7//     TerminalProvider implementation).
8
9//! # CreateTerminal Effect
10//!
11//! Defines the `ActionEffect` for creating a new integrated terminal instance.
12
13use std::sync::Arc;
14
15use serde_json::Value;
16
17use super::TerminalProvider::TerminalProvider;
18use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
19
20/// Creates an effect that, when executed, will create a new terminal instance
21/// based on the provided options.
22///
23/// The effect will use the `TerminalProvider` capability from the environment
24/// to perform the actual creation, which typically involves spawning a new
25/// pseudo-terminal (PTY) process.
26///
27/// # Parameters
28/// * `OptionsValue`: A `serde_json::Value` representing the `TerminalOptions`
29///   DTO, containing properties like the name, shell path, and arguments for
30///   the terminal.
31///
32/// # Returns
33/// An `ActionEffect` that resolves with a JSON `Value` containing details of
34/// the newly created terminal, such as its ID and process ID (PID).
35pub fn CreateTerminal(OptionsValue:Value) -> ActionEffect<Arc<dyn TerminalProvider>, CommonError, Value> {
36	ActionEffect::New(Arc::new(move |Provider:Arc<dyn TerminalProvider>| {
37		let OptionsClone = OptionsValue.clone();
38
39		Box::pin(async move { Provider.CreateTerminal(OptionsClone).await })
40	}))
41}