libnotcurses_sys/input/
input_type.rs

1//!
2
3/// The type of the [`NcInput`][crate::NcInput] event.
4///
5/// Note: *Unknown* and *Press* are considered equivalent.
6#[repr(u32)]
7#[derive(Clone, Copy, PartialEq, Eq)]
8pub enum NcInputType {
9    ///
10    Unknown,
11
12    ///
13    Press,
14
15    ///
16    Repeat,
17
18    ///
19    Release,
20}
21
22mod core_impls {
23    use super::{c_api::*, NcInputType};
24    use core::fmt;
25
26    impl Default for NcInputType {
27        fn default() -> Self {
28            Self::Unknown
29        }
30    }
31
32    impl fmt::Display for NcInputType {
33        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34            use NcInputType::*;
35            write!(
36                f,
37                "{}",
38                match self {
39                    Unknown => "Unknown",
40                    Press => "Press",
41                    Repeat => "Repeat",
42                    Release => "Release",
43                }
44            )
45        }
46    }
47
48    impl fmt::Debug for NcInputType {
49        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50            write!(f, "NcInputType::{}", self)
51        }
52    }
53
54    impl From<NcInputType> for u32 {
55        fn from(it: NcInputType) -> Self {
56            use NcInputType::*;
57            match it {
58                Unknown => NCTYPE_UNKNOWN,
59                Press => NCTYPE_PRESS,
60                Repeat => NCTYPE_REPEAT,
61                Release => NCTYPE_RELEASE,
62            }
63        }
64    }
65
66    impl From<u32> for NcInputType {
67        fn from(value: u32) -> Self {
68            use NcInputType::*;
69            match value {
70                NCTYPE_UNKNOWN => Unknown,
71                NCTYPE_PRESS => Press,
72                NCTYPE_REPEAT => Repeat,
73                NCTYPE_RELEASE => Release,
74                _ => Unknown,
75            }
76        }
77    }
78}
79
80pub(crate) mod c_api {
81    use crate::c_api::ffi;
82
83    /// The type of the [`NcInput`][crate::NcInput] event.
84    ///
85    /// It's recommended to use  [`NcInputType`][crate::NcInputType] instead.
86    ///
87    /// # Associated `c_api` constants:
88    /// - [`NCTYPE_UNKNOWN`]
89    /// - [`NCTYPE_PRESS`]
90    /// - [`NCTYPE_REPEAT`]
91    /// - [`NCTYPE_RELEASE`]
92    pub type NcInputType_u32 = u32;
93
94    /// [`NcInputType_u32`] *Unknown* input type event.
95    pub const NCTYPE_UNKNOWN: u32 = ffi::ncintype_e_NCTYPE_UNKNOWN;
96
97    /// [`NcInputType_u32`] *Press* input type event.
98    pub const NCTYPE_PRESS: u32 = ffi::ncintype_e_NCTYPE_PRESS;
99
100    /// [`NcInputType_u32`] *Repeat* input type event.
101    pub const NCTYPE_REPEAT: u32 = ffi::ncintype_e_NCTYPE_REPEAT;
102
103    /// [`NcInputType_u32`] *Release* input type event.
104    pub const NCTYPE_RELEASE: u32 = ffi::ncintype_e_NCTYPE_RELEASE;
105}