libnotcurses_sys/direct/mod.rs
1//! `NcDirect`
2
3// total: 63
4// ---------------------------------------------------
5// (X) 1 : wont do
6// (~) 3 : TODO / WIP
7//
8// (f) 46 : unsafe ffi function exported by bindgen
9// (w) 1 : safely wrapped ffi function
10// (r) 11 : static function manually reimplemented
11//
12// (m) 54 : method implemented
13//
14// (t) 0 : unit test done for the function
15// (T) 0 : unit test done also for the method
16// ---------------------------------------------------
17// fm ncdirect_bg_default
18// fm ncdirect_bg_palindex
19// fm ncdirect_bg_rgb
20// fm ncdirect_box
21// rm ncdirect_canbraille
22// rm ncdirect_canchangecolor
23// fm ncdirect_canget_cursor
24// rm ncdirect_canfade
25// rm ncdirect_canhalfblock
26// rm ncdirect_canopen_images
27// rm ncdirect_canopen_videos
28// rm ncdirect_canquadrant
29// rm ncdirect_cantruecolor
30// fm ncdirect_canutf8
31// wm ncdirect_capabilities
32// fm ncdirect_check_pixel_support
33// fm ncdirect_clear
34//~f ncdirect_core_init
35// fm ncdirect_cursor_disable
36// fm ncdirect_cursor_down
37// fm ncdirect_cursor_enable
38// fm ncdirect_cursor_left
39// fm ncdirect_cursor_move_yx
40// fm ncdirect_cursor_pop
41// fm ncdirect_cursor_push
42// fm ncdirect_cursor_right
43// fm ncdirect_cursor_up
44// fm ncdirect_cursor_yx
45// fm ncdirect_detected_terminal
46// fm ncdirect_dim_x
47// fm ncdirect_dim_y
48// fm ncdirect_double_box
49// fm ncdirect_fg_default
50// fm ncdirect_fg_palindex
51// fm ncdirect_fg_rgb
52// fm ncdirect_flush
53// fm ncdirect_get
54//~r ncdirect_heavy_box,
55// fm ncdirect_hline_interp
56// fm ncdirect_init
57// fm ncdirect_inputready_fd
58//~r ncdirect_light_box,
59// fm ncplane_on_styles
60// fm ncplane_off_styles
61// fm ncdirect_palette_size
62//X ncdirect_printf_aligned
63// f ncdirect_putegc
64// fm ncdirect_putstr
65// fm ncdirect_raster_frame
66// fm ncdirect_readline
67// fm ncdirect_render_frame
68// fm ncdirect_render_image
69// fm ncdirect_rounded_box
70// fm ncdirect_set_styles
71// fm ncdirect_stop
72// f ncdirect_stream
73// f ncdirect_styles
74// f ncdirect_supported_styles
75// fm ncdirect_vline_interp
76// r ncdirect_bg_rgb8 // unneeded method
77// r ncdirect_fg_rgb8 // unneeded method
78// rm ncdirect_get_blocking
79// rm ncdirect_get_nblock
80
81#[cfg(test)]
82mod test;
83
84mod methods;
85pub(crate) mod reimplemented;
86
87use c_api::NcDirectFlag_u64;
88
89/// Minimal notcurses instance for styling text.
90pub type NcDirect = crate::c_api::ffi::ncdirect;
91
92/// A bitmask of [`NcDirect`][crate::NcDirect] flags.
93///
94/// # Flag
95/// - [`DrainInput`][NcDirectFlag::DrainInput]
96/// - [`InhibitCbreak`][NcDirectFlag::InhibitCbreak]
97/// - [`InhibitSetLocale`][NcDirectFlag::InhibitSetLocale]
98/// - [`NoQuitSigHandlers`][NcDirectFlag::NoQuitSigHandlers]
99/// - [`Verbose`][NcDirectFlag::Verbose]
100/// - [`VeryVerbose`][NcDirectFlag::VeryVerbose]
101///
102/// # Default
103/// *[`NcDirectFlag::None`]
104///
105#[derive(Copy, Clone, Debug, PartialEq, Eq)]
106pub struct NcDirectFlag(pub NcDirectFlag_u64);
107
108///
109impl NcDirectFlag {
110 /// No flags.
111 pub const None: NcDirectFlag = Self(0);
112
113 /// Flag that indicates input may be freely dropped.
114 ///
115 /// This ought be provided when the program does not intend to handle input.
116 /// Otherwise, input can accumulate in internal buffers, eventually preventing
117 /// Notcurses from processing terminal messages.
118 pub const DrainInput: NcDirectFlag =
119 Self(c_api::NCDIRECT_OPTION_DRAIN_INPUT as NcDirectFlag_u64);
120
121 /// Flag that avoids placing the terminal into cbreak mode
122 /// (disabling echo and line buffering).
123 ///
124 pub const InhibitCbreak: NcDirectFlag =
125 Self(c_api::NCDIRECT_OPTION_INHIBIT_CBREAK as NcDirectFlag_u64);
126
127 /// Flag that avoids calling setlocale(LC_ALL, NULL).
128 ///
129 /// If the result is either "C" or "POSIX", it will print a
130 /// diagnostic to stderr, and then call setlocale(LC_ALL, "").
131 ///
132 /// This will attempt to set the locale based off the LANG
133 /// environment variable. Your program should call setlocale(3)
134 /// itself, usually as one of the first lines.
135 ///
136 pub const InhibitSetLocale: NcDirectFlag =
137 Self(c_api::NCDIRECT_OPTION_INHIBIT_SETLOCALE as NcDirectFlag_u64);
138
139 /// Flag that inhibits registration of the `SIGABRT`, `SIGBUS`, `SIGFPE`,
140 /// `SIGILL`, `SIGINT`, `SIGQUIT`, `SIGSEGV` and `SIGTERM`, signal handlers.
141 pub const NoQuitSigHandlers: NcDirectFlag =
142 Self(c_api::NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS as NcDirectFlag_u64);
143
144 /// Flag that enables showing detailed information.
145 pub const Verbose: NcDirectFlag = Self(c_api::NCDIRECT_OPTION_VERBOSE as NcDirectFlag_u64);
146
147 /// Flag that enables showing all diagnostics (equivalent to
148 /// [`NcLogLevel::trace`]. Implies [`NcDirectFlag::Verbose`].
149 ///
150 /// [`NcLogLevel::Trace`]: crate::NcLogLevel#associatedconstant.Trace
151 pub const VeryVerbose: NcDirectFlag =
152 Self(c_api::NCDIRECT_OPTION_VERY_VERBOSE as NcDirectFlag_u64);
153}
154
155mod core_impls {
156 use super::{c_api::NcDirectFlag_u64, NcDirectFlag};
157
158 impl Default for NcDirectFlag {
159 fn default() -> Self {
160 Self::None
161 }
162 }
163
164 crate::from_primitive![NcDirectFlag, NcDirectFlag_u64];
165 crate::unit_impl_from![NcDirectFlag, NcDirectFlag_u64];
166 crate::unit_impl_ops![bitwise; NcDirectFlag, NcDirectFlag_u64];
167 crate::unit_impl_fmt![bases+display; NcDirectFlag];
168}
169
170pub(crate) mod c_api {
171 use crate::c_api::ffi;
172
173 /// A bitmask of [`NcDirect`][crate::NcDirect] flags.
174 ///
175 /// It's recommended to use [`NcDirectFlag`][crate::NcDirectFlag] instead.
176 ///
177 /// # Associated `c_api` constants
178 /// - [`NCDIRECT_OPTION_DRAIN_INPUT`]
179 /// - [`NCDIRECT_OPTION_INHIBIT_CBREAK`]
180 /// - [`NCDIRECT_OPTION_INHIBIT_SETLOCALE`]
181 /// - [`NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS`]
182 /// - [`NCDIRECT_OPTION_VERBOSE`]
183 /// - [`NCDIRECT_OPTION_VERY_VERBOSE`]
184 pub type NcDirectFlag_u64 = u64;
185
186 /// [`NcDirectFlag_u64`] flag that indicates input may be freely dropped.
187 ///
188 /// This ought be provided when the program does not intend to handle input.
189 /// Otherwise, input can accumulate in internal buffers, eventually
190 /// preventing *notcurses* from processing terminal messages.
191 pub const NCDIRECT_OPTION_DRAIN_INPUT: NcDirectFlag_u64 =
192 ffi::NCDIRECT_OPTION_DRAIN_INPUT as NcDirectFlag_u64;
193
194 /// [`NcDirectFlag_u64`] flag to avoid placing the terminal into cbreak
195 /// mode (disabling echo and line buffering)
196 pub const NCDIRECT_OPTION_INHIBIT_CBREAK: NcDirectFlag_u64 =
197 ffi::NCDIRECT_OPTION_INHIBIT_CBREAK as NcDirectFlag_u64;
198
199 /// [`NcDirectFlag_u64`] flag to avoid calling setlocale(LC_ALL, NULL)
200 ///
201 /// If the result is either "C" or "POSIX", it will print a
202 /// diagnostic to stderr, and then call setlocale(LC_ALL, "").
203 ///
204 /// This will attempt to set the locale based off the LANG
205 /// environment variable. Your program should call setlocale(3)
206 /// itself, usually as one of the first lines.
207 ///
208 pub const NCDIRECT_OPTION_INHIBIT_SETLOCALE: NcDirectFlag_u64 =
209 ffi::NCDIRECT_OPTION_INHIBIT_SETLOCALE as NcDirectFlag_u64;
210
211 /// [`NcDirectFlag_u64`] flag that inhibits registration of the `SIGINT`,
212 /// `SIGSEGV`, `SIGABRT` & `SIGQUIT` signal handlers.
213 pub const NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS: NcDirectFlag_u64 =
214 ffi::NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS as NcDirectFlag_u64;
215
216 /// [`NcDirectFlag_u64`] flag that enables showing detailed information.
217 pub const NCDIRECT_OPTION_VERBOSE: NcDirectFlag_u64 =
218 ffi::NCDIRECT_OPTION_VERBOSE as NcDirectFlag_u64;
219
220 /// [`NcDirectFlag_u64`] flag that enables showing all diagnostics
221 /// (equivalent to [`NCLOGLEVEL_TRACE`]).
222 /// Implies [`NCDIRECT_OPTION_VERBOSE`].
223 ///
224 /// [`NCLOGLEVEL_TRACE`]: crate::c_api::NCLOGLEVEL_TRACE
225 pub const NCDIRECT_OPTION_VERY_VERBOSE: NcDirectFlag_u64 =
226 ffi::NCDIRECT_OPTION_VERY_VERBOSE as NcDirectFlag_u64;
227}