notcurses/visual/
pixel.rs

1// notcurses::visual::pixel
2//
3//!
4//
5
6/// Pixel blitting implementations, informative only.
7///
8/// This is returned by [`Capabilities.pixel_implementation`].
9///
10/// [`Capabilities.pixel_implementation`]: crate::Capabilities#method.pixel_implementation
11#[non_exhaustive]
12#[derive(Clone, Copy, PartialEq, Eq)]
13pub enum PixelImplementation {
14    /// No pixel support.
15    ///
16    /// This is the default.
17    None,
18
19    /// Sixel.
20    Sixel,
21
22    /// Linux framebuffer.
23    LinuxFb,
24
25    /// iTerm2.
26    Iterm2,
27
28    /// Kitty prior to C=1 and animation.
29    KittyStatic,
30
31    /// Kitty with animation but not reflexive composition.
32    KittyAnimated,
33
34    /// Kitty with reflexive composition.
35    KittySelfRef,
36}
37
38mod core_impls {
39    use super::PixelImplementation;
40    use crate::sys::{c_api::NcPixelImpl_u32, NcPixelImpl};
41    use core::fmt;
42
43    impl Default for PixelImplementation {
44        fn default() -> Self {
45            Self::None
46        }
47    }
48
49    impl fmt::Display for PixelImplementation {
50        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51            write!(
52                f,
53                "{}",
54                match self {
55                    PixelImplementation::None => "None",
56                    PixelImplementation::Sixel => "Sixel",
57                    PixelImplementation::LinuxFb => "LinuxFb",
58                    PixelImplementation::Iterm2 => "Iterm2",
59                    PixelImplementation::KittyStatic => "KittyStatic",
60                    PixelImplementation::KittyAnimated => "KittyAnimated",
61                    PixelImplementation::KittySelfRef => "KittySelfRef",
62                }
63            )
64        }
65    }
66
67    impl fmt::Debug for PixelImplementation {
68        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
69            write!(f, "Pixel::{}", self)
70        }
71    }
72
73    //
74
75    impl From<NcPixelImpl> for PixelImplementation {
76        fn from(nc: NcPixelImpl) -> PixelImplementation {
77            match nc {
78                NcPixelImpl::None => PixelImplementation::None,
79                NcPixelImpl::Sixel => PixelImplementation::Sixel,
80                NcPixelImpl::LinuxFb => PixelImplementation::LinuxFb,
81                NcPixelImpl::Iterm2 => PixelImplementation::Iterm2,
82                NcPixelImpl::KittyStatic => PixelImplementation::KittyStatic,
83                NcPixelImpl::KittyAnimated => PixelImplementation::KittyAnimated,
84                NcPixelImpl::KittySelfRef => PixelImplementation::KittySelfRef,
85                _ => PixelImplementation::default(),
86            }
87        }
88    }
89    impl From<PixelImplementation> for NcPixelImpl {
90        fn from(pi: PixelImplementation) -> NcPixelImpl {
91            match pi {
92                PixelImplementation::None => NcPixelImpl::None,
93                PixelImplementation::Sixel => NcPixelImpl::Sixel,
94                PixelImplementation::LinuxFb => NcPixelImpl::LinuxFb,
95                PixelImplementation::Iterm2 => NcPixelImpl::Iterm2,
96                PixelImplementation::KittyStatic => NcPixelImpl::KittyStatic,
97                PixelImplementation::KittyAnimated => NcPixelImpl::KittyAnimated,
98                PixelImplementation::KittySelfRef => NcPixelImpl::KittySelfRef,
99            }
100        }
101    }
102
103    impl From<NcPixelImpl_u32> for PixelImplementation {
104        fn from(ncu: NcPixelImpl_u32) -> PixelImplementation {
105            NcPixelImpl::from(ncu).into()
106        }
107    }
108    impl From<PixelImplementation> for NcPixelImpl_u32 {
109        fn from(pi: PixelImplementation) -> NcPixelImpl_u32 {
110            NcPixelImpl::from(pi).into()
111        }
112    }
113}