DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Terminal/TerminalSendText.rs
1//! Pipe text into a terminal's PTY stdin. Used both for direct
2//! key forwarding (xterm.js → Mountain → PTY) and for
3//! programmatic input (`vscode.window.terminals[…].sendText`).
4
5use std::sync::Arc;
6
7use CommonLibrary::Terminal::TerminalProvider::TerminalProvider;
8use serde_json::Value;
9
10use crate::{
11 IPC::WindServiceHandlers::Utilities::JsonValueHelpers::arg_string,
12 RunTime::ApplicationRunTime::ApplicationRunTime,
13};
14
15pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
16 let TerminalId = Arguments
17 .first()
18 .and_then(|V| V.as_u64())
19 .ok_or_else(|| "terminal:sendText requires terminal_id as first argument".to_string())?;
20
21 let Text = arg_string(&Arguments, 1);
22
23 RunTime
24 .Environment
25 .SendTextToTerminal(TerminalId, Text)
26 .await
27 .map(|()| Value::Null)
28 .map_err(|Error| format!("terminal:sendText failed: {}", Error))
29}