Skip to main content

Mountain/RPC/CocoonService/Terminal/
TerminalInput.rs

1#![allow(non_snake_case)]
2
3//! Forward bytes received from Cocoon to the PTY master writer.
4
5use tonic::{Response, Status};
6use CommonLibrary::Terminal::TerminalProvider::TerminalProvider;
7
8use crate::{
9	RPC::CocoonService::CocoonServiceImpl,
10	Vine::Generated::{Empty, TerminalInputRequest},
11	dev_log,
12};
13
14pub async fn Fn(Service:&CocoonServiceImpl, Request:TerminalInputRequest) -> Result<Response<Empty>, Status> {
15	let TerminalIdentifier = Request.terminal_id as u64;
16	dev_log!(
17		"cocoon",
18		"[CocoonService] terminal_input: id={} bytes={}",
19		TerminalIdentifier,
20		Request.data.len()
21	);
22
23	let Text = String::from_utf8_lossy(&Request.data).into_owned();
24
25	match Service.environment.SendTextToTerminal(TerminalIdentifier, Text).await {
26		Ok(()) => Ok(Response::new(Empty {})),
27		Err(Error) => {
28			dev_log!(
29				"cocoon",
30				"warn: [CocoonService] terminal_input failed id={}: {}",
31				TerminalIdentifier,
32				Error
33			);
34			Err(Status::not_found(format!("terminal_input: {}", Error)))
35		},
36	}
37}