Mountain/ApplicationState/DTO/
TerminalStateDTO.rs1#![allow(non_snake_case, non_camel_case_types)]
7
8use std::{collections::HashMap, path::PathBuf, sync::Arc};
9
10use serde_json::Value;
11use tokio::{
12 sync::{Mutex as TokioMutex, mpsc as TokioMPSC},
13 task::JoinHandle,
14};
15
16#[derive(Debug, Clone)]
20pub struct TerminalStateDTO {
21 pub Identifier:u64,
23
24 pub Name:String,
25
26 pub OSProcessIdentifier:Option<u32>,
27
28 pub ShellPath:String,
30
31 pub ShellArguments:Vec<String>,
32
33 pub CurrentWorkingDirectory:Option<PathBuf>,
34
35 pub EnvironmentVariables:Option<HashMap<String, Option<String>>>,
36
37 pub IsPTY:bool,
38
39 pub PTYInputTransmitter:Option<TokioMPSC::Sender<String>>,
41
42 pub ReaderTaskHandle:Option<Arc<TokioMutex<Option<JoinHandle<()>>>>>,
43
44 pub ProcessWaitHandle:Option<Arc<TokioMutex<Option<JoinHandle<()>>>>>,
45}
46
47impl TerminalStateDTO {
48 pub fn Create(Identifier:u64, Name:String, OptionsValue:&Value, DefaultShellPath:String) -> Self {
51 let ShellPath = OptionsValue
52 .get("shellPath")
53 .and_then(Value::as_str)
54 .unwrap_or(&DefaultShellPath)
55 .to_string();
56
57 let ShellArguments = match OptionsValue.get("shellArgs") {
58 Some(Value::Array(Array)) => Array.iter().filter_map(Value::as_str).map(String::from).collect(),
59
60 _ => Vec::new(),
61 };
62
63 let CWD = OptionsValue.get("cwd").and_then(Value::as_str).map(PathBuf::from);
64
65 let EnvVars = None;
67
68 Self {
69 Identifier,
70
71 Name,
72
73 ShellPath,
74
75 ShellArguments,
76
77 CurrentWorkingDirectory:CWD,
78
79 EnvironmentVariables:EnvVars,
80
81 OSProcessIdentifier:None,
82
83 IsPTY:true,
85
86 PTYInputTransmitter:None,
87
88 ReaderTaskHandle:None,
89
90 ProcessWaitHandle:None,
91 }
92 }
93}