Mountain/IPC/WindServiceHandlers/Terminal/TerminalDispose.rs
1
2//! Close a PTY, kill its child, and drop the entry from the
3//! provider's terminal registry. Idempotent - disposing an
4//! already-disposed id surfaces as a logged warning, not an
5//! error.
6
7use std::sync::Arc;
8
9use CommonLibrary::Terminal::TerminalProvider::TerminalProvider;
10use serde_json::Value;
11
12use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
13
14pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
15 let TerminalId = Arguments
16 .first()
17 .and_then(|V| V.as_u64())
18 .ok_or_else(|| "terminal:dispose requires terminal_id as first argument".to_string())?;
19
20 RunTime
21 .Environment
22 .DisposeTerminal(TerminalId)
23 .await
24 .map(|()| Value::Null)
25 .map_err(|Error| format!("terminal:dispose failed: {}", Error))
26}