use oxi_types as types;
use crate::Buffer;
use crate::ToFunction;
pub type OnLinesArgs = (
String,
Buffer,
u32,
usize,
usize,
usize,
usize,
Option<usize>,
Option<usize>,
);
pub type OnBytesArgs = (
String,
Buffer,
u32,
usize,
usize,
usize,
usize,
usize,
usize,
usize,
usize,
usize,
);
pub type OnChangedtickArgs = (String, Buffer, u32);
pub type OnDetachArgs = (String, Buffer);
pub type OnReloadArgs = (String, Buffer);
pub type ShouldDetach = bool;
#[cfg(not(feature = "neovim-nightly"))]
#[derive(Clone, Debug, Default)]
pub struct BufAttachOpts {
on_bytes: types::Object,
on_changedtick: types::Object,
on_detach: types::Object,
on_lines: types::Object,
on_reload: types::Object,
preview: types::Object,
utf_sizes: types::Object,
}
#[cfg(not(feature = "neovim-nightly"))]
impl BufAttachOpts {
#[inline(always)]
pub fn builder() -> BufAttachOptsBuilder {
BufAttachOptsBuilder::default()
}
}
#[cfg(not(feature = "neovim-nightly"))]
#[derive(Clone, Default)]
pub struct BufAttachOptsBuilder(BufAttachOpts);
#[cfg(not(feature = "neovim-nightly"))]
impl BufAttachOptsBuilder {
#[inline]
pub fn on_bytes<F>(&mut self, on_bytes: F) -> &mut Self
where
F: ToFunction<OnBytesArgs, ShouldDetach>,
{
self.0.on_bytes = types::Object::from_luaref(on_bytes.into_luaref());
self
}
#[inline]
pub fn on_changedtick<F>(&mut self, on_changedtick: F) -> &mut Self
where
F: ToFunction<OnChangedtickArgs, ShouldDetach>,
{
self.0.on_changedtick =
types::Object::from_luaref(on_changedtick.into_luaref());
self
}
#[inline]
pub fn on_detach<F>(&mut self, on_detach: F) -> &mut Self
where
F: ToFunction<OnDetachArgs, ShouldDetach>,
{
self.0.on_detach = types::Object::from_luaref(on_detach.into_luaref());
self
}
#[inline]
pub fn on_lines<F>(&mut self, fun: F) -> &mut Self
where
F: ToFunction<OnLinesArgs, ShouldDetach>,
{
self.0.on_lines = types::Object::from_luaref(fun.into_luaref());
self
}
#[inline]
pub fn on_reload<F>(&mut self, on_reload: F) -> &mut Self
where
F: ToFunction<OnReloadArgs, ShouldDetach>,
{
self.0.on_reload = types::Object::from_luaref(on_reload.into_luaref());
self
}
#[inline]
pub fn preview(&mut self, preview: bool) -> &mut Self {
self.0.preview = preview.into();
self
}
#[inline]
pub fn utf_sizes(&mut self, utf_sizes: bool) -> &mut Self {
self.0.utf_sizes = utf_sizes.into();
self
}
#[inline]
pub fn build(&mut self) -> BufAttachOpts {
std::mem::take(&mut self.0)
}
}
#[cfg(not(feature = "neovim-nightly"))]
impl From<&BufAttachOpts> for types::Dictionary {
#[inline]
fn from(opts: &BufAttachOpts) -> Self {
Self::from_iter([
("on_bytes", opts.on_bytes.clone()),
("on_changedtick", opts.on_changedtick.clone()),
("on_detach", opts.on_detach.clone()),
("on_lines", opts.on_lines.clone()),
("on_reload", opts.on_reload.clone()),
("preview", opts.preview.clone()),
("utf_sizes", opts.utf_sizes.clone()),
])
}
}
#[cfg(feature = "neovim-nightly")]
#[derive(Clone, Debug, Default, oxi_macros::OptsBuilder)]
#[repr(C)]
pub struct BufAttachOpts {
#[builder(mask)]
mask: u64,
#[builder(
generics = "F: ToFunction<OnBytesArgs, ShouldDetach>",
argtype = "F",
inline = "{0}.into_luaref()"
)]
on_bytes: types::LuaRef,
#[builder(
generics = "F: ToFunction<OnChangedtickArgs, ShouldDetach>",
argtype = "F",
inline = "{0}.into_luaref()"
)]
on_changedtick: types::LuaRef,
#[builder(
generics = "F: ToFunction<OnDetachArgs, ShouldDetach>",
argtype = "F",
inline = "{0}.into_luaref()"
)]
on_detach: types::LuaRef,
#[builder(
generics = "F: ToFunction<OnLinesArgs, ShouldDetach>",
argtype = "F",
inline = "{0}.into_luaref()"
)]
on_lines: types::LuaRef,
#[builder(
generics = "F: ToFunction<OnReloadArgs, ShouldDetach>",
argtype = "F",
inline = "{0}.into_luaref()"
)]
on_reload: types::LuaRef,
#[builder(argtype = "bool")]
preview: types::Boolean,
#[builder(argtype = "bool")]
utf_sizes: types::Boolean,
}