notcurses/visual/
pixel.rs

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
// notcurses::visual::pixel
//
//!
//

/// Pixel blitting implementations, informative only.
///
/// This is returned by [`Capabilities.pixel_implementation`].
///
/// [`Capabilities.pixel_implementation`]: crate::Capabilities#method.pixel_implementation
#[non_exhaustive]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum PixelImplementation {
    /// No pixel support.
    ///
    /// This is the default.
    None,

    /// Sixel.
    Sixel,

    /// Linux framebuffer.
    LinuxFb,

    /// iTerm2.
    Iterm2,

    /// Kitty prior to C=1 and animation.
    KittyStatic,

    /// Kitty with animation but not reflexive composition.
    KittyAnimated,

    /// Kitty with reflexive composition.
    KittySelfRef,
}

mod core_impls {
    use super::PixelImplementation;
    use crate::sys::{c_api::NcPixelImpl_u32, NcPixelImpl};
    use core::fmt;

    impl Default for PixelImplementation {
        fn default() -> Self {
            Self::None
        }
    }

    impl fmt::Display for PixelImplementation {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            write!(
                f,
                "{}",
                match self {
                    PixelImplementation::None => "None",
                    PixelImplementation::Sixel => "Sixel",
                    PixelImplementation::LinuxFb => "LinuxFb",
                    PixelImplementation::Iterm2 => "Iterm2",
                    PixelImplementation::KittyStatic => "KittyStatic",
                    PixelImplementation::KittyAnimated => "KittyAnimated",
                    PixelImplementation::KittySelfRef => "KittySelfRef",
                }
            )
        }
    }

    impl fmt::Debug for PixelImplementation {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            write!(f, "Pixel::{}", self)
        }
    }

    //

    impl From<NcPixelImpl> for PixelImplementation {
        fn from(nc: NcPixelImpl) -> PixelImplementation {
            match nc {
                NcPixelImpl::None => PixelImplementation::None,
                NcPixelImpl::Sixel => PixelImplementation::Sixel,
                NcPixelImpl::LinuxFb => PixelImplementation::LinuxFb,
                NcPixelImpl::Iterm2 => PixelImplementation::Iterm2,
                NcPixelImpl::KittyStatic => PixelImplementation::KittyStatic,
                NcPixelImpl::KittyAnimated => PixelImplementation::KittyAnimated,
                NcPixelImpl::KittySelfRef => PixelImplementation::KittySelfRef,
                _ => PixelImplementation::default(),
            }
        }
    }
    impl From<PixelImplementation> for NcPixelImpl {
        fn from(pi: PixelImplementation) -> NcPixelImpl {
            match pi {
                PixelImplementation::None => NcPixelImpl::None,
                PixelImplementation::Sixel => NcPixelImpl::Sixel,
                PixelImplementation::LinuxFb => NcPixelImpl::LinuxFb,
                PixelImplementation::Iterm2 => NcPixelImpl::Iterm2,
                PixelImplementation::KittyStatic => NcPixelImpl::KittyStatic,
                PixelImplementation::KittyAnimated => NcPixelImpl::KittyAnimated,
                PixelImplementation::KittySelfRef => NcPixelImpl::KittySelfRef,
            }
        }
    }

    impl From<NcPixelImpl_u32> for PixelImplementation {
        fn from(ncu: NcPixelImpl_u32) -> PixelImplementation {
            NcPixelImpl::from(ncu).into()
        }
    }
    impl From<PixelImplementation> for NcPixelImpl_u32 {
        fn from(pi: PixelImplementation) -> NcPixelImpl_u32 {
            NcPixelImpl::from(pi).into()
        }
    }
}