libnotcurses_sys/pixel/
pixel_impl.rs

1//!
2
3/// Pixel blitting implementations, informative only.
4///
5/// This is returned by [`Nc.check_pixel_support`].
6///
7/// [`Nc.check_pixel_support`]: crate::Nc#method.check_pixel_support
8#[repr(u32)]
9#[non_exhaustive]
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum NcPixelImpl {
12    /// No pixel support.
13    None = c_api::NCPIXEL_NONE,
14
15    /// Sixel.
16    Sixel = c_api::NCPIXEL_SIXEL,
17
18    /// Linux framebuffer.
19    LinuxFb = c_api::NCPIXEL_LINUXFB,
20
21    /// iTerm2.
22    Iterm2 = c_api::NCPIXEL_ITERM2,
23
24    /// Kitty prior to C=1 and animation.
25    KittyStatic = c_api::NCPIXEL_KITTY_STATIC,
26
27    /// Kitty with animation but not reflexive composition.
28    KittyAnimated = c_api::NCPIXEL_KITTY_ANIMATED,
29
30    /// Kitty with reflexive composition.
31    KittySelfRef = c_api::NCPIXEL_KITTY_SELFREF,
32}
33
34mod core_impls {
35    use super::{c_api::*, NcPixelImpl};
36    use core::fmt;
37
38    impl Default for NcPixelImpl {
39        fn default() -> Self {
40            Self::None
41        }
42    }
43
44    impl fmt::Display for NcPixelImpl {
45        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
46            use NcPixelImpl::*;
47            write!(
48                f,
49                "{}",
50                match self {
51                    NcPixelImpl::None => "None",
52                    Sixel => "Sixel",
53                    LinuxFb => "LinuxFb",
54                    Iterm2 => "Iterm2",
55                    KittyStatic => "KittyStatic",
56                    KittyAnimated => "KittyAnimated",
57                    KittySelfRef => "KittySelfRef",
58                }
59            )
60        }
61    }
62
63    impl From<NcPixelImpl_u32> for NcPixelImpl {
64        fn from(alpha: NcPixelImpl_u32) -> Self {
65            use NcPixelImpl::*;
66            match alpha {
67                NCPIXEL_NONE => NcPixelImpl::None,
68                NCPIXEL_SIXEL => Sixel,
69                NCPIXEL_LINUXFB => LinuxFb,
70                NCPIXEL_ITERM2 => Iterm2,
71                NCPIXEL_KITTY_STATIC => KittyStatic,
72                NCPIXEL_KITTY_ANIMATED => KittyAnimated,
73                NCPIXEL_KITTY_SELFREF => KittySelfRef,
74                _ => Self::default(),
75            }
76        }
77    }
78
79    impl From<NcPixelImpl> for NcPixelImpl_u32 {
80        fn from(alpha: NcPixelImpl) -> Self {
81            use NcPixelImpl::*;
82            match alpha {
83                NcPixelImpl::None => NCPIXEL_NONE,
84                Sixel => NCPIXEL_SIXEL,
85                LinuxFb => NCPIXEL_LINUXFB,
86                Iterm2 => NCPIXEL_ITERM2,
87                KittyStatic => NCPIXEL_KITTY_STATIC,
88                KittyAnimated => NCPIXEL_KITTY_ANIMATED,
89                KittySelfRef => NCPIXEL_KITTY_SELFREF,
90            }
91        }
92    }
93}
94
95pub(crate) mod c_api {
96    use crate::c_api::ffi;
97
98    /// Pixel blitting implementations, informative only.
99    ///
100    /// It's recommended to use [`NcPixelImpl`][crate::NcPixelImpl] instead.
101    ///
102    /// This is returned by [`notcurses_check_pixel_support`]
103    ///
104    /// # Associated `c_api` constants
105    ///
106    /// - [`NCPIXEL_NONE`]
107    /// - [`NCPIXEL_SIXEL`]
108    /// - [`NCPIXEL_LINUXFB`]
109    /// - [`NCPIXEL_ITERM2`]
110    /// - [`NCPIXEL_KITTY_STATIC`]
111    /// - [`NCPIXEL_KITTY_ANIMATED`]
112    /// - [`NCPIXEL_KITTY_SELFREF`]
113    ///
114    /// [`notcurses_check_pixel_support`]: crate::c_api::notcurses::check_pixel_support
115    pub type NcPixelImpl_u32 = ffi::ncpixelimpl_e;
116
117    /// [`NcPixelImpl_u32`] No pixel support.
118    pub const NCPIXEL_NONE: NcPixelImpl_u32 = ffi::ncpixelimpl_e_NCPIXEL_NONE;
119
120    /// [`NcPixelImpl_u32`] Sixel.
121    pub const NCPIXEL_SIXEL: NcPixelImpl_u32 = ffi::ncpixelimpl_e_NCPIXEL_SIXEL;
122
123    /// [`NcPixelImpl_u32`] Linux framebuffer.
124    pub const NCPIXEL_LINUXFB: NcPixelImpl_u32 = ffi::ncpixelimpl_e_NCPIXEL_LINUXFB;
125
126    /// [`NcPixelImpl_u32`] iTerm2.
127    pub const NCPIXEL_ITERM2: NcPixelImpl_u32 = ffi::ncpixelimpl_e_NCPIXEL_ITERM2;
128
129    /// [`NcPixelImpl_u32`] Kitty prior to C=1 and animation.
130    pub const NCPIXEL_KITTY_STATIC: NcPixelImpl_u32 = ffi::ncpixelimpl_e_NCPIXEL_KITTY_STATIC;
131
132    /// [`NcPixelImpl_u32`] Kitty with animation but not reflexive composition.
133    pub const NCPIXEL_KITTY_ANIMATED: NcPixelImpl_u32 = ffi::ncpixelimpl_e_NCPIXEL_KITTY_ANIMATED;
134
135    /// [`NcPixelImpl_u32`] Kitty with reflexive composition.
136    pub const NCPIXEL_KITTY_SELFREF: NcPixelImpl_u32 = ffi::ncpixelimpl_e_NCPIXEL_KITTY_SELFREF;
137}