libnotcurses_sys/channel/
channels.rs

1//!
2
3use crate::{
4    c_api::{self, NcChannels_u64},
5    error, NcAlpha, NcChannel, NcPaletteIndex, NcResult, NcRgb,
6};
7
8/// 64 bits containing a foreground and background [`NcChannel`]
9///
10/// At render time, both 24-bit [`NcRgb`] values are quantized down to terminal
11/// capabilities, if necessary. There's a clear path to 10-bit support should
12/// we one day need it.
13///
14/// ## Default Color
15///
16/// The "default color" is best explained by [color(3NCURSES)][0] and
17/// [default_colors(3NCURSES)][1]. Ours is the same concept.
18///
19/// [0]: https://manpages.debian.org/stretch/ncurses-doc/color.3ncurses.en.html
20/// [1]: https://manpages.debian.org/stretch/ncurses-doc/default_colors.3ncurses.en.html
21///
22/// **Until the "not default color" bit is set, any color you load will be ignored.**
23///
24/// ## Diagram
25///
26/// ```txt
27/// ~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB║~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB
28/// ↑↑↑↑↑↑↑↑↑↑↑↑ foreground ↑↑↑↑↑↑↑↑↑↑↑║↑↑↑↑↑↑↑↑↑↑↑↑ background ↑↑↑↑↑↑↑↑↑↑↑
29/// ```
30///
31/// Detailed info (specially on the context-dependent bits on each
32/// [`NcChannel`]'s 4th byte):
33///
34/// ```txt
35///                             ~foreground channel~
36/// reserved, must be 0                                  ↓bits view↓               ↓hex mask↓
37/// 0·······|········|········|········║········|········|········|········  =  8·······|········
38///
39/// NcChannels::FG_DEFAULT_MASK: foreground is NOT "default color"
40/// ·1······|········|········|········║········|········|········|········  =  4·······|········
41///
42/// NcChannels::FG_ALPHA_MASK: foreground alpha (2bits)
43/// ··11····|········|········|········║········|········|········|········  =  3·······|········
44///
45/// NcChannels::FG_PALETTE: foreground uses palette index
46/// ····1···|········|········|········║········|········|········|········  =  ·8······|········
47///
48/// NcChannels::NOBACKGROUND_MASK: glyph is entirely foreground
49/// ·····1··|········|········|········║········|········|········|········  =  ·4······|········
50///
51/// reserved, must be 0
52/// ······00|········|········|········║········|········|········|········  =  ·3······|········
53///
54/// NcChannels::FG_RGB_MASK: foreground in 3x8 RGB (rrggbb)
55/// ········|11111111|11111111|11111111║········|········|········|········  =  ··FFFFFF|········
56/// ```
57///
58/// ```txt
59///                             ~background channel~
60/// reserved, must be 0                                  ↓bits view↓               ↓hex mask↓
61/// ········|········|········|········║0·······|········|········|········  =  ········|8·······
62///
63/// NcChannels::BGDEFAULT_MASK: background is NOT "default color"
64/// ········|········|········|········║·1······|········|········|········  =  ········|4·······
65///
66/// NcChannels::BG_ALPHA_MASK: background alpha (2 bits)
67/// ········|········|········|········║··11····|········|········|········  =  ········|3·······
68///
69/// NcChannels::BG_PALETTE: background uses palette index
70/// ········|········|········|········║····1···|········|········|········  =  ········|·8······
71///
72/// reserved, must be 0
73/// ········|········|········|········║·····000|········|········|········  =  ········|·7······
74///
75/// NcChannels::BG_RGB_MASK: background in 3x8 RGB (rrggbb)
76/// ········|········|········|········║········|11111111|11111111|11111111  =  ········|··FFFFFF
77/// ```
78/// `type in C: channels (uint64_t)`
79///
80/// ## `NcChannels` Mask Flags
81///
82/// - [`NcChannels::BG_DEFAULT_MASK`][NcChannels#associatedconstant.BGDEFAULT_MASK]
83/// - [`NcChannels::BG_ALPHA_MASK`][NcChannels#associatedconstant.BG_ALPHA_MASK]
84/// - [`NcChannels::BG_PALETTE`][NcChannels#associatedconstant.BG_PALETTE]
85/// - [`NcChannels::BG_RGB_MASK`][NcChannels#associatedconstant.BG_RGB_MASK]
86/// - [`NcChannels::FG_DEFAULT_MASK`][NcChannels#associatedconstant.FGDEFAULT_MASK]
87/// - [`NcChannels::FG_ALPHA_MASK`][NcChannels#associatedconstant.FG_ALPHA_MASK]
88/// - [`NcChannels::FG_PALETTE`][NcChannels#associatedconstant.FG_PALETTE]
89/// - [`NcChannels::FG_RGB_MASK`][NcChannels#associatedconstant.FG_RGB_MASK]
90///
91#[repr(transparent)]
92#[derive(Clone, Copy, Debug, PartialEq, Eq)]
93pub struct NcChannels(pub NcChannels_u64);
94
95mod core_impls {
96    use super::{NcChannels, NcChannels_u64};
97
98    impl Default for NcChannels {
99        fn default() -> Self {
100            Self::with_default()
101        }
102    }
103
104    crate::from_primitive![NcChannels, NcChannels_u64];
105    crate::unit_impl_from![NcChannels, NcChannels_u64];
106    crate::unit_impl_fmt![bases+display; NcChannels];
107
108    // Different background and foreground:
109
110    impl From<NcChannels> for [u8; 6] {
111        #[inline]
112        fn from(rgb: NcChannels) -> Self {
113            let fg: (u8, u8, u8) = rgb.fg_rgb().into();
114            let bg: (u8, u8, u8) = rgb.bg_rgb().into();
115            [fg.0, fg.1, fg.2, bg.0, bg.1, bg.2]
116        }
117    }
118    impl From<[u8; 6]> for NcChannels {
119        #[inline]
120        fn from(a: [u8; 6]) -> Self {
121            Self::from_rgb((a[0], a[1], a[2]), (a[3], a[4], a[5]))
122        }
123    }
124
125    impl From<NcChannels> for (u8, u8, u8, u8, u8, u8) {
126        #[inline]
127        fn from(rgb: NcChannels) -> Self {
128            let fg: (u8, u8, u8) = rgb.fg_rgb().into();
129            let bg: (u8, u8, u8) = rgb.bg_rgb().into();
130            (fg.0, fg.1, fg.2, bg.0, bg.1, bg.2)
131        }
132    }
133    impl From<(u8, u8, u8, u8, u8, u8)> for NcChannels {
134        fn from(t: (u8, u8, u8, u8, u8, u8)) -> Self {
135            Self::from_rgb([t.0, t.1, t.2], [t.3, t.4, t.5])
136        }
137    }
138}
139
140/// # NcChannels constants
141impl NcChannels {
142    /// If this bit is set, we are *not* using the default background color.
143    ///
144    /// See the detailed diagram at [`NcChannels`][crate::NcChannels]
145    pub const BG_DEFAULT_MASK: u32 = super::c_api::NC_BGDEFAULT_MASK;
146
147    /// Extract these bits to get the background [`NcAlpha`] mask.
148    ///
149    /// See the detailed diagram at [`NcChannels`][crate::NcChannels]
150    pub const BG_ALPHA_MASK: u32 = super::c_api::NC_BG_ALPHA_MASK;
151
152    /// If this bit *and*
153    /// [`BG_DEFAULT_MASK`][NcChannels#associatedconstant.BG_DEFAULT_MASK]
154    /// are set, we're using a palette-indexed background color.
155    ///
156    /// See the detailed diagram at [`NcChannels`][crate::NcChannels]
157    pub const BG_PALETTE_MASK: u32 = super::c_api::NC_BG_PALETTE;
158
159    /// Extract these bits to get the background [`NcRgb`][crate::NcRgb] value.
160    pub const BG_RGB_MASK: u32 = super::c_api::NC_BG_RGB_MASK;
161
162    /// Does this glyph completely obscure the background? If so, there's no need
163    /// to emit a background when rasterizing, a small optimization. These are
164    /// also used to track regions into which we must not cellblit.
165    pub const NOBACKGROUND_MASK: u64 = c_api::NC_NOBACKGROUND_MASK;
166}
167
168/// # NcChannels constructors
169impl NcChannels {
170    /// New `NcChannels`, set to black and NOT using the "default color".
171    pub fn new() -> Self {
172        Self::combine(NcChannel::new(), NcChannel::new())
173    }
174
175    /// New `NcChannels`, set to black and using the "default color".
176    pub fn with_default() -> Self {
177        Self::combine(NcChannel::with_default(), NcChannel::with_default())
178    }
179
180    /// New `NcChannels`, expects two separate [`NcRgb`]s for the foreground
181    /// and background channels.
182    pub fn from_rgb(fg_rgb: impl Into<NcRgb>, bg_rgb: impl Into<NcRgb>) -> Self {
183        Self::combine(NcChannel::from_rgb(fg_rgb), NcChannel::from_rgb(bg_rgb))
184    }
185
186    /// New `NcChannels`, expects a single [`NcRgb`] for both foreground
187    /// and background channels.
188    pub fn from_rgb_both(rgb: impl Into<NcRgb>) -> Self {
189        let channel = NcChannel::new().set(rgb.into());
190        Self::combine(channel, channel)
191    }
192
193    /// New `NcChannels`, expects two separate [`NcRgb`] & [`NcAlpha`] for the
194    /// foreground and background channels.
195    pub fn from_rgb_alpha(
196        fg_rgb: impl Into<NcRgb>,
197        fg_alpha: impl Into<NcAlpha>,
198        bg_rgb: impl Into<NcRgb>,
199        bg_alpha: impl Into<NcAlpha>,
200    ) -> Self {
201        Self::combine(
202            NcChannel::from_rgb(fg_rgb).set_alpha(fg_alpha),
203            NcChannel::from_rgb(bg_rgb).set_alpha(bg_alpha),
204        )
205    }
206
207    /// New `NcChannels`, expects [`NcRgb`] & [`NcAlpha`] for both
208    /// channels.
209    pub fn from_rgb_alpha_both(rgb: impl Into<NcRgb>, alpha: impl Into<NcAlpha>) -> Self {
210        let channel = NcChannel::new().set(rgb.into()).set_alpha(alpha.into());
211        Self::combine(channel, channel)
212    }
213
214    // Combine & Reverse
215
216    /// Combines two [`NcChannel`]s into an [`NcChannels`].
217    ///
218    /// *C style function: [channels_combine()][c_api::ncchannels_combine].*
219    pub fn combine(fchannel: impl Into<NcChannel>, bchannel: impl Into<NcChannel>) -> Self {
220        c_api::ncchannels_combine(fchannel.into().0, bchannel.into().0).into()
221    }
222
223    /// Returns the `NcChannels` with the fore- and background's color
224    /// information swapped, but without touching housekeeping bits.
225    ///
226    /// Alpha is retained unless it would lead to an illegal state:
227    /// `HIGHCONTRAST`, `TRANSPARENT` and `BLEND` are taken to `OPAQUE`
228    /// unless the new value is RGB.
229    ///
230    /// [`HIGHCONTRAST`][NcAlpha#associatedconstant.HIGHCONTRAST]
231    /// [`TRANSPARENT`][NcAlpha#associatedconstant.TRANSPARENT]
232    /// [`BLEND`][NcAlpha#associatedconstant.BLEND]
233    /// [`OPAQUE`][NcAlpha#associatedconstant.OPAQUE]
234    ///
235    /// *C style function: [ncchannels_reverse()][c_api::ncchannels_reverse].*
236    pub fn reverse(&mut self) -> Self {
237        *self = c_api::ncchannels_reverse(self.0).into();
238        *self
239    }
240}
241
242/// # NcChannels methods
243impl NcChannels {
244    // NcChannel
245
246    /// Gets the foreground alpha and coloring bits as an [`NcChannel`].
247    ///
248    /// *C style function: [ncchannels_fchannel()][c_api::ncchannels_fchannel].*
249    pub fn fchannel(&self) -> NcChannel {
250        c_api::ncchannels_fchannel(self.0).into()
251    }
252
253    /// Gets the background alpha and coloring bits as an [`NcChannel`].
254    ///
255    /// *C style function: [ncchannels_bchannel()][c_api::ncchannels_bchannel].*
256    pub fn bchannel(&self) -> NcChannel {
257        c_api::ncchannels_bchannel(self.0).into()
258    }
259
260    /// Sets the foreground alpha and coloring bits from an [`NcChannel`].
261    ///
262    /// *C style function: [ncchannels_set_fchannel()][c_api::ncchannels_set_fchannel].*
263    pub fn set_fchannel(&mut self, fchannel: impl Into<NcChannel>) -> Self {
264        c_api::ncchannels_set_fchannel(&mut self.0, fchannel.into().0).into()
265    }
266
267    /// Sets the background alpha and coloring bits from an [`NcChannel`].
268    ///
269    /// *C style function: [ncchannels_set_bchannel()][c_api::ncchannels_set_bchannel].*
270    pub fn set_bchannel(&mut self, bchannel: impl Into<NcChannel>) -> Self {
271        c_api::ncchannels_set_bchannel(&mut self.0, bchannel.into().0).into()
272    }
273
274    /// Gets the alpha and coloring bits as an [`NcChannels`].
275    ///
276    /// *C style function: [ncchannels_bchannel()][c_api::ncchannels_bchannel].*
277    pub fn channels(&self) -> NcChannels {
278        c_api::ncchannels_channels(self.0).into()
279    }
280
281    /// Sets the foreground alpha and coloring bits as an [`NcChannels`],
282    /// from another [`NcChannels`].
283    ///
284    /// *C style function: [ncchannels_set_fchannel()][c_api::ncchannels_set_fchannel].*
285    pub fn set_channels(&mut self, from_channels: impl Into<NcChannels>) -> Self {
286        c_api::ncchannels_set_channels(&mut self.0, from_channels.into().0).into()
287    }
288
289    // Alpha
290
291    /// Gets the foreground [`NcAlpha`].
292    ///
293    /// *C style function: [ncchannels_fg_alpha()][c_api::ncchannels_fg_alpha].*
294    pub fn fg_alpha(&self) -> NcAlpha {
295        c_api::ncchannels_fg_alpha(self.0).into()
296    }
297
298    /// Gets the background [`NcAlpha`].
299    ///
300    /// *C style function: [ncchannels_bg_alpha()][c_api::ncchannels_bg_alpha].*
301    pub fn bg_alpha(&self) -> NcAlpha {
302        c_api::ncchannels_bg_alpha(self.0).into()
303    }
304
305    /// Sets the foreground [`NcAlpha`].
306    ///
307    /// *C style function: [ncchannels_set_fg_alpha()][c_api::ncchannels_set_fg_alpha].*
308    pub fn set_fg_alpha(&mut self, alpha: impl Into<NcAlpha>) -> NcResult<()> {
309        error![c_api::ncchannels_set_fg_alpha(&mut self.0, alpha.into())]
310    }
311
312    /// Sets the background [`NcAlpha`].
313    ///
314    /// *C style function: [ncchannels_set_bg_alpha()][c_api::ncchannels_set_bg_alpha].*
315    pub fn set_bg_alpha(&mut self, alpha: impl Into<NcAlpha>) -> NcResult<()> {
316        error![c_api::ncchannels_set_bg_alpha(&mut self.0, alpha.into())]
317    }
318
319    // NcRgb
320
321    /// Returns true if the foreground channel is set to RGB color.
322    ///
323    /// *C style function: [ncchannels_fg_rgb_p()][c_api::ncchannels_fg_rgb_p].*
324    pub fn fg_rgb_p(&self) -> bool {
325        c_api::ncchannels_fg_rgb_p(self.0)
326    }
327
328    /// Returns true if the background channel is set to RGB color.
329    ///
330    /// *C style function: [ncchannels_bg_rgb_p()][c_api::ncchannels_bg_rgb_p].*
331    pub fn bg_rgb_p(&self) -> bool {
332        c_api::ncchannels_bg_rgb_p(self.0)
333    }
334
335    /// Gets the foreground [`NcRgb`].
336    ///
337    /// *C style function: [ncchannels_fg_rgb()][c_api::ncchannels_fg_rgb].*
338    pub fn fg_rgb(&self) -> NcRgb {
339        c_api::ncchannels_fg_rgb(self.0).into()
340    }
341
342    /// Gets the background [`NcRgb`].
343    ///
344    /// *C style function: [ncchannels_bg_rgb()][c_api::ncchannels_bg_rgb].*
345    pub fn bg_rgb(&self) -> NcRgb {
346        c_api::ncchannels_bg_rgb(self.0).into()
347    }
348
349    /// Sets the foreground [`NcRgb`].
350    ///
351    /// *C style function: [channels_set_fg_rgb()][c_api::ncchannels_set_fg_rgb].*
352    pub fn set_fg_rgb(&mut self, rgb: impl Into<NcRgb>) -> Self {
353        c_api::ncchannels_set_fg_rgb(&mut self.0, rgb.into().0);
354        *self
355    }
356
357    /// Sets the background [`NcRgb`].
358    ///
359    /// *C style function: [channels_set_bg_rgb()][c_api::ncchannels_set_bg_rgb].*
360    pub fn set_bg_rgb(&mut self, rgb: impl Into<NcRgb>) -> Self {
361        c_api::ncchannels_set_bg_rgb(&mut self.0, rgb.into().0);
362        *self
363    }
364
365    /// Gets the foreground red component.
366    ///
367    /// *(No equivalent C style function)*
368    pub fn fg_r(&self) -> u8 {
369        c_api::ncchannel_r(c_api::ncchannels_fchannel(self.0))
370    }
371
372    /// Gets the foreground green component.
373    ///
374    /// *(No equivalent C style function)*
375    pub fn fg_g(&self) -> u8 {
376        c_api::ncchannel_g(c_api::ncchannels_fchannel(self.0))
377    }
378
379    /// Gets the foreground blue component.
380    ///
381    /// *(No equivalent C style function)*
382    pub fn fg_b(&self) -> u8 {
383        c_api::ncchannel_b(c_api::ncchannels_fchannel(self.0))
384    }
385
386    /// Gets the background red component.
387    ///
388    /// *(No equivalent C style function)*
389    pub fn bg_r(&self) -> u8 {
390        c_api::ncchannel_r(c_api::ncchannels_bchannel(self.0))
391    }
392
393    /// Gets the background green component.
394    ///
395    /// *(No equivalent C style function)*
396    pub fn bg_g(&self) -> u8 {
397        c_api::ncchannel_g(c_api::ncchannels_bchannel(self.0))
398    }
399
400    /// Gets the background blue component.
401    ///
402    /// *(No equivalent C style function)*
403    pub fn bg_b(&self) -> u8 {
404        c_api::ncchannel_b(c_api::ncchannels_bchannel(self.0))
405    }
406
407    /// Sets the foreground red component, and returns the new `NcChannels`.
408    ///
409    /// *(No equivalent C style function)*
410    pub fn fg_set_r(&mut self, r: impl Into<u8>) -> Self {
411        let (_, g, b) = self.bg_rgb().into();
412        c_api::ncchannels_set_fg_rgb8(&mut self.0, r.into(), g, b).into()
413    }
414
415    /// Sets the foreground green component, and returns the new `NcChannels`.
416    ///
417    /// *(No equivalent C style function)*
418    pub fn fg_set_g(&mut self, g: impl Into<u8>) -> Self {
419        let (r, _, b) = self.bg_rgb().into();
420        c_api::ncchannels_set_fg_rgb8(&mut self.0, r, g.into(), b).into()
421    }
422
423    /// Sets the foreground blue component, and returns the new `NcChannels`.
424    ///
425    /// *(No equivalent C style function)*
426    pub fn fg_set_b(&mut self, b: impl Into<u8>) -> Self {
427        let (r, g, _) = self.bg_rgb().into();
428        c_api::ncchannels_set_fg_rgb8(&mut self.0, r, g, b.into()).into()
429    }
430
431    /// Sets the background red component, and returns the new `NcChannels`.
432    ///
433    /// *(No equivalent C style function)*
434    pub fn bg_set_r(&mut self, r: impl Into<u8>) -> Self {
435        let (_, g, b) = self.bg_rgb().into();
436        c_api::ncchannels_set_bg_rgb8(&mut self.0, r.into(), g, b).into()
437    }
438
439    /// Sets the background green component, and returns the new `NcChannels`.
440    ///
441    /// *(No equivalent C style function)*
442    pub fn bg_set_g(&mut self, g: impl Into<u8>) -> Self {
443        let (r, _, b) = self.bg_rgb().into();
444        c_api::ncchannels_set_bg_rgb8(&mut self.0, r, g.into(), b).into()
445    }
446
447    /// Sets the background blue component, and returns the new `NcChannels`.
448    ///
449    /// *(No equivalent C style function)*
450    pub fn bg_set_b(&mut self, b: impl Into<u8>) -> Self {
451        let (r, g, _) = self.bg_rgb().into();
452        c_api::ncchannels_set_bg_rgb8(&mut self.0, r, g, b.into()).into()
453    }
454
455    // default color
456
457    /// Is the background using the "default background color"?
458    ///
459    /// *C style function: [channels_fg_default_p()][c_api::ncchannels_fg_default_p].*
460    pub fn fg_default_p(&self) -> bool {
461        c_api::ncchannels_fg_default_p(self.0)
462    }
463
464    /// Is the background using the "default background color"?
465    ///
466    /// The "default background color" must generally be used to take advantage
467    /// of terminal-effected transparency.
468    ///
469    /// *C style function: [channels_bg_default_p()][c_api::ncchannels_bg_default_p].*
470    pub fn bg_default_p(&self) -> bool {
471        c_api::ncchannels_bg_default_p(self.0)
472    }
473
474    /// Marks the foreground as using its "default color", and
475    /// returns the new [`NcChannels`].
476    ///
477    /// *C style function: [channels_set_fg_default()][c_api::ncchannels_set_fg_default].*
478    pub fn set_fg_default(&mut self) -> Self {
479        c_api::ncchannels_set_fg_default(&mut self.0).into()
480    }
481
482    /// Marks the background as using its "default color", and
483    /// returns the new [`NcChannels`].
484    ///
485    /// *C style function: [channels_set_bg_default()][c_api::ncchannels_set_bg_default].*
486    pub fn set_bg_default(&mut self) -> Self {
487        c_api::ncchannels_set_bg_default(&mut self.0).into()
488    }
489
490    /// Marks the foreground as NOT using its "default color", and
491    /// returns the new [`NcChannels`].
492    ///
493    /// *C style function: [channels_set_fg_default()][c_api::ncchannels_set_fg_default].*
494    //
495    // Not in the C API
496    pub fn set_fg_not_default(&mut self) -> Self {
497        c_api::ncchannels_set_fg_not_default(&mut self.0).into()
498    }
499
500    /// Marks the background as NOT using its "default color", and
501    /// returns the new [`NcChannels`].
502    ///
503    /// *C style function: [channels_set_bg_not_default()][c_api::ncchannels_set_bg_not_default].*
504    //
505    // Not in the C API
506    pub fn set_bg_not_default(&mut self) -> Self {
507        c_api::ncchannels_set_bg_not_default(&mut self.0).into()
508    }
509
510    /// Marks both the foreground and background as using its "default color", and
511    /// returns the new [`NcChannels`].
512    ///
513    //
514    // Not in the C API
515    pub fn set_default(&mut self) -> Self {
516        c_api::ncchannels_set_fg_default(&mut c_api::ncchannels_set_bg_default(&mut self.0)).into()
517    }
518
519    /// Marks both the foreground and background as NOT using its "default color",
520    /// and returns the new [`NcChannels`].
521    ///
522    //
523    // Not in the C API
524    pub fn set_not_default(&mut self) -> Self {
525        c_api::ncchannels_set_fg_not_default(&mut c_api::ncchannels_set_bg_not_default(&mut self.0))
526            .into()
527    }
528
529    // NcPaletteIndex
530
531    /// Gets the [`NcPaletteIndex`] from the foreground [`NcChannel`].
532    ///
533    /// *C style function: [channels_fg_palindex()][c_api::ncchannels_fg_palindex].*
534    pub fn fg_palindex(&self) -> NcPaletteIndex {
535        c_api::ncchannels_fg_palindex(self.0)
536    }
537
538    /// Gets the [`NcPaletteIndex`] from the background [`NcChannel`].
539    ///
540    /// *C style function: [channels_bg_palindex()][c_api::ncchannels_bg_palindex].*
541    pub fn bg_palindex(&self) -> NcPaletteIndex {
542        c_api::ncchannels_bg_palindex(self.0)
543    }
544
545    /// Is the foreground of using an [*indexed*][NcPaletteIndex]
546    /// [`NcPalette`][crate::NcPalette] color?
547    ///
548    /// *C style function: [channels_fg_palindex_p()][c_api::ncchannels_fg_palindex_p].*
549    pub fn fg_palindex_p(&self) -> bool {
550        c_api::ncchannels_fg_palindex_p(self.0)
551    }
552
553    /// Is the background of using an [*indexed*][NcPaletteIndex]
554    /// [`NcPalette`][crate::NcPalette] color?
555    ///
556    /// *C style function: [channels_bg_palindex_p()][c_api::ncchannels_bg_palindex_p].*
557    pub fn bg_palindex_p(&self) -> bool {
558        c_api::ncchannels_bg_palindex_p(self.0)
559    }
560
561    /// Sets the foreground of an [`NcChannels`] as using an
562    /// [*indexed*][NcPaletteIndex] [`NcPalette`][crate::NcPalette] color.
563    ///
564    /// *C style function: [channels_set_fg_palindex()][c_api::ncchannels_set_fg_palindex].*
565    pub fn set_fg_palindex(&mut self, index: impl Into<NcPaletteIndex>) -> Self {
566        c_api::ncchannels_set_fg_palindex(&mut self.0, index.into());
567        *self
568    }
569
570    /// Sets the background of an [`NcChannels`] as using an
571    /// [*indexed*][NcPaletteIndex] [`NcPalette`][crate::NcPalette] color.
572    ///
573    /// *C style function: [channels_set_bg_palindex()][c_api::ncchannels_set_bg_palindex].*
574    pub fn set_bg_palindex(&mut self, index: impl Into<NcPaletteIndex>) -> Self {
575        c_api::ncchannels_set_bg_palindex(&mut self.0, index.into());
576        *self
577    }
578}