rust: finish Notcurses methods & fix tests

This commit is contained in:
joseLuís 2020-12-24 03:24:39 +01:00
parent b62c1ec74b
commit 7d53abc1b1
5 changed files with 69 additions and 30 deletions

View File

@ -1,6 +1,6 @@
//! Test `NcCell` methods and associated functions.
use crate::NcCell;
use crate::{NcCell, NcPlane, Notcurses};
use serial_test::serial;
@ -8,6 +8,9 @@ use serial_test::serial;
#[serial]
fn constructors() {
let _c1 = NcCell::new();
let _c2 = NcCell::with_char7b('C');
let _c2 = NcCell::with_7bitchar('C');
let _n0 = Notcurses::new();
let _p0 = NcPlane::new(_n0, 0, 0, 10, 10);
let _c3 = NcCell::with_char('௵', _p0);
}

View File

@ -18,7 +18,7 @@ fn channels() {
assert_eq![0xBB445566, crate::cell_bchannel(&c1)];
assert_eq![0xAA112233BB445566, channels];
let c2 = NcCell::with_7bitchar('@');
let _c2 = NcCell::with_char7b('@');
}
#[test]

View File

@ -4,9 +4,10 @@ use core::ptr::{null, null_mut};
use std::ffi::CStr;
use crate::{
cstring, notcurses_init, sigset_t, NcBlitter, NcChannelPair, NcDimension, NcEgc, NcFile,
NcInput, NcLogLevel, NcPlane, NcResult, NcScale, NcStats, NcStyleMask, NcTime, Notcurses,
NotcursesOptions, NCOPTION_NO_ALTERNATE_SCREEN, NCOPTION_SUPPRESS_BANNERS, NCRESULT_OK,
cstring, notcurses_init, sigset_t, NcAlign, NcBlitter, NcChannelPair, NcDimension, NcEgc,
NcFile, NcInput, NcLogLevel, NcPlane, NcResult, NcScale, NcStats, NcStyleMask, NcTime,
Notcurses, NotcursesOptions, NCOPTION_NO_ALTERNATE_SCREEN, NCOPTION_SUPPRESS_BANNERS,
NCRESULT_OK,
};
/// # `NotcursesOptions` Constructors
@ -118,17 +119,16 @@ impl Notcurses {
/// # `Notcurses` methods
impl Notcurses {
//
// /// Returns the offset into 'availcols' at which 'cols' ought be output given
// /// the requirements of `align`.
// ///
// /// Returns -NCRESULT_MAX if NCALIGN_UNALIGNED or invalid NcAlign.
//
// ///
// /// *C style function: [notcurses_at_yx()][crate::notcurses_at_yx].*
// pub fn canchangecolor(&self) -> bool {
// unsafe { crate::notcurses_canchangecolor(self) }
// }
/// Returns the offset into `availcols` at which `cols` ought be output given
/// the requirements of `align`.
///
/// Returns `-`[`NCRESULT_MAX`][crate::NCRESULT_MAX] if
/// [NCALIGN_UNALIGNED][crate::NCALIGN_UNALIGNED] or invalid [NcAlign].
///
/// *C style function: [notcurses_align()][crate::notcurses_align].*
pub fn align(availcols: NcDimension, align: NcAlign, cols: NcDimension) -> NcResult {
crate::notcurses_align(availcols, align, cols)
}
/// Retrieves the current contents of the specified [NcCell][crate::NcCell]
/// as last rendered, returning the [NcEgc] (or None on error) and writing
@ -451,6 +451,32 @@ impl Notcurses {
}
}
/// [notcurses_stdplane()][crate::notcurses_stdplane], plus free bonus
/// dimensions written to non-NULL y/x!
///
/// *C style function: [notcurses_stddim_yx()][crate::notcurses_stddim_yx].*
#[inline]
pub fn stddim_yx<'a>(
nc: &'a mut Notcurses,
y: &mut NcDimension,
x: &mut NcDimension,
) -> &'a mut NcPlane {
crate::notcurses_stddim_yx(nc, y, x)
}
/// [stdplane_const()][#method.stdplane_const], plus free
/// bonus dimensions written to non-NULL y/x!
///
/// *C style function: [notcurses_stddim_yx()][crate::notcurses_stddim_yx].*
#[inline]
pub fn stddim_yx_const<'a>(
nc: &'a Notcurses,
y: &mut NcDimension,
x: &mut NcDimension,
) -> &'a NcPlane {
crate::notcurses_stddim_yx_const(nc, y, x)
}
/// Returns a mutable reference to the standard [NcPlane] for this terminal.
///
/// The standard plane always exists, and its origin is always at the

