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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
use types::Object;
#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
use types::{Boolean, Integer};

#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
#[derive(Clone, Debug, Default, PartialEq, macros::OptsBuilder)]
#[repr(C)]
pub struct SetHighlightOpts {
    #[builder(mask)]
    mask: u64,

    #[builder(argtype = "bool")]
    bold: Boolean,

    #[builder(argtype = "bool")]
    standout: Boolean,

    #[builder(argtype = "bool")]
    strikethrough: Boolean,

    #[builder(argtype = "bool")]
    underline: Boolean,

    #[builder(argtype = "bool")]
    undercurl: Boolean,

    #[builder(argtype = "bool")]
    underdouble: Boolean,

    #[builder(argtype = "bool")]
    underdotted: Boolean,

    #[builder(argtype = "bool")]
    underdashed: Boolean,

    #[builder(argtype = "bool")]
    italic: Boolean,

    #[builder(argtype = "bool")]
    reverse: Boolean,

    #[builder(argtype = "bool")]
    altfont: Boolean,

    #[builder(argtype = "bool")]
    nocombine: Boolean,

    #[builder(method = "builder", argtype = "bool")]
    // The field name is actually `default_`, but I think it somehow gets
    // converted to `default` at build time because the correct mask index
    // is obtained with `default`.
    default: Boolean,

    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
    cterm: Object,

    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
    foreground: Object,

    #[builder(skip)]
    fg: Object,

    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
    background: Object,

    #[builder(skip)]
    bg: Object,

    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
    ctermfg: Object,

    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
    ctermbg: Object,

    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
    special: Object,

    #[builder(skip)]
    sp: Object,

    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
    link: Object,

    #[builder(argtype = "&str", inline = "types::String::from({0}).into()")]
    global_link: Object,

    #[builder(argtype = "bool")]
    fallback: Boolean,

    #[builder(argtype = "u8", inline = "{0} as Integer")]
    blend: Integer,

    #[builder(argtype = "bool")]
    fg_indexed: Boolean,

    #[builder(argtype = "bool")]
    bg_indexed: Boolean,

    #[builder(argtype = "bool")]
    force: Boolean,
}

/// Options passed to [`set_hl()`](crate::set_hl).
#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
#[derive(Clone, Debug, Default, PartialEq)]
#[repr(C)]
pub struct SetHighlightOpts {
    bg: Object,
    fg: Object,
    sp: Object,
    bold: Object,
    link: Object,
    blend: Object,
    cterm: Object,
    italic: Object,
    special: Object,
    ctermbg: Object,
    ctermfg: Object,
    default: Object,
    altfont: Object,
    reverse: Object,
    fallback: Object,
    standout: Object,
    nocombine: Object,
    undercurl: Object,
    underline: Object,
    background: Object,
    bg_indexed: Object,
    foreground: Object,
    fg_indexed: Object,
    global_link: Object,
    underdashed: Object,
    underdotted: Object,
    underdouble: Object,
    strikethrough: Object,
}

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
impl SetHighlightOpts {
    /// Creates a new [`SetHighlightOptsBuilder`].
    #[inline]
    pub fn builder() -> SetHighlightOptsBuilder {
        <SetHighlightOptsBuilder as Default>::default()
    }
}

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
#[derive(Clone, Default)]
pub struct SetHighlightOptsBuilder(SetHighlightOpts);

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
impl SetHighlightOptsBuilder {
    #[inline]
    pub fn background(&mut self, background: &str) -> &mut Self {
        self.0.background = types::String::from(background).into();
        self
    }

    #[inline]
    pub fn blend(&mut self, blend: u8) -> &mut Self {
        self.0.blend = blend.into();
        self
    }

    #[inline]
    pub fn bold(&mut self, bold: bool) -> &mut Self {
        self.0.bold = bold.into();
        self
    }

    #[inline]
    pub fn cterm(&mut self, cterm: &str) -> &mut Self {
        self.0.cterm = types::String::from(cterm).into();
        self
    }

    #[inline]
    pub fn ctermbg(&mut self, ctermbg: &str) -> &mut Self {
        self.0.ctermbg = types::String::from(ctermbg).into();
        self
    }

    #[inline]
    pub fn ctermfg(&mut self, ctermfg: &str) -> &mut Self {
        self.0.ctermfg = types::String::from(ctermfg).into();
        self
    }

    #[inline]
    pub fn default(&mut self, default: bool) -> &mut Self {
        self.0.default = default.into();
        self
    }

    #[inline]
    pub fn fallback(&mut self, fallback: bool) -> &mut Self {
        self.0.fallback = fallback.into();
        self
    }

    #[inline]
    pub fn foreground(&mut self, foreground: &str) -> &mut Self {
        self.0.foreground = types::String::from(foreground).into();
        self
    }

    #[inline]
    pub fn global_link(&mut self, global_link: &str) -> &mut Self {
        self.0.global_link = types::String::from(global_link).into();
        self
    }

    #[inline]
    pub fn italic(&mut self, italic: bool) -> &mut Self {
        self.0.italic = italic.into();
        self
    }

    #[inline]
    pub fn link(&mut self, link: &str) -> &mut Self {
        self.0.link = types::String::from(link).into();
        self
    }

    #[inline]
    pub fn nocombine(&mut self, nocombine: bool) -> &mut Self {
        self.0.nocombine = nocombine.into();
        self
    }

    #[inline]
    pub fn reverse(&mut self, reverse: bool) -> &mut Self {
        self.0.reverse = reverse.into();
        self
    }

    #[inline]
    pub fn special(&mut self, special: &str) -> &mut Self {
        self.0.special = types::String::from(special).into();
        self
    }

    #[inline]
    pub fn standout(&mut self, standout: bool) -> &mut Self {
        self.0.standout = standout.into();
        self
    }

    #[inline]
    pub fn strikethrough(&mut self, strikethrough: bool) -> &mut Self {
        self.0.strikethrough = strikethrough.into();
        self
    }

    #[inline]
    pub fn undercurl(&mut self, undercurl: bool) -> &mut Self {
        self.0.undercurl = undercurl.into();
        self
    }

    #[inline]
    pub fn underdashed(&mut self, underdashed: bool) -> &mut Self {
        self.0.underdashed = underdashed.into();
        self
    }

    #[inline]
    pub fn underdotted(&mut self, underdotted: bool) -> &mut Self {
        self.0.underdotted = underdotted.into();
        self
    }

    #[inline]
    pub fn underdouble(&mut self, underdouble: bool) -> &mut Self {
        self.0.underdouble = underdouble.into();
        self
    }

    #[inline]
    pub fn underline(&mut self, underline: bool) -> &mut Self {
        self.0.underline = underline.into();
        self
    }

    #[inline]
    pub fn altfont(&mut self, altfont: bool) -> &mut Self {
        self.0.altfont = altfont.into();
        self
    }

    #[inline]
    pub fn bg_indexed(&mut self, bg_indexed: bool) -> &mut Self {
        self.0.bg_indexed = bg_indexed.into();
        self
    }

    #[inline]
    pub fn fg_indexed(&mut self, fg_indexed: bool) -> &mut Self {
        self.0.fg_indexed = fg_indexed.into();
        self
    }

    #[inline]
    pub fn build(&mut self) -> SetHighlightOpts {
        std::mem::take(&mut self.0)
    }
}