use oxi_types::Object;
use crate::ToFunction;
use crate::{Buffer, Window};
pub type OnBufArgs = (
String, Buffer, );
pub type OnEndArgs = (
String, u32, );
pub type OnLineArgs = (
String, Window, Buffer, usize, );
pub type OnStartArgs = (
String, u32, u32,
);
pub type OnWinArgs = (
String, Window, Buffer, u32, u32, );
pub type DontSkipRedrawCycle = bool;
pub type DontSkipOnLines = bool;
#[cfg(not(feature = "neovim-nightly"))]
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub struct DecorationProviderOpts {
on_buf: Object,
on_end: Object,
on_win: Object,
on_line: Object,
on_start: Object,
_on_hl_def: Object,
_on_spell_nav: Object,
}
#[cfg(feature = "neovim-nightly")]
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub struct DecorationProviderOpts {
on_start: Object,
on_buf: Object,
on_win: Object,
on_line: Object,
on_end: Object,
_on_hl_def: Object,
_on_spell_nav: Object,
}
impl DecorationProviderOpts {
#[inline(always)]
pub fn builder() -> DecorationProviderOptsBuilder {
DecorationProviderOptsBuilder::default()
}
}
#[derive(Clone, Default)]
pub struct DecorationProviderOptsBuilder(DecorationProviderOpts);
impl DecorationProviderOptsBuilder {
#[inline]
pub fn on_buf<F>(&mut self, fun: F) -> &mut Self
where
F: ToFunction<OnBufArgs, ()>,
{
self.0.on_buf = Object::from_luaref(fun.into_luaref());
self
}
#[inline]
pub fn on_end<F>(&mut self, fun: F) -> &mut Self
where
F: ToFunction<OnEndArgs, ()>,
{
self.0.on_end = Object::from_luaref(fun.into_luaref());
self
}
#[inline]
pub fn on_line<F>(&mut self, fun: F) -> &mut Self
where
F: ToFunction<OnLineArgs, ()>,
{
self.0.on_line = Object::from_luaref(fun.into_luaref());
self
}
#[inline]
pub fn on_start<F>(&mut self, fun: F) -> &mut Self
where
F: ToFunction<OnStartArgs, DontSkipRedrawCycle>,
{
self.0.on_start = Object::from_luaref(fun.into_luaref());
self
}
#[inline]
pub fn on_win<F>(&mut self, fun: F) -> &mut Self
where
F: ToFunction<OnWinArgs, DontSkipOnLines>,
{
self.0.on_win = Object::from_luaref(fun.into_luaref());
self
}
#[inline]
pub fn build(&mut self) -> DecorationProviderOpts {
std::mem::take(&mut self.0)
}
}