View File

@ -51,14 +51,14 @@
// -----------------------------------------
// (+) done: 6 / 0
// (#) test: 0
// (W) wrap: 2
// (W) wrap: 4 / 0
// -----------------------------------------
//W# notcurses_align
//W+ notcurses_getc_blocking
//W+ notcurses_getc_nblock
// + notcurses_stddim_yx
// + notcurses_stddim_yx_const
// + notcurses_term_dim_yx
//W+ notcurses_stddim_yx
//W+ notcurses_stddim_yx_const
//W+ notcurses_term_dim_yx
#[cfg(test)]
mod test;

View File

@ -10,11 +10,13 @@ use crate::{
// can't use libc::sigset_t with notcurses_getc(()
use crate::bindings::{sigemptyset, sigfillset, sigset_t};
/// Returns the offset into 'availcols' at which 'cols' ought be output given
/// the requirements of 'align'.
/// Returns the offset into `availcols` at which `cols` ought be output given
/// the requirements of `align`.
///
/// Returns -[`NCRESULT_MAX`] if [NCALIGN_UNALIGNED][crate::NCALIGN_UNALIGNED]
/// Returns `-`[`NCRESULT_MAX`] if [NCALIGN_UNALIGNED][crate::NCALIGN_UNALIGNED]
/// or invalid [NcAlign].
///
/// *Method: Notcurses.[align()][Notcurses#method.align].*
#[inline]
pub fn notcurses_align(availcols: NcDimension, align: NcAlign, cols: NcDimension) -> NcOffset {
if align == NCALIGN_LEFT {
@ -32,10 +34,12 @@ pub fn notcurses_align(availcols: NcDimension, align: NcAlign, cols: NcDimension
-NCRESULT_MAX // NCALIGN_UNALIGNED
}
/// 'input' may be NULL if the caller is uninterested in event details.
///
/// If no event is ready, returns 0.
///
/// *Method: Notcurses.[getc_nblock()][Notcurses#method.getc_nblock].*
//
// `input` may be NULL if the caller is uninterested in event details.
#[inline]
pub fn notcurses_getc_nblock(nc: &mut Notcurses, input: &mut NcInput) -> char {
unsafe {
@ -63,12 +67,13 @@ pub fn notcurses_getc_nblocking(nc: &mut Notcurses, input: &mut NcInput) -> char
}
}
/// notcurses_stdplane(), plus free bonus dimensions written to non-NULL y/x!
/// [notcurses_stdplane()][crate::notcurses_stdplane], plus free bonus
/// dimensions written to non-NULL y/x!
///
/// *Method: Notcurses.[getc_stddim_yx()][Notcurses#method.stddim_yx].*
#[inline]
pub fn notcurses_stddim_yx<'a>(
nc: &mut Notcurses,
nc: &'a mut Notcurses,
y: &mut NcDimension,
x: &mut NcDimension,
) -> &'a mut NcPlane {
@ -79,14 +84,19 @@ pub fn notcurses_stddim_yx<'a>(
}
}
/// notcurses_stdplane_const(), plus free bonus dimensions written to non-NULL y/x!
/// [notcurses_stdplane_const()][crate::notcurses_stdplane_const], plus free
/// bonus dimensions written to non-NULL y/x!
///
/// *Method: Notcurses.[getc_stddim_yx_const()][Notcurses#method.stddim_yx_const].*
#[inline]
pub fn notcurses_stddim_yx_const<'a>(nc: &'a Notcurses, y: &mut i32, x: &mut i32) -> &'a NcPlane {
pub fn notcurses_stddim_yx_const<'a>(
nc: &'a Notcurses,
y: &mut NcDimension,
x: &mut NcDimension,
) -> &'a NcPlane {
unsafe {
let s = crate::notcurses_stdplane_const(nc);
crate::ncplane_dim_yx(s, y, x);
crate::ncplane_dim_yx(s, &mut (*y as i32), &mut (*x as i32));
&*s
}
}