mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-04 06:00:30 +00:00
rust: finish Notcurses methods & fix tests
This commit is contained in:
parent
b62c1ec74b
commit
7d53abc1b1
@ -1,6 +1,6 @@
|
|||||||
//! Test `NcCell` methods and associated functions.
|
//! Test `NcCell` methods and associated functions.
|
||||||
|
|
||||||
use crate::NcCell;
|
use crate::{NcCell, NcPlane, Notcurses};
|
||||||
|
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
@ -8,6 +8,9 @@ use serial_test::serial;
|
|||||||
#[serial]
|
#[serial]
|
||||||
fn constructors() {
|
fn constructors() {
|
||||||
let _c1 = NcCell::new();
|
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);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ fn channels() {
|
|||||||
assert_eq![0xBB445566, crate::cell_bchannel(&c1)];
|
assert_eq![0xBB445566, crate::cell_bchannel(&c1)];
|
||||||
assert_eq![0xAA112233BB445566, channels];
|
assert_eq![0xAA112233BB445566, channels];
|
||||||
|
|
||||||
let c2 = NcCell::with_7bitchar('@');
|
let _c2 = NcCell::with_char7b('@');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -4,9 +4,10 @@ use core::ptr::{null, null_mut};
|
|||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cstring, notcurses_init, sigset_t, NcBlitter, NcChannelPair, NcDimension, NcEgc, NcFile,
|
cstring, notcurses_init, sigset_t, NcAlign, NcBlitter, NcChannelPair, NcDimension, NcEgc,
|
||||||
NcInput, NcLogLevel, NcPlane, NcResult, NcScale, NcStats, NcStyleMask, NcTime, Notcurses,
|
NcFile, NcInput, NcLogLevel, NcPlane, NcResult, NcScale, NcStats, NcStyleMask, NcTime,
|
||||||
NotcursesOptions, NCOPTION_NO_ALTERNATE_SCREEN, NCOPTION_SUPPRESS_BANNERS, NCRESULT_OK,
|
Notcurses, NotcursesOptions, NCOPTION_NO_ALTERNATE_SCREEN, NCOPTION_SUPPRESS_BANNERS,
|
||||||
|
NCRESULT_OK,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// # `NotcursesOptions` Constructors
|
/// # `NotcursesOptions` Constructors
|
||||||
@ -118,17 +119,16 @@ impl Notcurses {
|
|||||||
|
|
||||||
/// # `Notcurses` methods
|
/// # `Notcurses` methods
|
||||||
impl Notcurses {
|
impl Notcurses {
|
||||||
//
|
/// Returns the offset into `availcols` at which `cols` ought be output given
|
||||||
// /// Returns the offset into 'availcols' at which 'cols' ought be output given
|
/// the requirements of `align`.
|
||||||
// /// the requirements of `align`.
|
///
|
||||||
// ///
|
/// Returns `-`[`NCRESULT_MAX`][crate::NCRESULT_MAX] if
|
||||||
// /// Returns -NCRESULT_MAX if NCALIGN_UNALIGNED or invalid NcAlign.
|
/// [NCALIGN_UNALIGNED][crate::NCALIGN_UNALIGNED] or invalid [NcAlign].
|
||||||
//
|
///
|
||||||
// ///
|
/// *C style function: [notcurses_align()][crate::notcurses_align].*
|
||||||
// /// *C style function: [notcurses_at_yx()][crate::notcurses_at_yx].*
|
pub fn align(availcols: NcDimension, align: NcAlign, cols: NcDimension) -> NcResult {
|
||||||
// pub fn canchangecolor(&self) -> bool {
|
crate::notcurses_align(availcols, align, cols)
|
||||||
// unsafe { crate::notcurses_canchangecolor(self) }
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
/// Retrieves the current contents of the specified [NcCell][crate::NcCell]
|
/// Retrieves the current contents of the specified [NcCell][crate::NcCell]
|
||||||
/// as last rendered, returning the [NcEgc] (or None on error) and writing
|
/// 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.
|
/// Returns a mutable reference to the standard [NcPlane] for this terminal.
|
||||||
///
|
///
|
||||||
/// The standard plane always exists, and its origin is always at the
|
/// The standard plane always exists, and its origin is always at the
|
||||||
|
@ -51,14 +51,14 @@
|
|||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
// (+) done: 6 / 0
|
// (+) done: 6 / 0
|
||||||
// (#) test: 0
|
// (#) test: 0
|
||||||
// (W) wrap: 2
|
// (W) wrap: 4 / 0
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
//W# notcurses_align
|
//W# notcurses_align
|
||||||
//W+ notcurses_getc_blocking
|
//W+ notcurses_getc_blocking
|
||||||
//W+ notcurses_getc_nblock
|
//W+ notcurses_getc_nblock
|
||||||
// + notcurses_stddim_yx
|
//W+ notcurses_stddim_yx
|
||||||
// + notcurses_stddim_yx_const
|
//W+ notcurses_stddim_yx_const
|
||||||
// + notcurses_term_dim_yx
|
//W+ notcurses_term_dim_yx
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
|
@ -10,11 +10,13 @@ use crate::{
|
|||||||
// can't use libc::sigset_t with notcurses_getc(()
|
// can't use libc::sigset_t with notcurses_getc(()
|
||||||
use crate::bindings::{sigemptyset, sigfillset, sigset_t};
|
use crate::bindings::{sigemptyset, sigfillset, sigset_t};
|
||||||
|
|
||||||
/// Returns the offset into 'availcols' at which 'cols' ought be output given
|
/// Returns the offset into `availcols` at which `cols` ought be output given
|
||||||
/// the requirements of 'align'.
|
/// 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].
|
/// or invalid [NcAlign].
|
||||||
|
///
|
||||||
|
/// *Method: Notcurses.[align()][Notcurses#method.align].*
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn notcurses_align(availcols: NcDimension, align: NcAlign, cols: NcDimension) -> NcOffset {
|
pub fn notcurses_align(availcols: NcDimension, align: NcAlign, cols: NcDimension) -> NcOffset {
|
||||||
if align == NCALIGN_LEFT {
|
if align == NCALIGN_LEFT {
|
||||||
@ -32,10 +34,12 @@ pub fn notcurses_align(availcols: NcDimension, align: NcAlign, cols: NcDimension
|
|||||||
-NCRESULT_MAX // NCALIGN_UNALIGNED
|
-NCRESULT_MAX // NCALIGN_UNALIGNED
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 'input' may be NULL if the caller is uninterested in event details.
|
///
|
||||||
/// If no event is ready, returns 0.
|
/// If no event is ready, returns 0.
|
||||||
///
|
///
|
||||||
/// *Method: Notcurses.[getc_nblock()][Notcurses#method.getc_nblock].*
|
/// *Method: Notcurses.[getc_nblock()][Notcurses#method.getc_nblock].*
|
||||||
|
//
|
||||||
|
// `input` may be NULL if the caller is uninterested in event details.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn notcurses_getc_nblock(nc: &mut Notcurses, input: &mut NcInput) -> char {
|
pub fn notcurses_getc_nblock(nc: &mut Notcurses, input: &mut NcInput) -> char {
|
||||||
unsafe {
|
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].*
|
/// *Method: Notcurses.[getc_stddim_yx()][Notcurses#method.stddim_yx].*
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn notcurses_stddim_yx<'a>(
|
pub fn notcurses_stddim_yx<'a>(
|
||||||
nc: &mut Notcurses,
|
nc: &'a mut Notcurses,
|
||||||
y: &mut NcDimension,
|
y: &mut NcDimension,
|
||||||
x: &mut NcDimension,
|
x: &mut NcDimension,
|
||||||
) -> &'a mut NcPlane {
|
) -> &'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].*
|
/// *Method: Notcurses.[getc_stddim_yx_const()][Notcurses#method.stddim_yx_const].*
|
||||||
#[inline]
|
#[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 {
|
unsafe {
|
||||||
let s = crate::notcurses_stdplane_const(nc);
|
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
|
&*s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user