rust: more refactoring

- make Notcurses `new()` constructor not output banners.
- add an additional constructor `with_banners()`.
- add new aliases for running examples silently.
- improve comments & run rustfmt.
dankamongmen/clock_nanosleep_portable
joseLuís 4 years ago
parent 0d31a03be9
commit 04882971a2

@ -3,6 +3,8 @@ d = "doc --no-deps"
do = "doc --no-deps --open"
re = "run --example"
rqe = "run --quiet --example "
req = "rqe"
# TEST
# fix IO errors: https://github.com/dankamongmen/notcurses/issues/766

@ -1,5 +1,4 @@
#[allow(unused_imports)]
use crate::Cell;
// Cell ------------------------------------------------------------------------
@ -60,4 +59,3 @@ macro_rules! cell_trivial_initializer {
// #define PREFIXFMT(x) NCMETRICFWIDTH((x), PREFIXCOLUMNS), (x)
// #define IPREFIXFMT(x) NCMETRIXFWIDTH((x), IPREFIXCOLUMNS), (x)
// #define BPREFIXFMT(x) NCMETRICFWIDTH((x), BPREFIXCOLUMNS), (x)

@ -63,9 +63,10 @@ use crate::{
notcurses_init,
notcurses_stdplane,
notcurses_stdplane_const,
types::{NcAlign, NcInput, NcLogLevel, NcPlane, Notcurses, NotcursesOptions},
NCALIGN_CENTER,
NCALIGN_LEFT,
types::{
NcAlign, NcInput, NcLogLevel, NcPlane, Notcurses, NotcursesOptions, NCALIGN_CENTER,
NCALIGN_LEFT, NCOPTION_SUPPRESS_BANNERS,
},
};
impl NotcursesOptions {
@ -104,10 +105,17 @@ impl NotcursesOptions {
///
/// - flags
///
/// General flags; see NCOPTION_*. This is expressed as a bitfield so that
/// future options can be added without reshaping the struct.
/// General flags; This is expressed as a bitfield so that future options
/// can be added without reshaping the struct.
/// Undefined bits must be set to 0.
///
/// - [`NCOPTION_INHIBIT_SETLOCALE`](type.NCOPTION_INHIBIT_SETLOCALE.html)
/// - [`NCOPTION_NO_ALTERNATE_SCREEN`](type.NCOPTION_NO_ALTERNATE_SCREEN.html)
/// - [`NCOPTION_NO_FONT_CHANGES`](type.NCOPTION_NO_FONT_CHANGES.html)
/// - [`NCOPTION_NO_QUIT_SIGHANDLERS`](type.NCOPTION_NO_QUIT_SIGHANDLERS.html)
/// - [`NCOPTION_NO_WINCH_SIGHANDLER`](type.NCOPTION_NO_WINCH_SIGHANDLER.html)
/// - [`NCOPTION_SUPPRESS_BANNERS`](type.NCOPTION_SUPPRESS_BANNERS.html)
///
pub fn with_all_options(
loglevel: NcLogLevel,
margin_t: i32,
@ -130,13 +138,19 @@ impl NotcursesOptions {
}
impl Notcurses {
/// `Notcurses` simple constructor
/// `Notcurses` simple constructor with clean output
pub unsafe fn new<'a>() -> &'a mut Notcurses {
let options = NotcursesOptions::with_flags(NCOPTION_SUPPRESS_BANNERS);
&mut *notcurses_init(&options, null_mut())
}
/// `Notcurses` simple constructor, showing banners
pub unsafe fn with_banners<'a>() -> &'a mut Notcurses {
&mut *notcurses_init(&NotcursesOptions::new(), null_mut())
}
/// `Notcurses` constructor with options
pub unsafe fn with_options(options: &NotcursesOptions) -> &mut Notcurses {
pub unsafe fn with_options<'a>(options: &NotcursesOptions) -> &'a mut Notcurses {
&mut *notcurses_init(options, null_mut())
}
}

@ -1,5 +1,5 @@
//! Miscellaneous types and constants
//!
//!
// error handling --------------------------------------------------------------

@ -31,7 +31,8 @@ pub use channel::{
CHANNEL_ALPHA_MASK,
};
pub use misc::{
IntResult, PREFIXCOLUMNS, BPREFIXCOLUMNS, IPREFIXCOLUMNS, PREFIXSTRLEN, BPREFIXSTRLEN, IPREFIXSTRLEN
IntResult, BPREFIXCOLUMNS, BPREFIXSTRLEN, IPREFIXCOLUMNS, IPREFIXSTRLEN, PREFIXCOLUMNS,
PREFIXSTRLEN,
};
pub use plane::{
NCBLIT_1x1, NCBLIT_2x1, NCBLIT_2x2, NCBLIT_3x2, NCBLIT_4x1, NCBLIT_8x1, NcAlign, NcBlitter,
@ -42,7 +43,9 @@ pub use plane::{
};
pub use terminal::{
NcDirect, NcDirectFlags, NcInput, NcLogLevel, Notcurses, NotcursesOptions,
NCDIRECT_OPTION_INHIBIT_CBREAK, NCDIRECT_OPTION_INHIBIT_SETLOCALE, NCOPTION_INHIBIT_SETLOCALE,
NCDIRECT_OPTION_INHIBIT_CBREAK, NCDIRECT_OPTION_INHIBIT_SETLOCALE, NCLOGLEVEL_DEBUG,
NCLOGLEVEL_ERROR, NCLOGLEVEL_FATAL, NCLOGLEVEL_INFO, NCLOGLEVEL_PANIC, NCLOGLEVEL_SILENT,
NCLOGLEVEL_TRACE, NCLOGLEVEL_VERBOSE, NCLOGLEVEL_WARNING, NCOPTION_INHIBIT_SETLOCALE,
NCOPTION_NO_ALTERNATE_SCREEN, NCOPTION_NO_FONT_CHANGES, NCOPTION_NO_QUIT_SIGHANDLERS,
NCOPTION_NO_WINCH_SIGHANDLER, NCOPTION_SUPPRESS_BANNERS, NCOPTION_VERIFY_SIXEL,
};

Loading…
Cancel
Save