nvim_api/opts/
decoration_provider.rs1use derive_builder::Builder;
2use nvim_types::{Dictionary, Object};
3
4use crate::ToFunction;
5use crate::{Buffer, Window};
6
7pub type OnBufArgs = (
11 String, Buffer, );
14
15pub type OnEndArgs = (
18 String, u32, );
21
22pub type OnLineArgs = (
25 String, Window, Buffer, usize, );
30
31pub type OnStartArgs = (
34 String, u32, u32, );
38
39pub type OnWinArgs = (
42 String, Window, Buffer, u32, u32, );
48
49pub type DontSkipRedrawCycle = bool;
52
53pub type DontSkipOnLines = bool;
56
57#[derive(Clone, Debug, Default, Builder)]
60#[builder(default, build_fn(private, name = "fallible_build"))]
61pub struct DecorationProviderOpts {
62 #[builder(setter(custom))]
63 on_buf: Object,
64
65 #[builder(setter(custom))]
66 on_end: Object,
67
68 #[builder(setter(custom))]
69 on_line: Object,
70
71 #[builder(setter(custom))]
72 on_start: Object,
73
74 #[builder(setter(custom))]
75 on_win: Object,
76}
77
78impl DecorationProviderOpts {
79 #[inline(always)]
80 pub fn builder() -> DecorationProviderOptsBuilder {
82 DecorationProviderOptsBuilder::default()
83 }
84}
85
86impl DecorationProviderOptsBuilder {
87 pub fn on_buf<F>(&mut self, fun: F) -> &mut Self
88 where
89 F: ToFunction<OnBufArgs, ()>,
90 {
91 self.on_buf = Some(fun.to_object());
92 self
93 }
94
95 pub fn on_end<F>(&mut self, fun: F) -> &mut Self
96 where
97 F: ToFunction<OnEndArgs, ()>,
98 {
99 self.on_end = Some(fun.to_object());
100 self
101 }
102
103 pub fn on_line<F>(&mut self, fun: F) -> &mut Self
104 where
105 F: ToFunction<OnLineArgs, ()>,
106 {
107 self.on_line = Some(fun.to_object());
108 self
109 }
110
111 pub fn on_start<F>(&mut self, fun: F) -> &mut Self
112 where
113 F: ToFunction<OnStartArgs, DontSkipRedrawCycle>,
114 {
115 self.on_start = Some(fun.to_object());
116 self
117 }
118
119 pub fn on_win<F>(&mut self, fun: F) -> &mut Self
120 where
121 F: ToFunction<OnWinArgs, DontSkipOnLines>,
122 {
123 self.on_win = Some(fun.to_object());
124 self
125 }
126
127 pub fn build(&mut self) -> DecorationProviderOpts {
128 self.fallible_build().expect("never fails, all fields have defaults")
129 }
130}
131
132impl From<&DecorationProviderOpts> for Dictionary {
133 fn from(opts: &DecorationProviderOpts) -> Self {
134 Self::from_iter([
135 ("on_buf", opts.on_buf.clone()),
136 ("on_end", opts.on_end.clone()),
137 ("on_line", opts.on_line.clone()),
138 ("on_start", opts.on_start.clone()),
139 ("on_win", opts.on_win.clone()),
140 ])
141 }
142}