1use std::fmt::Display;
2
3use tokio::{sync::mpsc::Sender, task::JoinHandle};
4
5use crate::{Action, Input, proto};
6
7#[derive(Clone)]
11pub struct Menu {
12 pub(crate) sender: Sender<Result<proto::ActivationResponse, tonic::Status>>,
13}
14
15impl Menu {
16 fn send_action(&self, action: Action) -> JoinHandle<()> {
17 let sender = self.sender.clone();
18 tokio::spawn(async move {
19 _ = sender
20 .send(Ok(proto::ActivationResponse {
21 action: action.into_proto(),
22 }))
23 .await
24 })
25 }
26
27 pub fn close(&self) -> JoinHandle<()> {
28 self.send_action(Action::close())
29 }
30
31 pub fn copy(&self, str: impl Into<String>) -> JoinHandle<()> {
32 self.send_action(Action::copy(str))
33 }
34
35 pub fn set_input(&self, input: impl Into<Input>) -> JoinHandle<()> {
36 self.send_action(Action::set_input(input))
37 }
38
39 pub fn display_error(&self, err: impl Display) -> JoinHandle<()> {
40 self.send_action(Action::display_error(err))
41 }
42}