nvim_rs/exttypes/
tabpage.rs

1use futures::io::AsyncWrite;
2use rmpv::Value;
3
4use crate::{
5  error::CallError, exttypes::Window, impl_exttype_traits, rpc::model::IntoVal,
6  Neovim,
7};
8
9/// A struct representing a neovim tabpage. It is specific to a
10/// [`Neovim`](crate::neovim::Neovim) instance, and calling a method on it will
11/// always use this instance.
12pub struct Tabpage<W>
13where
14  W: AsyncWrite + Send + Unpin + 'static,
15{
16  pub(crate) code_data: Value,
17  pub(crate) neovim: Neovim<W>,
18}
19
20impl_exttype_traits!(Tabpage);
21
22impl<W> Tabpage<W>
23where
24  W: AsyncWrite + Send + Unpin + 'static,
25{
26  /// since: 1
27  pub async fn list_wins(&self) -> Result<Vec<Window<W>>, Box<CallError>> {
28    match self
29      .neovim
30      .call("nvim_tabpage_list_wins", call_args![self.code_data.clone()])
31      .await??
32    {
33      Value::Array(arr) => Ok(
34        arr
35          .into_iter()
36          .map(|v| Window::new(v, self.neovim.clone()))
37          .collect(),
38      ),
39      val => Err(CallError::WrongValueType(val))?,
40    }
41  }
42  /// since: 1
43  pub async fn get_win(&self) -> Result<Window<W>, Box<CallError>> {
44    Ok(
45      self
46        .neovim
47        .call("nvim_tabpage_get_win", call_args![self.code_data.clone()])
48        .await?
49        .map(|val| Window::new(val, self.neovim.clone()))?,
50    )
51  }
52}