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
17	dev_log!(
18		"cocoon",
19		"[CocoonService] terminal_input: id={} bytes={}",
20		TerminalIdentifier,
21		Request.data.len()
22	);
23
24	let Text = String::from_utf8_lossy(&Request.data).into_owned();
25
26	match Service.environment.SendTextToTerminal(TerminalIdentifier, Text).await {
27		Ok(()) => Ok(Response::new(Empty {})),
28
29		Err(Error) => {
30			dev_log!(
31				"cocoon",
32				"warn: [CocoonService] terminal_input failed id={}: {}",
33				TerminalIdentifier,
34				Error
35			);
36
37			Err(Status::not_found(format!("terminal_input: {}", Error)))
38		},
39	}
40}