1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use oxi_types::{self as nvim, conversion::FromObject};
use crate::choose;
use crate::ffi::win_config::*;
use crate::types::*;
use crate::Result;
use crate::{Buffer, Window};
/// Binding to [`nvim_open_win()`][1].
///
/// Opens a new floating or external window.
///
/// [1]: https://neovim.io/doc/user/api.html#nvim_open_win()
pub fn open_win(
buf: &Buffer,
enter: bool,
config: &WindowConfig,
) -> Result<Window> {
let mut err = nvim::Error::new();
let handle =
unsafe { nvim_open_win(buf.0, enter, &config.into(), &mut err) };
choose!(err, Ok(handle.into()))
}
impl Window {
/// Binding to [`nvim_win_get_config()`][1].
///
/// Gets the window configuration.
///
/// [1]: https://neovim.io/doc/user/api.html#nvim_win_get_config()
pub fn get_config(&self) -> Result<WindowConfig> {
let mut err = nvim::Error::new();
let mut dict = unsafe { nvim_win_get_config(self.0, &mut err) };
let win = dict.get("win").map(|obj| unsafe {
// SAFETY: if the `win` key is present it's set to an integer
// representing a window handle.
obj.as_integer_unchecked() as i32
});
if let Some(handle) = win {
dict["relative"] = handle.into();
}
choose!(err, Ok(WindowConfig::from_object(dict.into())?))
}
/// Binding to [`nvim_win_get_config()`][1].
///
/// Configures the window layout. Only for floating and external windows.
///
/// [1]: https://neovim.io/doc/user/api.html#nvim_win_get_config()
pub fn set_config(&mut self, config: &WindowConfig) -> Result<()> {
let mut err = nvim::Error::new();
unsafe { nvim_win_set_config(self.0, &config.into(), &mut err) };
choose!(err, ())
}
}