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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//!

/// Log level for [`NcOptions`][crate::NcOptions].
///
/// # Default
///
/// These log levels consciously map cleanly to those of libav; notcurses itself
/// does not use this full granularity.
///
/// The log level does not affect the opening and closing banners,
/// which can be disabled via [`NcFlag::SuppressBanners`]
///
/// [`NcFlag::SuppressBanners`]: crate::NcFlag#associatedconstant.SuppressBanners
///
/// Note that if stderr is connected to the same terminal on which we're
/// rendering, any kind of logging will disrupt the output.
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NcLogLevel {
    /// Default. print nothing once fullscreen service begins.
    Silent = c_api::NCLOGLEVEL_SILENT,

    /// Print diagnostics immediately related to crashing.
    Panic = c_api::NCLOGLEVEL_PANIC,

    /// We're hanging around, but we've had a horrible fault.
    Fatal = c_api::NCLOGLEVEL_FATAL,

    /// We can't keep doin' this, but we can do other things.
    Error = c_api::NCLOGLEVEL_ERROR,

    /// You probably don't want what's happening to happen.
    Warning = c_api::NCLOGLEVEL_WARNING,

    /// "Standard information".
    Info = c_api::NCLOGLEVEL_INFO,

    /// "Detailed information".
    Verbose = c_api::NCLOGLEVEL_VERBOSE,

    /// This is honestly a bit much.
    Debug = c_api::NCLOGLEVEL_DEBUG,

    /// There's probably a better way to do what you want.
    Trace = c_api::NCLOGLEVEL_TRACE,
}

mod std_impls {
    use super::{c_api, NcLogLevel};
    use std::fmt;

    impl Default for NcLogLevel {
        fn default() -> Self {
            Self::Silent
        }
    }

    impl fmt::Display for NcLogLevel {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            use NcLogLevel::*;
            write!(
                f,
                "{}",
                match self {
                    Silent => "Silent",
                    Panic => "Panic",
                    Fatal => "Fatal",
                    Error => "Error",
                    Warning => "Warning",
                    Info => "Info",
                    Verbose => "Verbose",
                    Debug => "Debug",
                    Trace => "Trace",
                }
            )
        }
    }

    impl From<c_api::NcLogLevel_i32> for NcLogLevel {
        fn from(log_level: c_api::NcLogLevel_i32) -> Self {
            use {c_api::*, NcLogLevel::*};
            match log_level {
                NCLOGLEVEL_SILENT => Silent,
                NCLOGLEVEL_PANIC => Panic,
                NCLOGLEVEL_FATAL => Fatal,
                NCLOGLEVEL_ERROR => Error,
                NCLOGLEVEL_WARNING => Warning,
                NCLOGLEVEL_INFO => Info,
                NCLOGLEVEL_VERBOSE => Verbose,
                NCLOGLEVEL_DEBUG => Debug,
                NCLOGLEVEL_TRACE => Trace,
                _ => Self::default(),
            }
        }
    }

    impl From<NcLogLevel> for c_api::NcLogLevel_i32 {
        fn from(loglevel: NcLogLevel) -> Self {
            use {c_api::*, NcLogLevel::*};
            match loglevel {
                Silent => NCLOGLEVEL_SILENT,
                Panic => NCLOGLEVEL_PANIC,
                Fatal => NCLOGLEVEL_FATAL,
                Error => NCLOGLEVEL_ERROR,
                Warning => NCLOGLEVEL_WARNING,
                Info => NCLOGLEVEL_INFO,
                Verbose => NCLOGLEVEL_VERBOSE,
                Debug => NCLOGLEVEL_DEBUG,
                Trace => NCLOGLEVEL_TRACE,
            }
        }
    }
}

pub(crate) mod c_api {
    use crate::c_api::ffi;

    /// Log level for [`NcOptions`][crate::NcOptions].
    ///
    /// It's recommended to use [`NcLogLevel`][crate::NcLogLevel] instead.
    ///
    /// # Associated `c_api` constants
    /// - [`NCLOGLEVEL_SILENT`]
    /// - [`NCLOGLEVEL_PANIC`]
    /// - [`NCLOGLEVEL_FATAL`]
    /// - [`NCLOGLEVEL_ERROR`]
    /// - [`NCLOGLEVEL_WARNING`]
    /// - [`NCLOGLEVEL_INFO`]
    /// - [`NCLOGLEVEL_VERBOSE`]
    /// - [`NCLOGLEVEL_DEBUG`]
    /// - [`NCLOGLEVEL_TRACE`]
    ///
    /// These log levels consciously map cleanly to those of libav; notcurses itself
    /// does not use this full granularity. The log level does not affect the opening
    /// and closing banners, which can be disabled via the `NcOptions`
    /// `NCOPTION_SUPPRESS_BANNERS`.
    ///
    /// Note that if stderr is connected to the same terminal on which we're
    /// rendering, any kind of logging will disrupt the output.
    pub type NcLogLevel_i32 = ffi::ncloglevel_e;

    /// [`NcLogLevel_i32`] default. print nothing once fullscreen service begins.
    pub const NCLOGLEVEL_SILENT: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_SILENT;

    /// [`NcLogLevel_i32`] print diagnostics immediately related to crashing.
    pub const NCLOGLEVEL_PANIC: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_PANIC;

    /// [`NcLogLevel_i32`] we're hanging around, but we've had a horrible fault.
    pub const NCLOGLEVEL_FATAL: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_FATAL;

    /// [`NcLogLevel_i32`] we can't keep doin' this, but we can do other things.
    pub const NCLOGLEVEL_ERROR: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_ERROR;

    /// [`NcLogLevel_i32`] you probably don't want what's happening to happen.
    pub const NCLOGLEVEL_WARNING: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_WARNING;

    /// [`NcLogLevel_i32`] "detailed information.
    pub const NCLOGLEVEL_INFO: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_INFO;

    /// [`NcLogLevel_i32`] "detailed information.
    pub const NCLOGLEVEL_VERBOSE: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_VERBOSE;

    /// [`NcLogLevel_i32`] this is honestly a bit much.
    pub const NCLOGLEVEL_DEBUG: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_DEBUG;

    /// [`NcLogLevel_i32`] there's probably a better way to do what you want.
    pub const NCLOGLEVEL_TRACE: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_TRACE;
}