Skip to main content

Mountain/IPC/WindServiceHandlers/Terminal/
TerminalSendText.rs

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