libnotcurses_sys/notcurses/options/mod.rs
1//! `NcOptions`
2
3use crate::{c_api::ffi, NcLogLevel};
4use core::ptr::null;
5
6mod builder;
7pub(crate) mod flags;
8
9pub use builder::NcOptionsBuilder;
10pub use flags::NcFlag;
11
12/// Options struct for [`Nc`][crate::Nc].
13///
14/// # Fields
15/// - [`termtype`]: The name of the terminfo database entry describing this terminal.
16/// - [`loglevel`]: stderr output [`NcLogLevel`][crate::NcLogLevel].
17/// - [`margin_t`]: Desirable top margin.
18/// - [`margin_r`]: Desirable right margin.
19/// - [`margin_b`]: Desirable bottom margin.
20/// - [`margin_l`]: Desirable left margin.
21/// - [`flags`]: [`NcFlag`] flags.
22///
23/// [`termtype`]: ffi::notcurses_options#structfield.termtype
24/// [`loglevel`]: ffi::notcurses_options#structfield.loglevel
25/// [`margin_t`]: ffi::notcurses_options#structfield.margin_t
26/// [`margin_r`]: ffi::notcurses_options#structfield.margin_r
27/// [`margin_b`]: ffi::notcurses_options#structfield.margin_b
28/// [`margin_l`]: ffi::notcurses_options#structfield.margin_l
29/// [`flags`]: NcOptions#associatedconstant.flags
30pub type NcOptions = ffi::notcurses_options;
31
32/// # constructors
33impl NcOptions {
34 /// Returns a default `Nc` options builder.
35 pub fn builder() -> NcOptionsBuilder {
36 NcOptionsBuilder::default()
37 }
38
39 /// Returns a builder object from the current `Nc` options.
40 pub fn to_builder(&self) -> NcOptionsBuilder {
41 NcOptionsBuilder::from_options(self)
42 }
43
44 //
45
46 /// New `NcOptions`.
47 pub fn new() -> Self {
48 Self::with_all_options(NcLogLevel::Silent, Some((0, 0, 0, 0)), NcFlag::None)
49 }
50
51 /// New `NcOptions`, with margins.
52 pub fn with_margins(top: u32, right: u32, bottom: u32, left: u32) -> Self {
53 Self::with_all_options(
54 NcLogLevel::Silent,
55 Some((top, right, bottom, left)),
56 NcFlag::None,
57 )
58 }
59
60 /// New `NcOptions`, with flags.
61 pub fn with_flags(flags: NcFlag) -> Self {
62 Self::with_all_options(NcLogLevel::Silent, Some((0, 0, 0, 0)), flags)
63 }
64
65 /// New `NcOptions`, with flags
66 pub fn with_all_options(
67 loglevel: NcLogLevel,
68 trbl_margins: Option<(u32, u32, u32, u32)>,
69 flags: NcFlag,
70 ) -> NcOptions {
71 let (margin_t, margin_r, margin_b, margin_l) = trbl_margins.unwrap_or((0, 0, 0, 0));
72 NcOptions {
73 termtype: null(),
74 loglevel: loglevel.into(),
75 margin_t,
76 margin_r,
77 margin_b,
78 margin_l,
79 flags: flags.into(),
80 }
81 }
82}
83
84/// # methods
85impl NcOptions {
86 /// Returns the `(top, right, bottom, left)` margins.
87 pub fn margins(&self) -> (u32, u32, u32, u32) {
88 (self.margin_t, self.margin_r, self.margin_b, self.margin_l)
89 }
90
91 /// Returns the log level.
92 pub fn log_level(&self) -> NcLogLevel {
93 self.loglevel.into()
94 }
95
96 // flags
97
98 /// Returns `true` if it has the [`DrainInput`] flag set.
99 ///
100 /// [`DrainInput`]: NcFlag#associatedconstant.DrainInput
101 pub fn is_drain_input(&self) -> bool {
102 self.flags & NcFlag::DrainInput != NcFlag::None
103 }
104
105 /// Returns `true` if it has the [`InhibitSetLocale`] flag set.
106 ///
107 /// [`InhibitSetLocale`]: NcFlag#associatedconstant.InhibitSetLocale
108 pub fn is_inhibit_set_locale(&self) -> bool {
109 self.flags & NcFlag::InhibitSetLocale != NcFlag::None
110 }
111
112 /// Returns `true` if it has the [`NoAlternateScreen`] flag set.
113 ///
114 /// [`NoAlternateScreen`]: NcFlag#associatedconstant.NoAlternateScreen
115 pub fn is_no_alternate_screen(&self) -> bool {
116 self.flags & NcFlag::NoAlternateScreen != NcFlag::None
117 }
118
119 /// Returns `true` if it has the [`NoClearBitmaps`] flag set.
120 ///
121 /// [`NoClearBitmaps`]: NcFlag#associatedconstant.NoClearBitmaps
122 pub fn is_no_clear_bitmaps(&self) -> bool {
123 self.flags & NcFlag::NoClearBitmaps != NcFlag::None
124 }
125
126 /// Returns `true` if it has the [`NoFontChanges`] flag set.
127 ///
128 /// [`NoFontChanges`]: NcFlag#associatedconstant.NoFontChanges
129 pub fn is_no_font_changes(&self) -> bool {
130 self.flags & NcFlag::NoFontChanges != NcFlag::None
131 }
132
133 /// Returns `true` if it has the [`NoQuitSigHandlers`] flag set.
134 ///
135 /// [`NoQuitSigHandlers`]: NcFlag#associatedconstant.NoQuitSigHandlers
136 pub fn is_no_quit_sig_handlers(&self) -> bool {
137 self.flags & NcFlag::NoQuitSigHandlers != NcFlag::None
138 }
139
140 /// Returns `true` if it has the [`NoWinchSigHandler`] flag set.
141 ///
142 /// [`NoWinchSigHandler`]: NcFlag#associatedconstant.NoWinchSigHandler
143 pub fn is_no_winch_sig_handler(&self) -> bool {
144 self.flags & NcFlag::NoWinchSigHandler != NcFlag::None
145 }
146
147 /// Returns `true` if it has the [`PreserveCursor`] flag set.
148 ///
149 /// [`PreserveCursor`]: NcFlag#associatedconstant.PreserveCursor
150 pub fn is_preserve_cursor(&self) -> bool {
151 self.flags & NcFlag::PreserveCursor != NcFlag::None
152 }
153
154 /// Returns `true` if it has the [`Scrolling`] flag set.
155 ///
156 /// [`Scrolling`]: NcFlag#associatedconstant.Scrolling
157 pub fn is_scrolling(&self) -> bool {
158 self.flags & NcFlag::Scrolling != NcFlag::None
159 }
160
161 /// Returns `true` if it has the [`CliMode`] flag set.
162 ///
163 /// [`CliMode`]: NcFlag#associatedconstant.CliMode
164 // CHECK boolean logic
165 pub fn is_cli_mode(&self) -> bool {
166 self.flags & NcFlag::CliMode != NcFlag::None
167 }
168
169 /// Returns `true` if it has the [`SuppressBanners`] flag set.
170 ///
171 /// [`SuppressBanners`]: NcFlag#associatedconstant.SuppressBanners
172 pub fn is_suppress_banners(&self) -> bool {
173 self.flags & NcFlag::SuppressBanners != NcFlag::None
174 }
175}