zellij_utils/plugin_api/
input_mode.rs1pub use super::generated_api::api::input_mode::{
2 InputMode as ProtobufInputMode, InputModeMessage as ProtobufInputModeMessage,
3};
4use crate::data::InputMode;
5
6use std::convert::TryFrom;
7
8impl TryFrom<ProtobufInputMode> for InputMode {
9 type Error = &'static str;
10 fn try_from(protobuf_input_mode: ProtobufInputMode) -> Result<Self, &'static str> {
11 match protobuf_input_mode {
12 ProtobufInputMode::Normal => Ok(InputMode::Normal),
13 ProtobufInputMode::Locked => Ok(InputMode::Locked),
14 ProtobufInputMode::Resize => Ok(InputMode::Resize),
15 ProtobufInputMode::Pane => Ok(InputMode::Pane),
16 ProtobufInputMode::Tab => Ok(InputMode::Tab),
17 ProtobufInputMode::Scroll => Ok(InputMode::Scroll),
18 ProtobufInputMode::EnterSearch => Ok(InputMode::EnterSearch),
19 ProtobufInputMode::Search => Ok(InputMode::Search),
20 ProtobufInputMode::RenameTab => Ok(InputMode::RenameTab),
21 ProtobufInputMode::RenamePane => Ok(InputMode::RenamePane),
22 ProtobufInputMode::Session => Ok(InputMode::Session),
23 ProtobufInputMode::Move => Ok(InputMode::Move),
24 ProtobufInputMode::Prompt => Ok(InputMode::Prompt),
25 ProtobufInputMode::Tmux => Ok(InputMode::Tmux),
26 }
27 }
28}
29
30impl TryFrom<InputMode> for ProtobufInputMode {
31 type Error = &'static str;
32 fn try_from(input_mode: InputMode) -> Result<Self, &'static str> {
33 Ok(match input_mode {
34 InputMode::Normal => ProtobufInputMode::Normal,
35 InputMode::Locked => ProtobufInputMode::Locked,
36 InputMode::Resize => ProtobufInputMode::Resize,
37 InputMode::Pane => ProtobufInputMode::Pane,
38 InputMode::Tab => ProtobufInputMode::Tab,
39 InputMode::Scroll => ProtobufInputMode::Scroll,
40 InputMode::EnterSearch => ProtobufInputMode::EnterSearch,
41 InputMode::Search => ProtobufInputMode::Search,
42 InputMode::RenameTab => ProtobufInputMode::RenameTab,
43 InputMode::RenamePane => ProtobufInputMode::RenamePane,
44 InputMode::Session => ProtobufInputMode::Session,
45 InputMode::Move => ProtobufInputMode::Move,
46 InputMode::Prompt => ProtobufInputMode::Prompt,
47 InputMode::Tmux => ProtobufInputMode::Tmux,
48 })
49 }
50}
51
52impl TryFrom<ProtobufInputModeMessage> for InputMode {
53 type Error = &'static str;
54 fn try_from(protobuf_input_mode: ProtobufInputModeMessage) -> Result<Self, &'static str> {
55 ProtobufInputMode::from_i32(protobuf_input_mode.input_mode)
56 .and_then(|p| p.try_into().ok())
57 .ok_or("Invalid input mode")
58 }
59}
60
61impl TryFrom<InputMode> for ProtobufInputModeMessage {
62 type Error = &'static str;
63 fn try_from(input_mode: InputMode) -> Result<Self, &'static str> {
64 let protobuf_input_mode: ProtobufInputMode = input_mode.try_into()?;
65 Ok(ProtobufInputModeMessage {
66 input_mode: protobuf_input_mode as i32,
67 })
68 }
69}