1use nvim_types::{self as nvim, conversion::FromObject};
2
3use crate::choose;
4use crate::ffi::win_config::*;
5use crate::types::*;
6use crate::Result;
7use crate::{Buffer, Window};
8
9pub fn open_win(
13 buf: &Buffer,
14 enter: bool,
15 config: &WindowConfig,
16) -> Result<Window> {
17 let mut err = nvim::Error::new();
18 let handle =
19 unsafe { nvim_open_win(buf.0, enter, &config.into(), &mut err) };
20 choose!(err, Ok(handle.into()))
21}
22
23impl Window {
24 pub fn get_config(&self) -> Result<WindowConfig> {
28 let mut err = nvim::Error::new();
29 let mut dict = unsafe { nvim_win_get_config(self.0, &mut err) };
30 let win = dict.get(&"win").map(|obj| unsafe {
31 obj.as_integer_unchecked() as i32
34 });
35 if let Some(handle) = win {
36 dict["relative"] = handle.into();
37 }
38 choose!(err, Ok(WindowConfig::from_object(dict.into())?))
39 }
40
41 pub fn set_config(&mut self, config: &WindowConfig) -> Result<()> {
45 let mut err = nvim::Error::new();
46 unsafe { nvim_win_set_config(self.0, &config.into(), &mut err) };
47 choose!(err, ())
48 }
49}