nvim_api/opts/
set_highlight.rs

1use derive_builder::Builder;
2use nvim_types::{self as nvim, NonOwning, Object};
3
4/// Options passed to [`nvim_oxi::api::set_hl`](crate::set_hl).
5#[derive(Clone, Debug, Default, PartialEq, Builder)]
6#[builder(default, build_fn(private, name = "fallible_build"))]
7pub struct SetHighlightOpts {
8    #[builder(setter(custom))]
9    background: Object,
10
11    #[builder(setter(strip_option))]
12    blend: Option<u8>,
13
14    #[builder(setter(strip_option))]
15    bold: Option<bool>,
16
17    #[builder(setter(custom))]
18    cterm: Object,
19
20    #[builder(setter(custom))]
21    ctermbg: Object,
22
23    #[builder(setter(custom))]
24    ctermfg: Object,
25
26    #[builder(setter(strip_option))]
27    default: Option<bool>,
28
29    #[builder(setter(custom))]
30    foreground: Object,
31
32    #[builder(setter(strip_option))]
33    italic: Option<bool>,
34
35    #[builder(setter(custom))]
36    link: Object,
37
38    #[builder(setter(strip_option))]
39    nocombine: Option<bool>,
40
41    #[builder(setter(strip_option))]
42    reverse: Option<bool>,
43
44    #[builder(setter(custom))]
45    special: Object,
46
47    #[builder(setter(strip_option))]
48    standout: Option<bool>,
49
50    #[builder(setter(strip_option))]
51    strikethrough: Option<bool>,
52
53    #[builder(setter(strip_option))]
54    undercurl: Option<bool>,
55
56    #[builder(setter(strip_option))]
57    underdashed: Option<bool>,
58
59    #[builder(setter(strip_option))]
60    underdotted: Option<bool>,
61
62    #[builder(setter(strip_option))]
63    underdouble: Option<bool>,
64
65    #[builder(setter(strip_option))]
66    underline: Option<bool>,
67}
68
69impl SetHighlightOpts {
70    #[inline(always)]
71    /// Creates a new [`SetHighlightOptsBuilder`].
72    pub fn builder() -> SetHighlightOptsBuilder {
73        <SetHighlightOptsBuilder as Default>::default()
74    }
75}
76
77impl SetHighlightOptsBuilder {
78    pub fn background(&mut self, background: &str) -> &mut Self {
79        self.background = Some(nvim::String::from(background).into());
80        self
81    }
82
83    pub fn cterm(&mut self, cterm: &str) -> &mut Self {
84        self.cterm = Some(nvim::String::from(cterm).into());
85        self
86    }
87
88    pub fn ctermbg(&mut self, ctermbg: &str) -> &mut Self {
89        self.ctermbg = Some(nvim::String::from(ctermbg).into());
90        self
91    }
92
93    pub fn ctermfg(&mut self, ctermfg: &str) -> &mut Self {
94        self.ctermfg = Some(nvim::String::from(ctermfg).into());
95        self
96    }
97
98    pub fn foreground(&mut self, foreground: &str) -> &mut Self {
99        self.foreground = Some(nvim::String::from(foreground).into());
100        self
101    }
102
103    pub fn link(&mut self, link: &str) -> &mut Self {
104        self.link = Some(nvim::String::from(link).into());
105        self
106    }
107
108    pub fn special(&mut self, special: &str) -> &mut Self {
109        self.special = Some(nvim::String::from(special).into());
110        self
111    }
112
113    pub fn build(&mut self) -> SetHighlightOpts {
114        self.fallible_build().expect("never fails, all fields have defaults")
115    }
116}
117
118// Diff between 0.7.2 and master is:
119//
120// `temp` -> removed
121// `global` -> renamed to `global_link`
122// `underdot` -> renamed to `underdotted`
123// `underdash` -> renamed to `underdashed`
124// `underlineline` -> renamed to `underdouble`
125//
126// also `nocombine` and `undercurl` don't make it to the final definition of
127// `KeyDict_highlight` in nightly builds, but are still mentioned in the docs
128// and are present in `keysets.lua` so idk, I'll leave them in for now.
129#[derive(Default)]
130#[allow(non_camel_case_types)]
131#[repr(C)]
132pub(crate) struct KeyDict_highlight<'a> {
133    bg: Object,
134    fg: Object,
135    sp: Object,
136    bold: Object,
137    link: NonOwning<'a, Object>,
138    #[cfg(feature = "neovim-0-7")]
139    temp: Object,
140    blend: Object,
141    cterm: NonOwning<'a, Object>,
142    #[cfg(feature = "neovim-0-7")]
143    global: Object,
144    italic: Object,
145    special: NonOwning<'a, Object>,
146    ctermbg: NonOwning<'a, Object>,
147    ctermfg: NonOwning<'a, Object>,
148    default_: Object,
149    reverse: Object,
150    fallback: Object,
151    standout: Object,
152    #[cfg(feature = "neovim-0-7")]
153    underdot: Object,
154    nocombine: Object,
155    undercurl: Object,
156    #[cfg(feature = "neovim-0-7")]
157    underdash: Object,
158    underline: Object,
159    background: NonOwning<'a, Object>,
160    foreground: NonOwning<'a, Object>,
161    #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
162    global_link: Object,
163    #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
164    underdashed: Object,
165    #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
166    underdotted: Object,
167    #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
168    underdouble: Object,
169    strikethrough: Object,
170    #[cfg(feature = "neovim-0-7")]
171    underlineline: Object,
172}
173
174impl<'a> From<&'a SetHighlightOpts> for KeyDict_highlight<'a> {
175    fn from(opts: &'a SetHighlightOpts) -> Self {
176        Self {
177            bg: Object::nil(),
178            fg: Object::nil(),
179            sp: Object::nil(),
180            bold: opts.bold.into(),
181            link: opts.link.non_owning(),
182            #[cfg(feature = "neovim-0-7")]
183            temp: Object::nil(),
184            blend: opts.blend.into(),
185            cterm: opts.cterm.non_owning(),
186            #[cfg(feature = "neovim-0-7")]
187            global: Object::nil(),
188            italic: opts.italic.into(),
189            special: opts.special.non_owning(),
190            ctermbg: opts.ctermbg.non_owning(),
191            ctermfg: opts.ctermfg.non_owning(),
192            default_: opts.default.into(),
193            reverse: opts.reverse.into(),
194            fallback: Object::nil(),
195            standout: opts.standout.into(),
196            #[cfg(feature = "neovim-0-7")]
197            underdot: opts.underdotted.into(),
198            nocombine: opts.nocombine.into(),
199            undercurl: opts.undercurl.into(),
200            #[cfg(feature = "neovim-0-7")]
201            underdash: opts.underdashed.into(),
202            underline: opts.underline.into(),
203            background: opts.background.non_owning(),
204            foreground: opts.foreground.non_owning(),
205            #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
206            global_link: Object::nil(),
207            #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
208            underdashed: opts.underdashed.into(),
209            #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
210            underdotted: opts.underdotted.into(),
211            #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
212            underdouble: opts.underdouble.into(),
213            strikethrough: opts.strikethrough.into(),
214            #[cfg(feature = "neovim-0-7")]
215            underlineline: opts.underdouble.into(),
216        }
217    }
218}