nvim_api/types/
channel_infos.rs

1use nvim_types::{
2    conversion::{self, FromObject},
3    serde::Deserializer,
4    Object,
5};
6use serde::Deserialize;
7
8use super::ClientInfos;
9use crate::Buffer;
10
11#[non_exhaustive]
12#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
13pub struct ChannelInfos {
14    /// Job arguments list.
15    pub argv: Option<Vec<String>>,
16
17    /// Buffer with connected terminal instance. Only present when `mode` is
18    /// `ChannelMode::Terminal`.
19    pub buffer: Option<Buffer>,
20
21    /// Info about the client on the other side of an RPC channel. Only present
22    /// when `mode` is `ChannelMode::Rpc`.
23    pub client: Option<ClientInfos>,
24
25    /// Channel id.
26    pub id: u32,
27
28    /// How data receiveed on the channel is interpeted.
29    pub mode: ChannelMode,
30
31    /// Name of a pseudoterminal. On a POSIX system this is a device path like
32    /// `/dev/pts/1`. If the name is unknown, the key will still be present if
33    /// a pty is used (e.g. for `ConPTY` on Windows).
34    pub pty: Option<String>,
35
36    /// Stream underlying the channel.
37    pub stream: ChannelStream,
38}
39
40#[non_exhaustive]
41#[derive(Clone, Debug, Eq, PartialEq, Hash, Deserialize)]
42#[serde(rename_all = "lowercase")]
43pub enum ChannelStream {
44    Job,
45    Socket,
46    StdErr,
47    StdIo,
48}
49
50#[non_exhaustive]
51#[derive(Clone, Debug, Eq, PartialEq, Hash, Deserialize)]
52#[serde(rename_all = "lowercase")]
53pub enum ChannelMode {
54    Bytes,
55    Rpc,
56    Terminal,
57}
58
59impl FromObject for ChannelInfos {
60    fn from_object(obj: Object) -> Result<Self, conversion::Error> {
61        Self::deserialize(Deserializer::new(obj)).map_err(Into::into)
62    }
63}