Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/Terminal/
TerminalInput.rs

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