nvim_oxi_api/opts/
set_highlight.rs

1use types::Object;
2#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
3use types::{Boolean, Integer};
4
5#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
6#[derive(Clone, Debug, Default, PartialEq, macros::OptsBuilder)]
7#[repr(C)]
8pub struct SetHighlightOpts {
9    #[builder(mask)]
10    mask: u64,
11
12    #[builder(argtype = "bool")]
13    bold: Boolean,
14
15    #[builder(argtype = "bool")]
16    standout: Boolean,
17
18    #[builder(argtype = "bool")]
19    strikethrough: Boolean,
20
21    #[builder(argtype = "bool")]
22    underline: Boolean,
23
24    #[builder(argtype = "bool")]
25    undercurl: Boolean,
26
27    #[builder(argtype = "bool")]
28    underdouble: Boolean,
29
30    #[builder(argtype = "bool")]
31    underdotted: Boolean,
32
33    #[builder(argtype = "bool")]
34    underdashed: Boolean,
35
36    #[builder(argtype = "bool")]
37    italic: Boolean,
38
39    #[builder(argtype = "bool")]
40    reverse: Boolean,
41
42    #[builder(argtype = "bool")]
43    altfont: Boolean,
44
45    #[builder(argtype = "bool")]
46    nocombine: Boolean,
47
48    #[builder(method = "builder", argtype = "bool")]
49    // The field name is actually `default_`, but I think it somehow gets
50    // converted to `default` at build time because the correct mask index
51    // is obtained with `default`.
52    default: Boolean,
53
54    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
55    cterm: Object,
56
57    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
58    foreground: Object,
59
60    #[builder(skip)]
61    fg: Object,
62
63    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
64    background: Object,
65
66    #[builder(skip)]
67    bg: Object,
68
69    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
70    ctermfg: Object,
71
72    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
73    ctermbg: Object,
74
75    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
76    special: Object,
77
78    #[builder(skip)]
79    sp: Object,
80
81    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
82    link: Object,
83
84    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
85    global_link: Object,
86
87    #[builder(argtype = "bool")]
88    fallback: Boolean,
89
90    #[builder(argtype = "u8", inline = "{0} as Integer")]
91    blend: Integer,
92
93    #[builder(argtype = "bool")]
94    fg_indexed: Boolean,
95
96    #[builder(argtype = "bool")]
97    bg_indexed: Boolean,
98
99    #[builder(argtype = "bool")]
100    force: Boolean,
101}
102
103/// Options passed to [`set_hl()`](crate::set_hl).
104#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
105#[derive(Clone, Debug, Default, PartialEq)]
106#[repr(C)]
107pub struct SetHighlightOpts {
108    bg: Object,
109    fg: Object,
110    sp: Object,
111    bold: Object,
112    link: Object,
113    blend: Object,
114    cterm: Object,
115    italic: Object,
116    special: Object,
117    ctermbg: Object,
118    ctermfg: Object,
119    default: Object,
120    altfont: Object,
121    reverse: Object,
122    fallback: Object,
123    standout: Object,
124    nocombine: Object,
125    undercurl: Object,
126    underline: Object,
127    background: Object,
128    bg_indexed: Object,
129    foreground: Object,
130    fg_indexed: Object,
131    global_link: Object,
132    underdashed: Object,
133    underdotted: Object,
134    underdouble: Object,
135    strikethrough: Object,
136}
137
138#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
139impl SetHighlightOpts {
140    /// Creates a new [`SetHighlightOptsBuilder`].
141    #[inline]
142    pub fn builder() -> SetHighlightOptsBuilder {
143        <SetHighlightOptsBuilder as Default>::default()
144    }
145}
146
147#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
148#[derive(Clone, Default)]
149pub struct SetHighlightOptsBuilder(SetHighlightOpts);
150
151#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
152impl SetHighlightOptsBuilder {
153    #[inline]
154    pub fn background(&mut self, background: &str) -> &mut Self {
155        self.0.background = types::String::from(background).into();
156        self
157    }
158
159    #[inline]
160    pub fn blend(&mut self, blend: u8) -> &mut Self {
161        self.0.blend = blend.into();
162        self
163    }
164
165    #[inline]
166    pub fn bold(&mut self, bold: bool) -> &mut Self {
167        self.0.bold = bold.into();
168        self
169    }
170
171    #[inline]
172    pub fn cterm(&mut self, cterm: &str) -> &mut Self {
173        self.0.cterm = types::String::from(cterm).into();
174        self
175    }
176
177    #[inline]
178    pub fn ctermbg(&mut self, ctermbg: &str) -> &mut Self {
179        self.0.ctermbg = types::String::from(ctermbg).into();
180        self
181    }
182
183    #[inline]
184    pub fn ctermfg(&mut self, ctermfg: &str) -> &mut Self {
185        self.0.ctermfg = types::String::from(ctermfg).into();
186        self
187    }
188
189    #[inline]
190    pub fn default(&mut self, default: bool) -> &mut Self {
191        self.0.default = default.into();
192        self
193    }
194
195    #[inline]
196    pub fn fallback(&mut self, fallback: bool) -> &mut Self {
197        self.0.fallback = fallback.into();
198        self
199    }
200
201    #[inline]
202    pub fn foreground(&mut self, foreground: &str) -> &mut Self {
203        self.0.foreground = types::String::from(foreground).into();
204        self
205    }
206
207    #[inline]
208    pub fn global_link(&mut self, global_link: &str) -> &mut Self {
209        self.0.global_link = types::String::from(global_link).into();
210        self
211    }
212
213    #[inline]
214    pub fn italic(&mut self, italic: bool) -> &mut Self {
215        self.0.italic = italic.into();
216        self
217    }
218
219    #[inline]
220    pub fn link(&mut self, link: &str) -> &mut Self {
221        self.0.link = types::String::from(link).into();
222        self
223    }
224
225    #[inline]
226    pub fn nocombine(&mut self, nocombine: bool) -> &mut Self {
227        self.0.nocombine = nocombine.into();
228        self
229    }
230
231    #[inline]
232    pub fn reverse(&mut self, reverse: bool) -> &mut Self {
233        self.0.reverse = reverse.into();
234        self
235    }
236
237    #[inline]
238    pub fn special(&mut self, special: &str) -> &mut Self {
239        self.0.special = types::String::from(special).into();
240        self
241    }
242
243    #[inline]
244    pub fn standout(&mut self, standout: bool) -> &mut Self {
245        self.0.standout = standout.into();
246        self
247    }
248
249    #[inline]
250    pub fn strikethrough(&mut self, strikethrough: bool) -> &mut Self {
251        self.0.strikethrough = strikethrough.into();
252        self
253    }
254
255    #[inline]
256    pub fn undercurl(&mut self, undercurl: bool) -> &mut Self {
257        self.0.undercurl = undercurl.into();
258        self
259    }
260
261    #[inline]
262    pub fn underdashed(&mut self, underdashed: bool) -> &mut Self {
263        self.0.underdashed = underdashed.into();
264        self
265    }
266
267    #[inline]
268    pub fn underdotted(&mut self, underdotted: bool) -> &mut Self {
269        self.0.underdotted = underdotted.into();
270        self
271    }
272
273    #[inline]
274    pub fn underdouble(&mut self, underdouble: bool) -> &mut Self {
275        self.0.underdouble = underdouble.into();
276        self
277    }
278
279    #[inline]
280    pub fn underline(&mut self, underline: bool) -> &mut Self {
281        self.0.underline = underline.into();
282        self
283    }
284
285    #[inline]
286    pub fn altfont(&mut self, altfont: bool) -> &mut Self {
287        self.0.altfont = altfont.into();
288        self
289    }
290
291    #[inline]
292    pub fn bg_indexed(&mut self, bg_indexed: bool) -> &mut Self {
293        self.0.bg_indexed = bg_indexed.into();
294        self
295    }
296
297    #[inline]
298    pub fn fg_indexed(&mut self, fg_indexed: bool) -> &mut Self {
299        self.0.fg_indexed = fg_indexed.into();
300        self
301    }
302
303    #[inline]
304    pub fn build(&mut self) -> SetHighlightOpts {
305        std::mem::take(&mut self.0)
306    }
307}