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 169 170 171 172 173 174 175
//! `NcOptions`
use crate::{c_api::ffi, NcLogLevel};
use std::ptr::null;
mod builder;
pub(crate) mod flags;
pub use builder::NcOptionsBuilder;
pub use flags::NcFlag;
/// Options struct for [`Nc`][crate::Nc].
///
/// # Fields
/// - [`termtype`]: The name of the terminfo database entry describing this terminal.
/// - [`loglevel`]: stderr output [`NcLogLevel`][crate::NcLogLevel].
/// - [`margin_t`]: Desirable top margin.
/// - [`margin_r`]: Desirable right margin.
/// - [`margin_b`]: Desirable bottom margin.
/// - [`margin_l`]: Desirable left margin.
/// - [`flags`]: [`NcFlag`] flags.
///
/// [`termtype`]: ffi::notcurses_options#structfield.termtype
/// [`loglevel`]: ffi::notcurses_options#structfield.loglevel
/// [`margin_t`]: ffi::notcurses_options#structfield.margin_t
/// [`margin_r`]: ffi::notcurses_options#structfield.margin_r
/// [`margin_b`]: ffi::notcurses_options#structfield.margin_b
/// [`margin_l`]: ffi::notcurses_options#structfield.margin_l
/// [`flags`]: NcOptions#associatedconstant.flags
pub type NcOptions = ffi::notcurses_options;
/// # constructors
impl NcOptions {
/// Returns a default `Nc` options builder.
pub fn builder() -> NcOptionsBuilder {
NcOptionsBuilder::default()
}
/// Returns a builder object from the current `Nc` options.
pub fn to_builder(&self) -> NcOptionsBuilder {
NcOptionsBuilder::from_options(self)
}
//
/// New `NcOptions`.
pub fn new() -> Self {
Self::with_all_options(NcLogLevel::Silent, Some((0, 0, 0, 0)), NcFlag::None)
}
/// New `NcOptions`, with margins.
pub fn with_margins(top: u32, right: u32, bottom: u32, left: u32) -> Self {
Self::with_all_options(
NcLogLevel::Silent,
Some((top, right, bottom, left)),
NcFlag::None,
)
}
/// New `NcOptions`, with flags.
pub fn with_flags(flags: NcFlag) -> Self {
Self::with_all_options(NcLogLevel::Silent, Some((0, 0, 0, 0)), flags)
}
/// New `NcOptions`, with flags
pub fn with_all_options(
loglevel: NcLogLevel,
trbl_margins: Option<(u32, u32, u32, u32)>,
flags: NcFlag,
) -> NcOptions {
let (margin_t, margin_r, margin_b, margin_l) = trbl_margins.unwrap_or((0, 0, 0, 0));
NcOptions {
termtype: null(),
loglevel: loglevel.into(),
margin_t,
margin_r,
margin_b,
margin_l,
flags: flags.into(),
}
}
}
/// # methods
impl NcOptions {
/// Returns the `(top, right, bottom, left)` margins.
pub fn margins(&self) -> (u32, u32, u32, u32) {
(self.margin_t, self.margin_r, self.margin_b, self.margin_l)
}
/// Returns the log level.
pub fn log_level(&self) -> NcLogLevel {
self.loglevel.into()
}
// flags
/// Returns `true` if it has the [`DrainInput`] flag set.
///
/// [`DrainInput`]: NcFlag#associatedconstant.DrainInput
pub fn is_drain_input(&self) -> bool {
self.flags & NcFlag::DrainInput != NcFlag::None
}
/// Returns `true` if it has the [`InhibitSetLocale`] flag set.
///
/// [`InhibitSetLocale`]: NcFlag#associatedconstant.InhibitSetLocale
pub fn is_inhibit_set_locale(&self) -> bool {
self.flags & NcFlag::InhibitSetLocale != NcFlag::None
}
/// Returns `true` if it has the [`NoAlternateScreen`] flag set.
///
/// [`NoAlternateScreen`]: NcFlag#associatedconstant.NoAlternateScreen
pub fn is_no_alternate_screen(&self) -> bool {
self.flags & NcFlag::NoAlternateScreen != NcFlag::None
}
/// Returns `true` if it has the [`NoClearBitmaps`] flag set.
///
/// [`NoClearBitmaps`]: NcFlag#associatedconstant.NoClearBitmaps
pub fn is_no_clear_bitmaps(&self) -> bool {
self.flags & NcFlag::NoClearBitmaps != NcFlag::None
}
/// Returns `true` if it has the [`NoFontChanges`] flag set.
///
/// [`NoFontChanges`]: NcFlag#associatedconstant.NoFontChanges
pub fn is_no_font_changes(&self) -> bool {
self.flags & NcFlag::NoFontChanges != NcFlag::None
}
/// Returns `true` if it has the [`NoQuitSigHandlers`] flag set.
///
/// [`NoQuitSigHandlers`]: NcFlag#associatedconstant.NoQuitSigHandlers
pub fn is_no_quit_sig_handlers(&self) -> bool {
self.flags & NcFlag::NoQuitSigHandlers != NcFlag::None
}
/// Returns `true` if it has the [`NoWinchSigHandler`] flag set.
///
/// [`NoWinchSigHandler`]: NcFlag#associatedconstant.NoWinchSigHandler
pub fn is_no_winch_sig_handler(&self) -> bool {
self.flags & NcFlag::NoWinchSigHandler != NcFlag::None
}
/// Returns `true` if it has the [`PreserveCursor`] flag set.
///
/// [`PreserveCursor`]: NcFlag#associatedconstant.PreserveCursor
pub fn is_preserve_cursor(&self) -> bool {
self.flags & NcFlag::PreserveCursor != NcFlag::None
}
/// Returns `true` if it has the [`Scrolling`] flag set.
///
/// [`Scrolling`]: NcFlag#associatedconstant.Scrolling
pub fn is_scrolling(&self) -> bool {
self.flags & NcFlag::Scrolling != NcFlag::None
}
/// Returns `true` if it has the [`CliMode`] flag set.
///
/// [`CliMode`]: NcFlag#associatedconstant.CliMode
// CHECK boolean logic
pub fn is_cli_mode(&self) -> bool {
self.flags & NcFlag::CliMode != NcFlag::None
}
/// Returns `true` if it has the [`SuppressBanners`] flag set.
///
/// [`SuppressBanners`]: NcFlag#associatedconstant.SuppressBanners
pub fn is_suppress_banners(&self) -> bool {
self.flags & NcFlag::SuppressBanners != NcFlag::None
}
}