rust: rename ffi:: namespace to nc::

+rustfmt
pull/931/head
joseLuís 4 years ago
parent 9dc847c8b5
commit 73961c04ce

@ -57,12 +57,11 @@
//use core::mem::transmute;
use crate as ffi;
use ffi::types::{
AlphaBits, Channel, ChannelPair, CellGcluster, Color, EGC, IntResult, PaletteIndex, StyleMask,
use crate as nc;
use nc::types::{
AlphaBits, CellGcluster, Channel, ChannelPair, Color, IntResult, PaletteIndex, StyleMask, EGC,
};
use ffi::{cell, ncplane};
use nc::{cell, ncplane};
/// cell_load(), plus blast the styling with 'style' and 'channels'.
///
@ -78,26 +77,24 @@ use ffi::{cell, ncplane};
// TODO: TEST!
#[allow(unused_unsafe)]
pub unsafe fn cell_prime(
plane: &mut ffi::ncplane,
cell: &mut ffi::cell,
plane: &mut nc::ncplane,
cell: &mut nc::cell,
gcluster: *const i8,
style: StyleMask,
channels: ChannelPair,
) -> IntResult {
cell.stylemask = style;
cell.channels = channels;
unsafe {
ffi::cell_load(plane, cell, gcluster)
nc::cell_load(plane, cell, gcluster)
//let mut egc_bytes: [u8; 4] = gcluster.to_ne_bytes(); // < TODO: WIP (u8...)
//let egc_bytes = transmute::<EGC, [i8; 4]>(gcluster);
//ffi::cell_load(plane, cell, &egc_bytes as *const i8)
//nc::cell_load(plane, cell, &egc_bytes as *const i8)
}
}
/// load up six cells with the EGCs necessary to draw a box.
///
/// returns 0 on success, -1 on error.
@ -124,7 +121,6 @@ pub unsafe fn cells_load_box(
vl: &mut cell,
gcluster: *const i8, // WIP EGC
) -> IntResult {
//let gcluster = transmute::<EGC, *const u8>(gcluster); // WIP EGC
let mut ulen: IntResult;
@ -132,43 +128,52 @@ pub unsafe fn cells_load_box(
ulen = unsafe { cell_prime(plane, ul, gclu, style, channels) };
if ulen > 0 { // 1
if ulen > 0 {
gclu = unsafe { gclu.offset(ulen as isize) };
ulen = unsafe { cell_prime(plane, ur, gclu, style, channels) };
if ulen > 0 { // 2
if ulen > 0 {
gclu = unsafe { gclu.offset(ulen as isize) };
ulen = unsafe { cell_prime(plane, ll, gclu, style, channels) };
if ulen > 0 { // 3
if ulen > 0 {
gclu = unsafe { gcluster.offset(ulen as isize) };
ulen = unsafe { cell_prime(plane, lr, gclu, style, channels) };
if ulen > 0 { // 4
if ulen > 0 {
gclu = unsafe { gcluster.offset(ulen as isize) };
ulen = unsafe { cell_prime(plane, hl, gclu, style, channels) };
if ulen > 0 { // 5
if ulen > 0 {
gclu = unsafe { gcluster.offset(ulen as isize) };
ulen = unsafe { cell_prime(plane, vl, gclu, style, channels) };
if ulen > 0 { // 6
if ulen > 0 {
return 0;
}
unsafe {ffi::cell_release(plane, hl);}
unsafe {
nc::cell_release(plane, hl);
}
}
unsafe {ffi::cell_release(plane, lr);}
unsafe {
nc::cell_release(plane, lr);
}
}
unsafe {
nc::cell_release(plane, ll);
}
unsafe {ffi::cell_release(plane, ll);}
}
unsafe {ffi::cell_release(plane, ur);}
unsafe {
nc::cell_release(plane, ur);
}
}
unsafe {
nc::cell_release(plane, ul);
}
unsafe {ffi::cell_release(plane, ul);}
}
-1
}
///
// TODO: TEST
#[inline]
@ -182,7 +187,7 @@ pub fn cell_init(cell: &mut cell) {
// TODO: TEST
#[inline]
pub fn cell_styles_set(cell: &mut cell, stylebits: StyleMask) {
cell.stylemask = stylebits & ffi::NCSTYLE_MASK as u16;
cell.stylemask = stylebits & nc::NCSTYLE_MASK as u16;
}
/// Extract the style bits from the cell.
@ -197,42 +202,42 @@ pub fn cell_styles(cell: &cell) -> StyleMask {
// TODO: TEST
#[inline]
pub fn cell_styles_on(cell: &mut cell, stylebits: StyleMask) {
cell.stylemask |= stylebits & ffi::NCSTYLE_MASK as u16;
cell.stylemask |= stylebits & nc::NCSTYLE_MASK as u16;
}
/// Remove the specified styles (in the LSBs) from the cell's existing spec.
// TODO: TEST
#[inline]
pub fn cell_styles_off(cell: &mut cell, stylebits: StyleMask) {
cell.stylemask &= !(stylebits & ffi::NCSTYLE_MASK as u16);
cell.stylemask &= !(stylebits & nc::NCSTYLE_MASK as u16);
}
/// Use the default color for the foreground.
// TODO: TEST
#[inline]
pub fn cell_set_fg_default(cell: &mut cell) {
ffi::channels_set_fg_default(&mut cell.channels);
nc::channels_set_fg_default(&mut cell.channels);
}
/// Use the default color for the background.
// TODO: TEST
#[inline]
pub fn cell_set_bg_default(cell: &mut cell) {
ffi::channels_set_bg_default(&mut cell.channels);
nc::channels_set_bg_default(&mut cell.channels);
}
/// Set the foreground alpha.
// TODO: TEST
#[inline]
pub fn cell_set_fg_alpha(cell: &mut cell, alpha: AlphaBits) {
ffi::channels_set_fg_alpha(&mut cell.channels, alpha);
nc::channels_set_fg_alpha(&mut cell.channels, alpha);
}
/// Set the background alpha.
// TODO: TEST
#[inline]
pub fn cell_set_bg_alpha(cell: &mut cell, alpha: AlphaBits) {
ffi::channels_set_bg_alpha(&mut cell.channels, alpha);
nc::channels_set_bg_alpha(&mut cell.channels, alpha);
}
/// Does the cell contain an East Asian Wide codepoint?
@ -240,7 +245,7 @@ pub fn cell_set_bg_alpha(cell: &mut cell, alpha: AlphaBits) {
// NOTE: remove casting when fixed: https://github.com/rust-lang/rust-bindgen/issues/1875
#[inline]
pub fn cell_double_wide_p(cell: &cell) -> bool {
(cell.channels & ffi::CELL_WIDEASIAN_MASK as u64) != 0
(cell.channels & nc::CELL_WIDEASIAN_MASK as u64) != 0
}
/// Is this the right half of a wide character?
@ -263,12 +268,13 @@ pub fn cell_wide_left_p(cell: &cell) -> bool {
#[inline]
pub fn cell_strdup(plane: &ncplane, cell: &cell) -> EGC {
core::char::from_u32(
unsafe {libc::strdup(ffi::cell_extended_gcluster(plane, cell)) } as i32 as u32)
.expect("wrong char")
unsafe { libc::strdup(nc::cell_extended_gcluster(plane, cell)) } as i32 as u32,
)
.expect("wrong char")
// unsafer option B (maybe faster, TODO: bench)
// unsafe {
// core::char::from_u32_unchecked(libc::strdup(ffi::cell_extended_gcluster(plane, cell)) as i32 as u32)
// core::char::from_u32_unchecked(libc::strdup(nc::cell_extended_gcluster(plane, cell)) as i32 as u32)
// }
}
@ -304,9 +310,9 @@ pub fn cellcmp(plane1: &ncplane, cell1: &cell, plane2: &ncplane, cell2: &cell) -
return true;
}
unsafe {
ffi::strcmp(
ffi::cell_extended_gcluster(plane1, cell1),
ffi::cell_extended_gcluster(plane2, cell2),
nc::strcmp(
nc::cell_extended_gcluster(plane1, cell1),
nc::cell_extended_gcluster(plane2, cell2),
) != 0
}
}
@ -316,9 +322,9 @@ pub fn cellcmp(plane1: &ncplane, cell1: &cell, plane2: &ncplane, cell2: &cell) -
#[inline]
pub fn cell_load_simple(plane: &mut ncplane, cell: &mut cell, ch: EGC) -> i32 {
unsafe {
ffi::cell_release(plane, cell);
nc::cell_release(plane, cell);
}
cell.channels &= !(ffi::CELL_WIDEASIAN_MASK as u64 | ffi::CELL_NOBACKGROUND_MASK);
cell.channels &= !(nc::CELL_WIDEASIAN_MASK as u64 | nc::CELL_NOBACKGROUND_MASK);
cell.gcluster = ch as CellGcluster;
1
}
@ -327,70 +333,70 @@ pub fn cell_load_simple(plane: &mut ncplane, cell: &mut cell, ch: EGC) -> i32 {
// TODO: TEST
#[inline]
pub fn cell_bchannel(cell: &cell) -> Channel {
ffi::channels_bchannel(cell.channels)
nc::channels_bchannel(cell.channels)
}
/// Extract the 32-bit foreground channel from a cell.
// TODO: TEST
#[inline]
pub fn cell_fchannel(cell: &cell) -> Channel {
ffi::channels_fchannel(cell.channels)
nc::channels_fchannel(cell.channels)
}
/// Set the 32-bit background channel of a cell.
// TODO: TEST
#[inline]
pub fn cell_set_bchannel(cell: &mut cell, channel: Channel) -> ChannelPair {
ffi::channels_set_bchannel(&mut cell.channels, channel)
nc::channels_set_bchannel(&mut cell.channels, channel)
}
/// Set the 32-bit foreground channel of a cell.
// TODO: TEST
#[inline]
pub fn cell_set_fchannel(cell: &mut cell, channel: Channel) -> ChannelPair {
ffi::channels_set_fchannel(&mut cell.channels, channel)
nc::channels_set_fchannel(&mut cell.channels, channel)
}
/// Extract 24 bits of foreground RGB from 'cell', shifted to LSBs.
// TODO: TEST
#[inline]
pub fn cell_fg(cell: &cell) -> Channel {
ffi::channels_fg(cell.channels)
nc::channels_fg(cell.channels)
}
/// Extract 24 bits of background RGB from 'cell', shifted to LSBs.
// TODO: TEST
#[inline]
pub fn cell_bg(cell: &cell) -> Channel {
ffi::channels_bg(cell.channels)
nc::channels_bg(cell.channels)
}
/// Extract 2 bits of foreground alpha from 'cell', shifted to LSBs.
// TODO: TEST
#[inline]
pub fn cell_fg_alpha(cell: &cell) -> AlphaBits {
ffi::channels_fg_alpha(cell.channels)
nc::channels_fg_alpha(cell.channels)
}
/// Extract 2 bits of background alpha from 'cell', shifted to LSBs.
// TODO: TEST
#[inline]
pub fn cell_bg_alpha(cell: &cell) -> AlphaBits {
ffi::channels_bg_alpha(cell.channels)
nc::channels_bg_alpha(cell.channels)
}
/// Extract 24 bits of foreground RGB from 'cell', split into components.
// TODO: TEST
#[inline]
pub fn cell_fg_rgb(cell: &cell, red: &mut Color, green: &mut Color, blue: &mut Color) -> Channel {
ffi::channels_fg_rgb(cell.channels, red, green, blue)
nc::channels_fg_rgb(cell.channels, red, green, blue)
}
/// Extract 24 bits of background RGB from 'cell', split into components.
// TODO: TEST
#[inline]
pub fn cell_bg_rgb(cell: &cell, red: &mut Color, green: &mut Color, blue: &mut Color) -> Channel {
ffi::channels_bg_rgb(cell.channels, red, green, blue)
nc::channels_bg_rgb(cell.channels, red, green, blue)
}
/// Set the r, g, and b cell for the foreground component of this 64-bit
@ -398,14 +404,14 @@ pub fn cell_bg_rgb(cell: &cell, red: &mut Color, green: &mut Color, blue: &mut C
// TODO: TEST
#[inline]
pub fn cell_set_fg_rgb(cell: &mut cell, red: Color, green: Color, blue: Color) {
ffi::channels_set_fg_rgb(&mut cell.channels, red, green, blue);
nc::channels_set_fg_rgb(&mut cell.channels, red, green, blue);
}
/// Same as `cell_set_fg_rgb()` but with an assembled 24-bit RGB value.
// TODO: TEST
#[inline]
pub fn cell_set_fg(cell: &mut cell, channel: Channel) {
ffi::channels_set_fg(&mut cell.channels, channel);
nc::channels_set_fg(&mut cell.channels, channel);
}
/// Set the cell's foreground palette index, set the foreground palette index
@ -415,9 +421,9 @@ pub fn cell_set_fg(cell: &mut cell, channel: Channel) {
// NOTE: this function now can't fail
#[inline]
pub fn cell_set_fg_palindex(cell: &mut cell, index: PaletteIndex) {
cell.channels |= ffi::CELL_FGDEFAULT_MASK;
cell.channels |= ffi::CELL_FG_PALETTE;
cell_set_fg_alpha(cell, ffi::CELL_ALPHA_OPAQUE);
cell.channels |= nc::CELL_FGDEFAULT_MASK;
cell.channels |= nc::CELL_FG_PALETTE;
cell_set_fg_alpha(cell, nc::CELL_ALPHA_OPAQUE);
cell.channels &= 0xff000000ffffffff_u64;
cell.channels |= (index as u64) << 32;
}
@ -434,7 +440,7 @@ pub fn cell_fg_palindex(cell: &cell) -> PaletteIndex {
// TODO: TEST
#[inline]
pub fn cell_set_bg_rgb(cell: &mut cell, red: Color, green: Color, blue: Color) {
ffi::channels_set_bg_rgb(&mut cell.channels, red, green, blue);
nc::channels_set_bg_rgb(&mut cell.channels, red, green, blue);
}
/// Same as `cell_set_fg_rgb()` but with an assembled 24-bit RGB value.
@ -442,7 +448,7 @@ pub fn cell_set_bg_rgb(cell: &mut cell, red: Color, green: Color, blue: Color) {
// TODO: TEST
#[inline]
pub fn cell_set_bg(cell: &mut cell, channel: Channel) {
ffi::channels_set_bg(&mut cell.channels, channel);
nc::channels_set_bg(&mut cell.channels, channel);
}
/// Set the cell's background palette index, set the background palette index
@ -452,9 +458,9 @@ pub fn cell_set_bg(cell: &mut cell, channel: Channel) {
// NOTE: this function now can't fail
#[inline]
pub fn cell_set_bg_palindex(cell: &mut cell, index: PaletteIndex) {
cell.channels |= ffi::CELL_BGDEFAULT_MASK as u64;
cell.channels |= ffi::CELL_BG_PALETTE as u64;
cell_set_bg_alpha(cell, ffi::CELL_ALPHA_OPAQUE);
cell.channels |= nc::CELL_BGDEFAULT_MASK as u64;
cell.channels |= nc::CELL_BG_PALETTE as u64;
cell_set_bg_alpha(cell, nc::CELL_ALPHA_OPAQUE);
cell.channels &= 0xffffffffff000000;
cell.channels |= index as u64;
}
@ -469,12 +475,12 @@ pub fn cell_bg_palindex(cell: &cell) -> PaletteIndex {
// TODO: TEST
#[inline]
pub fn cell_fg_default_p(cell: &cell) -> bool {
ffi::channels_fg_default_p(cell.channels)
nc::channels_fg_default_p(cell.channels)
}
// TODO: TEST
#[inline]
pub fn cell_fg_palindex_p(cell: &cell) -> bool {
ffi::channels_fg_palindex_p(cell.channels)
nc::channels_fg_palindex_p(cell.channels)
}
/// Is the background using the "default background color"? The "default
@ -483,18 +489,18 @@ pub fn cell_fg_palindex_p(cell: &cell) -> bool {
// TODO: TEST
#[inline]
pub fn cell_bg_default_p(cell: &cell) -> bool {
ffi::channels_bg_default_p(cell.channels)
nc::channels_bg_default_p(cell.channels)
}
// TODO: TEST
#[inline]
pub fn cell_bg_palindex_p(cell: &cell) -> bool {
ffi::channels_bg_palindex_p(cell.channels)
nc::channels_bg_palindex_p(cell.channels)
}
#[cfg(test)]
mod test {
// use super::ffi;
// use super::nc;
// use serial_test::serial;
/*
#[test]

@ -59,7 +59,7 @@
#![allow(dead_code)]
use crate as ffi;
use crate as nc;
use crate::types::{AlphaBits, Channel, ChannelPair, Color, Rgb};
@ -95,31 +95,31 @@ pub fn channel_rgb(channel: Channel, r: &mut Color, g: &mut Color, b: &mut Color
#[inline]
pub fn channel_set_rgb(channel: &mut Channel, r: Color, g: Color, b: Color) {
let rgb: Rgb = (r as Channel) << 16 | (g as Channel) << 8 | (b as Channel);
*channel = (*channel & !ffi::CELL_BG_RGB_MASK) | ffi::CELL_BGDEFAULT_MASK | rgb;
*channel = (*channel & !nc::CELL_BG_RGB_MASK) | nc::CELL_BGDEFAULT_MASK | rgb;
}
/// Same as channel_set_rgb(), but provide an assembled, packed 24 bits of rgb.
// TODO: TEST
#[inline]
pub fn channel_set(channel: &mut Channel, rgb: Rgb) {
*channel = (*channel & !ffi::CELL_BG_RGB_MASK) | ffi::CELL_BGDEFAULT_MASK | (rgb & 0x00ffffff);
*channel = (*channel & !nc::CELL_BG_RGB_MASK) | nc::CELL_BGDEFAULT_MASK | (rgb & 0x00ffffff);
}
/// Extract the 2-bit alpha component from a 32-bit channel.
#[inline]
pub fn channel_alpha(channel: Channel) -> AlphaBits {
channel & ffi::NCCHANNEL_ALPHA_MASK
channel & nc::NCCHANNEL_ALPHA_MASK
}
/// Set the 2-bit alpha component of the 32-bit channel.
#[inline]
pub fn channel_set_alpha(channel: &mut Channel, alpha: AlphaBits) {
let alpha_clean = alpha & ffi::NCCHANNEL_ALPHA_MASK;
*channel = alpha_clean | (*channel & !ffi::NCCHANNEL_ALPHA_MASK);
let alpha_clean = alpha & nc::NCCHANNEL_ALPHA_MASK;
*channel = alpha_clean | (*channel & !nc::NCCHANNEL_ALPHA_MASK);
if alpha != ffi::CELL_ALPHA_OPAQUE {
if alpha != nc::CELL_ALPHA_OPAQUE {
// indicate that we are *not* using the default background color
*channel |= ffi::CELL_BGDEFAULT_MASK;
*channel |= nc::CELL_BGDEFAULT_MASK;
}
}
@ -127,20 +127,20 @@ pub fn channel_set_alpha(channel: &mut Channel, alpha: AlphaBits) {
// TODO: TEST
#[inline]
pub fn channel_default_p(channel: Channel) -> bool {
(channel & ffi::CELL_BGDEFAULT_MASK) == 0
(channel & nc::CELL_BGDEFAULT_MASK) == 0
}
/// Is this channel using palette-indexed color rather than RGB?
// TODO: TEST
#[inline]
pub fn channel_palindex_p(channel: Channel) -> bool {
!channel_default_p(channel) && (channel & ffi::CELL_BG_PALETTE) == 0
!channel_default_p(channel) && (channel & nc::CELL_BG_PALETTE) == 0
}
/// Mark the channel as using its default color, which also marks it opaque.
#[inline]
pub fn channel_set_default(channel: &mut Channel) -> Channel {
*channel &= !(ffi::CELL_BGDEFAULT_MASK | ffi::CELL_ALPHA_HIGHCONTRAST); // < NOTE shouldn't be better NCCHANNEL_ALPHA_MASK?
*channel &= !(nc::CELL_BGDEFAULT_MASK | nc::CELL_ALPHA_HIGHCONTRAST); // < NOTE shouldn't be better NCCHANNEL_ALPHA_MASK?
*channel
}
@ -183,14 +183,14 @@ pub fn channels_combine(fchannel: Channel, bchannel: Channel) -> ChannelPair {
// TODO: TEST
#[inline]
pub fn channels_fg(channels: ChannelPair) -> Channel {
channels_fchannel(channels) & ffi::CELL_BG_RGB_MASK
channels_fchannel(channels) & nc::CELL_BG_RGB_MASK
}
/// Extract 24 bits of background RGB from 'channels', shifted to LSBs.
// TODO: TEST
#[inline]
pub fn channels_bg(channels: ChannelPair) -> Channel {
channels_bchannel(channels) & ffi::CELL_BG_RGB_MASK
channels_bchannel(channels) & nc::CELL_BG_RGB_MASK
}
/// Extract 2 bits of foreground alpha from 'channels', shifted to LSBs.
@ -283,9 +283,9 @@ pub fn channels_set_fg_alpha(channels: &mut ChannelPair, alpha: AlphaBits) {
#[inline]
pub fn channels_set_bg_alpha(channels: &mut ChannelPair, alpha: AlphaBits) {
let mut alpha_clean = alpha;
if alpha == ffi::CELL_ALPHA_HIGHCONTRAST {
if alpha == nc::CELL_ALPHA_HIGHCONTRAST {
// forbidden for background alpha, so makes it opaque
alpha_clean = ffi::CELL_ALPHA_OPAQUE;
alpha_clean = nc::CELL_ALPHA_OPAQUE;
}
let mut channel = channels_bchannel(*channels);
channel_set_alpha(&mut channel, alpha_clean);
@ -344,7 +344,7 @@ pub fn channels_set_bg_default(channels: &mut ChannelPair) -> ChannelPair {
#[cfg(test)]
mod test {
use super::{ffi, Channel, ChannelPair};
use super::{nc, Channel, ChannelPair};
use serial_test::serial;
#[test]
@ -389,25 +389,25 @@ mod test {
#[test]
#[serial]
fn channel_alpha() {
let c: Channel = 0x112233 | ffi::CELL_ALPHA_TRANSPARENT;
assert_eq!(super::channel_alpha(c), ffi::CELL_ALPHA_TRANSPARENT);
let c: Channel = 0x112233 | nc::CELL_ALPHA_TRANSPARENT;
assert_eq!(super::channel_alpha(c), nc::CELL_ALPHA_TRANSPARENT);
}
#[test]
#[serial]
fn channel_set_alpha() {
let mut c: Channel = 0x112233;
super::channel_set_alpha(&mut c, ffi::CELL_ALPHA_HIGHCONTRAST);
assert_eq!(ffi::CELL_ALPHA_HIGHCONTRAST, super::channel_alpha(c));
super::channel_set_alpha(&mut c, nc::CELL_ALPHA_HIGHCONTRAST);
assert_eq!(nc::CELL_ALPHA_HIGHCONTRAST, super::channel_alpha(c));
super::channel_set_alpha(&mut c, ffi::CELL_ALPHA_TRANSPARENT);
assert_eq!(ffi::CELL_ALPHA_TRANSPARENT, super::channel_alpha(c));
super::channel_set_alpha(&mut c, nc::CELL_ALPHA_TRANSPARENT);
assert_eq!(nc::CELL_ALPHA_TRANSPARENT, super::channel_alpha(c));
super::channel_set_alpha(&mut c, ffi::CELL_ALPHA_BLEND);
assert_eq!(ffi::CELL_ALPHA_BLEND, super::channel_alpha(c));
super::channel_set_alpha(&mut c, nc::CELL_ALPHA_BLEND);
assert_eq!(nc::CELL_ALPHA_BLEND, super::channel_alpha(c));
super::channel_set_alpha(&mut c, ffi::CELL_ALPHA_OPAQUE);
assert_eq!(ffi::CELL_ALPHA_OPAQUE, super::channel_alpha(c));
// TODO: CHECK for ffi::CELL_BGDEFAULT_MASK
super::channel_set_alpha(&mut c, nc::CELL_ALPHA_OPAQUE);
assert_eq!(nc::CELL_ALPHA_OPAQUE, super::channel_alpha(c));
// TODO: CHECK for nc::CELL_BGDEFAULT_MASK
}
#[test]
@ -415,7 +415,7 @@ mod test {
fn channel_set_default() {
const DEFAULT: Channel = 0x112233;
let mut c: Channel = DEFAULT | ffi::CELL_ALPHA_TRANSPARENT;
let mut c: Channel = DEFAULT | nc::CELL_ALPHA_TRANSPARENT;
assert!(c != DEFAULT);
super::channel_set_default(&mut c);
@ -429,10 +429,10 @@ mod test {
assert_eq!(true, super::channel_default_p(c));
// TODO FIXME: test for the false result
// let _ = super::channel_set_alpha(&mut c, ffi::CELL_ALPHA_TRANSPARENT);
// let _ = super::channel_set_alpha(&mut c, nc::CELL_ALPHA_TRANSPARENT);
// assert_eq!(false, super::channel_default_p(c));
let _ = super::channel_set_alpha(&mut c, ffi::CELL_ALPHA_OPAQUE);
let _ = super::channel_set_alpha(&mut c, nc::CELL_ALPHA_OPAQUE);
assert_eq!(true, super::channel_default_p(c));
}
#[test]

@ -37,11 +37,11 @@
// ncdirect_vline_interp
//
use crate as ffi;
use ffi::ncdirect;
use crate as nc;
use nc::ncdirect;
extern "C" {
fn libc_stdout() -> *mut ffi::_IO_FILE;
fn libc_stdout() -> *mut nc::_IO_FILE;
}
/// A simple ncdirect_init() wrapper
@ -53,13 +53,12 @@ extern "C" {
/// This can be used to add color and styling to text in the standard output paradigm.
/// Returns NULL on error, including any failure initializing terminfo.
pub unsafe fn ncdirect_start() -> *mut ncdirect {
ffi::ncdirect_init(core::ptr::null(), libc_stdout())
nc::ncdirect_init(core::ptr::null(), libc_stdout())
}
#[cfg(test)]
mod test {
// use super::ffi;
// use super::nc;
// use serial_test::serial;
/*
#[test]
@ -68,4 +67,3 @@ mod test {
}
*/
}

@ -9,7 +9,7 @@
//+nckey_mouse_p
//+nckey_supppuab_p
use crate as ffi;
use crate as nc;
/// Is this char32_t a Supplementary Private Use Area-B codepoint?
// TODO: TEST
@ -22,12 +22,12 @@ pub fn nckey_supppuab_p(w: u32) -> bool {
// TODO: TEST
#[inline]
pub fn nckey_mouse_p(r: u32) -> bool {
r >= ffi::NCKEY_BUTTON1 && r <= ffi::NCKEY_RELEASE
r >= nc::NCKEY_BUTTON1 && r <= nc::NCKEY_RELEASE
}
#[cfg(test)]
mod test {
// use super::ffi;
// use super::nc;
// use serial_test::serial;
/*
#[test]

@ -4,6 +4,7 @@
#![no_std]
#![allow(clippy::too_many_arguments)]
// Include the bindgen bindings
// see https://github.com/rust-lang/rust-bindgen/issues/1470
#[allow(clippy::all)]
mod bindings {
@ -35,21 +36,22 @@ pub use pixel::*;
pub use plane::*;
pub use types::*;
// TODO: move tests out
#[cfg(test)]
mod tests {
use core::ptr::{null, null_mut};
use cstr_core::{CStr, CString};
use libc_print::*;
use serial_test::serial; // serialize tests w/ ffi::notcurses_init()
use serial_test::serial; // serialize tests w/ nc::notcurses_init()
use crate as ffi;
use crate as nc;
#[test]
#[serial]
fn get_notcurses_version() {
let c_str = unsafe {
let s = ffi::notcurses_version();
let s = nc::notcurses_version();
assert!(!s.is_null());
CStr::from_ptr(s)
};
@ -62,7 +64,7 @@ mod tests {
fn create_notcurses_context() {
unsafe {
let _ = libc::setlocale(libc::LC_ALL, CString::new("").unwrap().as_ptr());
let opts = ffi::notcurses_options {
let opts = nc::notcurses_options {
loglevel: 0,
termtype: null(),
renderfp: null_mut(),
@ -70,10 +72,10 @@ mod tests {
margin_r: 0,
margin_b: 0,
margin_l: 0,
flags: (ffi::NCOPTION_NO_ALTERNATE_SCREEN | ffi::NCOPTION_INHIBIT_SETLOCALE) as u64,
flags: (nc::NCOPTION_NO_ALTERNATE_SCREEN | nc::NCOPTION_INHIBIT_SETLOCALE) as u64,
};
let nc = ffi::notcurses_init(&opts, null_mut());
ffi::notcurses_stop(nc);
let nc = nc::notcurses_init(&opts, null_mut());
nc::notcurses_stop(nc);
}
}
@ -82,8 +84,8 @@ mod tests {
fn create_direct_context() {
unsafe {
let _ = libc::setlocale(libc::LC_ALL, CString::new("").unwrap().as_ptr());
let nc = ffi::ncdirect_init(null_mut(), null_mut());
ffi::ncdirect_stop(nc);
let nc = nc::ncdirect_init(null_mut(), null_mut());
nc::ncdirect_stop(nc);
}
}
}

@ -1,4 +1,3 @@
// #define CELL_INITIALIZER(c, s, chan) { .gcluster = (c), .gcluster_backstop = 0, .reserved = 0, .stylemask = (s), .channels = (chan), }
#[macro_export]
macro_rules! cell_initializer {
@ -21,7 +20,6 @@ macro_rules! cell_simple_initializer {
};
}
// #define CELL_TRIVIAL_INITIALIZER { }
#[macro_export]
macro_rules! cell_trivial_initializer {

@ -48,22 +48,22 @@
use core::ptr::null;
use crate as ffi;
use ffi::{ncinput, ncplane, notcurses};
use crate as nc;
use nc::{ncinput, ncplane, notcurses};
/// 'input' may be NULL if the caller is uninterested in event details.
/// If no event is ready, returns 0.
// TODO: TEST
#[inline]
pub fn notcurses_getc_nblock(nc: &mut notcurses, input: &mut ncinput) -> ffi::char32_t {
pub fn notcurses_getc_nblock(nc: &mut notcurses, input: &mut ncinput) -> nc::char32_t {
unsafe {
let mut sigmask = ffi::sigset_t { __val: [0; 16] };
ffi::sigfillset(&mut sigmask);
let ts = ffi::timespec {
let mut sigmask = nc::sigset_t { __val: [0; 16] };
nc::sigfillset(&mut sigmask);
let ts = nc::timespec {
tv_sec: 0,
tv_nsec: 0,
};
ffi::notcurses_getc(nc, &ts, &mut sigmask, input)
nc::notcurses_getc(nc, &ts, &mut sigmask, input)
}
}
@ -71,11 +71,11 @@ pub fn notcurses_getc_nblock(nc: &mut notcurses, input: &mut ncinput) -> ffi::ch
/// Blocks until an event is processed or a signal is received.
// TODO: TEST
#[inline]
pub fn notcurses_getc_nblocking(nc: &mut notcurses, input: &mut ncinput) -> ffi::char32_t {
pub fn notcurses_getc_nblocking(nc: &mut notcurses, input: &mut ncinput) -> nc::char32_t {
unsafe {
let mut sigmask = ffi::sigset_t { __val: [0; 16] };
ffi::sigemptyset(&mut sigmask);
ffi::notcurses_getc(nc, null(), &mut sigmask, input)
let mut sigmask = nc::sigset_t { __val: [0; 16] };
nc::sigemptyset(&mut sigmask);
nc::notcurses_getc(nc, null(), &mut sigmask, input)
}
}
@ -84,8 +84,8 @@ pub fn notcurses_getc_nblocking(nc: &mut notcurses, input: &mut ncinput) -> ffi:
#[inline]
pub fn notcurses_stddim_yx(nc: &mut notcurses, y: &mut i32, x: &mut i32) -> ncplane {
unsafe {
let s = ffi::notcurses_stdplane(nc);
ffi::ncplane_dim_yx(s, y, x);
let s = nc::notcurses_stdplane(nc);
nc::ncplane_dim_yx(s, y, x);
*s
}
}
@ -95,13 +95,13 @@ pub fn notcurses_stddim_yx(nc: &mut notcurses, y: &mut i32, x: &mut i32) -> ncpl
#[inline]
pub fn notcurses_term_dim_yx(nc: &notcurses, rows: &mut i32, cols: &mut i32) {
unsafe {
ffi::ncplane_dim_yx(ffi::notcurses_stdplane_const(nc), rows, cols);
nc::ncplane_dim_yx(nc::notcurses_stdplane_const(nc), rows, cols);
}
}
#[cfg(test)]
mod test {
// use super::ffi;
// use super::nc;
// use serial_test::serial;
/*
#[test]

@ -17,46 +17,46 @@
//+palette256_set
//+palette256_set_rgb
use crate as ffi;
use crate as nc;
use crate::types::Color;
use ffi::{Channel, PaletteIndex, Rgb};
use nc::{Channel, PaletteIndex, Rgb};
/// Set the different color components of an entry inside a palette store.
// TODO: TEST
#[inline]
pub fn palette256_set_rgb(
palette: &mut ffi::palette256,
palette: &mut nc::palette256,
idx: PaletteIndex,
red: Color,
green: Color,
blue: Color,
) {
ffi::channel_set_rgb(&mut palette.chans[idx as usize], red, green, blue)
nc::channel_set_rgb(&mut palette.chans[idx as usize], red, green, blue)
}
/// Same as `palette256_set_rgb()` but set an assembled 24 bit channel at once.
// TODO: TEST
#[inline]
pub fn palette256_set(palette: &mut ffi::palette256, idx: PaletteIndex, rgb: Rgb) {
ffi::channel_set(&mut palette.chans[idx as usize], rgb);
pub fn palette256_set(palette: &mut nc::palette256, idx: PaletteIndex, rgb: Rgb) {
nc::channel_set(&mut palette.chans[idx as usize], rgb);
}
/// Extract the three 8-bit R/G/B components from an entry inside a palette store.
// TODO: TEST
#[inline]
pub fn palette256_get_rgb(
palette: &ffi::palette256,
palette: &nc::palette256,
idx: PaletteIndex,
red: &mut Color,
green: &mut Color,
blue: &mut Color,
) -> Channel {
ffi::channel_rgb(palette.chans[idx as usize], red, green, blue)
nc::channel_rgb(palette.chans[idx as usize], red, green, blue)
}
#[cfg(test)]
mod test {
// use super::ffi;
// use super::nc;
// use serial_test::serial;
/*
#[test]

@ -27,7 +27,8 @@
//+ncpixel_set_r
//+ncpixel_set_rgb
use crate::types::{Color, Pixel};
use crate as nc;
use nc::{Color, Pixel};
// Pixel Structure:
//
@ -90,7 +91,7 @@ pub fn ncpixel_set_rgb(pixel: &mut Pixel, red: Color, green: Color, blue: Color)
#[cfg(test)]
mod test {
// use super::ffi;
// use super::nc;
// use serial_test::serial;
/*
#[test]

@ -141,9 +141,9 @@ use core::ptr::null_mut;
use cstr_core::CString;
use crate as ffi;
use ffi::types::{AlphaBits, Channel, ChannelPair, Color, EGC, EGCBackstop, IntResult, StyleMask};
use ffi::{cell, ncalign_e, ncplane};
use crate as nc;
use nc::types::{AlphaBits, Channel, ChannelPair, Color, EGCBackstop, IntResult, StyleMask, EGC};
use nc::{cell, ncalign_e, ncplane};
/// Return the column at which 'cols' columns ought start in order to be aligned
/// according to 'align' within ncplane 'n'. Returns INT_MAX on invalid 'align'.
@ -153,7 +153,7 @@ use ffi::{cell, ncalign_e, ncplane};
// TODO: TEST
#[inline]
pub fn ncplane_align(plane: &ncplane, align: ncalign_e, cols: i32) -> i32 {
if align == ffi::ncalign_e_NCALIGN_LEFT {
if align == nc::ncalign_e_NCALIGN_LEFT {
return 0;
}
@ -162,9 +162,9 @@ pub fn ncplane_align(plane: &ncplane, align: ncalign_e, cols: i32) -> i32 {
return 0;
}
if align == ffi::ncalign_e_NCALIGN_CENTER {
if align == nc::ncalign_e_NCALIGN_CENTER {
return plane_cols - cols / 2;
} else if align == ffi::ncalign_e_NCALIGN_RIGHT {
} else if align == nc::ncalign_e_NCALIGN_RIGHT {
return plane_cols - cols;
}
core::i32::MAX
@ -175,14 +175,14 @@ pub fn ncplane_align(plane: &ncplane, align: ncalign_e, cols: i32) -> i32 {
// TODO: TEST
#[inline]
pub fn nplane_at_cursor_cell(plane: &mut ncplane, cell: &mut cell) -> IntResult {
let mut egc = unsafe { ffi::ncplane_at_cursor(plane, &mut cell.stylemask, &mut cell.channels) };
let mut egc = unsafe { nc::ncplane_at_cursor(plane, &mut cell.stylemask, &mut cell.channels) };
if egc.is_null() {
return -1;
}
let result: IntResult = unsafe { ffi::cell_load(plane, cell, egc) };
let result: IntResult = unsafe { nc::cell_load(plane, cell, egc) };
if result < 0 {
unsafe {
ffi::free(&mut egc as *mut _ as *mut c_void);
nc::free(&mut egc as *mut _ as *mut c_void);
}
}
result
@ -194,15 +194,15 @@ pub fn nplane_at_cursor_cell(plane: &mut ncplane, cell: &mut cell) -> IntResult
#[inline]
pub fn ncplane_at_yx_cell(plane: &mut ncplane, y: i32, x: i32, cell: &mut cell) -> IntResult {
let mut egc =
unsafe { ffi::ncplane_at_yx(plane, y, x, &mut cell.stylemask, &mut cell.channels) };
unsafe { nc::ncplane_at_yx(plane, y, x, &mut cell.stylemask, &mut cell.channels) };
if egc.is_null() {
return -1;
}
let channels = cell.channels; // need to preserve wide flag
let result: IntResult = unsafe { ffi::cell_load(plane, cell, egc) };
let result: IntResult = unsafe { nc::cell_load(plane, cell, egc) };
cell.channels = channels;
unsafe {
ffi::free(&mut egc as *mut _ as *mut c_void);
nc::free(&mut egc as *mut _ as *mut c_void);
}
result
}
@ -226,8 +226,8 @@ pub fn ncplane_box_sized(
) -> IntResult {
let (mut y, mut x) = (0, 0);
unsafe {
ffi::ncplane_cursor_yx(plane, &mut y, &mut x);
ffi::ncplane_box(
nc::ncplane_cursor_yx(plane, &mut y, &mut x);
nc::ncplane_box(
plane,
ul,
ur,
@ -248,7 +248,7 @@ pub fn ncplane_box_sized(
pub fn ncplane_dim_x(plane: &ncplane) -> i32 {
unsafe {
let mut x = 0;
ffi::ncplane_dim_yx(plane, null_mut(), &mut x);
nc::ncplane_dim_yx(plane, null_mut(), &mut x);
x
}
}
@ -259,7 +259,7 @@ pub fn ncplane_dim_x(plane: &ncplane) -> i32 {
pub fn ncplane_dim_y(plane: &ncplane) -> i32 {
unsafe {
let mut y = 0;
ffi::ncplane_dim_yx(plane, &mut y, null_mut());
nc::ncplane_dim_yx(plane, &mut y, null_mut());
y
}
}
@ -285,7 +285,7 @@ pub fn ncplane_double_box(
let mut vl = cell_trivial_initializer![];
unsafe {
ret = ffi::cells_double_box(
ret = nc::cells_double_box(
plane,
stylemask as u32,
channels,
@ -297,15 +297,15 @@ pub fn ncplane_double_box(
&mut vl,
);
if ret == 0 {
ret = ffi::ncplane_box(plane, &ul, &ur, &ll, &lr, &hl, &vl, ystop, xstop, ctlword);
ret = nc::ncplane_box(plane, &ul, &ur, &ll, &lr, &hl, &vl, ystop, xstop, ctlword);
}
ffi::cell_release(plane, &mut ul);
ffi::cell_release(plane, &mut ur);
ffi::cell_release(plane, &mut ll);
ffi::cell_release(plane, &mut lr);
ffi::cell_release(plane, &mut hl);
ffi::cell_release(plane, &mut vl);
nc::cell_release(plane, &mut ul);
nc::cell_release(plane, &mut ur);
nc::cell_release(plane, &mut ll);
nc::cell_release(plane, &mut lr);
nc::cell_release(plane, &mut hl);
nc::cell_release(plane, &mut vl);
}
ret
}
@ -322,7 +322,7 @@ pub fn ncplane_double_box_sized(
) -> IntResult {
let (mut y, mut x) = (0, 0);
unsafe {
ffi::ncplane_cursor_yx(plane, &mut y, &mut x);
nc::ncplane_cursor_yx(plane, &mut y, &mut x);
}
ncplane_double_box(
plane,
@ -338,7 +338,7 @@ pub fn ncplane_double_box_sized(
// TODO: TEST
#[inline]
pub fn ncplane_hline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 {
unsafe { ffi::ncplane_hline_interp(plane, cell, len, cell.channels, cell.channels) }
unsafe { nc::ncplane_hline_interp(plane, cell, len, cell.channels, cell.channels) }
}
///
@ -355,9 +355,9 @@ pub fn ncplane_perimeter(
ctlword: u32,
) -> IntResult {
unsafe {
ffi::ncplane_cursor_move_yx(plane, 0, 0);
nc::ncplane_cursor_move_yx(plane, 0, 0);
let (mut dimy, mut dimx) = (0, 0);
ffi::ncplane_dim_yx(plane, &mut dimy, &mut dimx);
nc::ncplane_dim_yx(plane, &mut dimy, &mut dimx);
ncplane_box_sized(plane, ul, ur, ll, lr, hline, vline, dimy, dimx, ctlword)
}
}
@ -370,12 +370,12 @@ pub fn ncplane_perimeter_double(
channels: ChannelPair,
ctlword: u32,
) -> IntResult {
if unsafe { ffi::ncplane_cursor_move_yx(plane, 0, 0) } != 0 {
if unsafe { nc::ncplane_cursor_move_yx(plane, 0, 0) } != 0 {
return -1;
}
let (mut dimy, mut dimx) = (0, 0);
unsafe {
ffi::ncplane_dim_yx(plane, &mut dimy, &mut dimx);
nc::ncplane_dim_yx(plane, &mut dimy, &mut dimx);
}
let mut ul = cell_trivial_initializer![];
let mut ur = cell_trivial_initializer![];
@ -384,7 +384,7 @@ pub fn ncplane_perimeter_double(
let mut hl = cell_trivial_initializer![];
let mut vl = cell_trivial_initializer![];
if unsafe {
ffi::cells_double_box(
nc::cells_double_box(
plane,
stylemask as u32,
channels,
@ -401,12 +401,12 @@ pub fn ncplane_perimeter_double(
}
let ret = ncplane_box_sized(plane, &ul, &ur, &ll, &lr, &hl, &vl, dimy, dimx, ctlword);
unsafe {
ffi::cell_release(plane, &mut ul);
ffi::cell_release(plane, &mut ur);
ffi::cell_release(plane, &mut ll);
ffi::cell_release(plane, &mut lr);
ffi::cell_release(plane, &mut hl);
ffi::cell_release(plane, &mut vl);
nc::cell_release(plane, &mut ul);
nc::cell_release(plane, &mut ur);
nc::cell_release(plane, &mut ll);
nc::cell_release(plane, &mut lr);
nc::cell_release(plane, &mut hl);
nc::cell_release(plane, &mut vl);
}
ret
}
@ -419,12 +419,12 @@ pub fn ncplane_perimeter_rounded(
channels: ChannelPair,
ctlword: u32,
) -> IntResult {
if unsafe { ffi::ncplane_cursor_move_yx(plane, 0, 0) } != 0 {
if unsafe { nc::ncplane_cursor_move_yx(plane, 0, 0) } != 0 {
return -1;
}
let (mut dimy, mut dimx) = (0, 0);
unsafe {
ffi::ncplane_dim_yx(plane, &mut dimy, &mut dimx);
nc::ncplane_dim_yx(plane, &mut dimy, &mut dimx);
}
let mut ul = cell_trivial_initializer![];
let mut ur = cell_trivial_initializer![];
@ -433,7 +433,7 @@ pub fn ncplane_perimeter_rounded(
let mut hl = cell_trivial_initializer![];
let mut vl = cell_trivial_initializer![];
if unsafe {
ffi::cells_rounded_box(
nc::cells_rounded_box(
plane,
stylemask as u32,
channels,
@ -450,12 +450,12 @@ pub fn ncplane_perimeter_rounded(
}
let ret = ncplane_box_sized(plane, &ul, &ur, &ll, &lr, &hl, &vl, dimy, dimx, ctlword);
unsafe {
ffi::cell_release(plane, &mut ul);
ffi::cell_release(plane, &mut ur);
ffi::cell_release(plane, &mut ll);
ffi::cell_release(plane, &mut lr);
ffi::cell_release(plane, &mut hl);
ffi::cell_release(plane, &mut vl);
nc::cell_release(plane, &mut ul);
nc::cell_release(plane, &mut ur);
nc::cell_release(plane, &mut ll);
nc::cell_release(plane, &mut lr);
nc::cell_release(plane, &mut hl);
nc::cell_release(plane, &mut vl);
}
ret
}
@ -464,21 +464,21 @@ pub fn ncplane_perimeter_rounded(
// TODO: TEST
#[inline]
pub fn ncplane_putc(plane: &mut ncplane, cell: &cell) -> IntResult {
unsafe { ffi::ncplane_putc_yx(plane, -1, -1, cell) }
unsafe { nc::ncplane_putc_yx(plane, -1, -1, cell) }
}
/// Call ncplane_putsimple_yx() at the current cursor location.
// TODO: TEST
#[inline]
pub fn ncplane_putsimple(plane: &mut ncplane, ch: EGC) -> IntResult {
ffi::ncplane_putsimple_yx(plane, -1, -1, ch)
nc::ncplane_putsimple_yx(plane, -1, -1, ch)
}
/// Call ncplane_putegc() at the current cursor location.
// TODO: TEST
#[inline]
pub fn ncplane_putegc(plane: &mut ncplane, gcluster: i8, sbytes: &mut i32) -> IntResult {
unsafe { ffi::ncplane_putegc_yx(plane, -1, -1, &gcluster, sbytes) }
unsafe { nc::ncplane_putegc_yx(plane, -1, -1, &gcluster, sbytes) }
}
/// Replace the EGC underneath us, but retain the styling. The current styling
@ -490,10 +490,10 @@ pub fn ncplane_putegc(plane: &mut ncplane, gcluster: i8, sbytes: &mut i32) -> In
// TODO: TEST
#[inline]
pub fn ncplane_putsimple_yx(plane: &mut ncplane, y: i32, x: i32, ch: EGC) -> IntResult {
let newcell = cell_initializer![ch, unsafe { ffi::ncplane_attr(plane) }, unsafe {
ffi::ncplane_channels(plane)
let newcell = cell_initializer![ch, unsafe { nc::ncplane_attr(plane) }, unsafe {
nc::ncplane_channels(plane)
}];
unsafe { ffi::ncplane_putc_yx(plane, y, x, &newcell) }
unsafe { nc::ncplane_putc_yx(plane, y, x, &newcell) }
}
///
@ -501,7 +501,7 @@ pub fn ncplane_putsimple_yx(plane: &mut ncplane, y: i32, x: i32, ch: EGC) -> Int
#[inline]
pub fn ncplane_putstr(plane: &mut ncplane, gclustarr: &[u8]) -> IntResult {
unsafe {
ffi::ncplane_putstr_yx(
nc::ncplane_putstr_yx(
plane,
-1,
-1,
@ -513,9 +513,9 @@ pub fn ncplane_putstr(plane: &mut ncplane, gclustarr: &[u8]) -> IntResult {
///
// TODO: TEST
#[inline]
pub fn ncplane_putnstr(plane: &mut ncplane, size: ffi::size_t, gclustarr: &[u8]) -> IntResult {
pub fn ncplane_putnstr(plane: &mut ncplane, size: nc::size_t, gclustarr: &[u8]) -> IntResult {
unsafe {
ffi::ncplane_putnstr_yx(
nc::ncplane_putnstr_yx(
plane,
-1,
-1,
@ -532,7 +532,7 @@ pub fn ncplane_putnstr(plane: &mut ncplane, size: ffi::size_t, gclustarr: &[u8])
pub fn ncplane_resize_simple(plane: &mut ncplane, ylen: i32, xlen: i32) -> IntResult {
let (mut oldy, mut oldx) = (0, 0);
unsafe {
ffi::ncplane_dim_yx(plane, &mut oldy, &mut oldx);
nc::ncplane_dim_yx(plane, &mut oldy, &mut oldx);
}
let keepleny = {
if oldy > ylen {
@ -548,7 +548,7 @@ pub fn ncplane_resize_simple(plane: &mut ncplane, ylen: i32, xlen: i32) -> IntRe
oldx
}
};
unsafe { ffi::ncplane_resize(plane, 0, 0, keepleny, keeplenx, 0, 0, ylen, xlen) }
unsafe { nc::ncplane_resize(plane, 0, 0, keepleny, keeplenx, 0, 0, ylen, xlen) }
}
///
@ -556,18 +556,14 @@ pub fn ncplane_resize_simple(plane: &mut ncplane, ylen: i32, xlen: i32) -> IntRe
// TODO: TEST
#[inline]
pub fn ncplane_vline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 {
unsafe { ffi::ncplane_vline_interp(plane, cell, len, cell.channels, cell.channels) }
unsafe { nc::ncplane_vline_interp(plane, cell, len, cell.channels, cell.channels) }
}
// TODO: TEST
#[inline]
pub fn ncplane_vprintf(
plane: &mut ncplane,
format: &str,
ap: &mut ffi::__va_list_tag,
) -> IntResult {
pub fn ncplane_vprintf(plane: &mut ncplane, format: &str, ap: &mut nc::__va_list_tag) -> IntResult {
unsafe {
ffi::ncplane_vprintf_yx(
nc::ncplane_vprintf_yx(
plane,
-1,
-1,
@ -599,8 +595,8 @@ pub fn ncplane_gradient_sized(
}
let (mut y, mut x) = (0, 0);
unsafe {
ffi::ncplane_cursor_yx(plane, &mut y, &mut x);
ffi::ncplane_gradient(
nc::ncplane_cursor_yx(plane, &mut y, &mut x);
nc::ncplane_gradient(
plane,
CString::new(egc).expect("Bad EGC").as_ptr(),
stylemask as u32,
@ -618,56 +614,56 @@ pub fn ncplane_gradient_sized(
// TODO: TEST
#[inline]
pub fn ncplane_fchannel(plane: &ncplane) -> Channel {
ffi::channels_fchannel(unsafe { ffi::ncplane_channels(plane) })
nc::channels_fchannel(unsafe { nc::ncplane_channels(plane) })
}
/// Extract the 32-bit working background channel from an ncplane.
// TODO: TEST
#[inline]
pub fn ncplane_bchannel(plane: &ncplane) -> Channel {
ffi::channels_bchannel(unsafe { ffi::ncplane_channels(plane) })
nc::channels_bchannel(unsafe { nc::ncplane_channels(plane) })
}
/// Extract 24 bits of working foreground RGB from an ncplane, shifted to LSBs.
// TODO: TEST
#[inline]
pub fn ncplane_fg(plane: &ncplane) -> Channel {
ffi::channels_fg(unsafe { ffi::ncplane_channels(plane) })
nc::channels_fg(unsafe { nc::ncplane_channels(plane) })
}
/// Extract 24 bits of working background RGB from an ncplane, shifted to LSBs.
// TODO: TEST
#[inline]
pub fn ncplane_bg(plane: &ncplane) -> Channel {
ffi::channels_bg(unsafe { ffi::ncplane_channels(plane) })
nc::channels_bg(unsafe { nc::ncplane_channels(plane) })
}
/// Extract 2 bits of foreground alpha from 'struct ncplane', shifted to LSBs.
// TODO: TEST
#[inline]
pub fn ncplane_fg_alpha(plane: &ncplane) -> AlphaBits {
ffi::channels_fg_alpha(unsafe { ffi::ncplane_channels(plane) })
nc::channels_fg_alpha(unsafe { nc::ncplane_channels(plane) })
}
/// Extract 2 bits of background alpha from 'struct ncplane', shifted to LSBs.
// TODO: TEST
#[inline]
pub fn ncplane_bg_alpha(plane: &ncplane) -> AlphaBits {
ffi::channels_bg_alpha(unsafe { ffi::ncplane_channels(plane) })
nc::channels_bg_alpha(unsafe { nc::ncplane_channels(plane) })
}
/// Is the plane's foreground using the "default foreground color"?
// TODO: TEST
#[inline]
pub fn ncplane_fg_default_p(plane: &ncplane) -> bool {
ffi::channels_fg_default_p(unsafe { ffi::ncplane_channels(plane) })
nc::channels_fg_default_p(unsafe { nc::ncplane_channels(plane) })
}
/// Is the plane's background using the "default background color"?
// TODO: TEST
#[inline]
pub fn ncplane_bg_default_p(plane: &ncplane) -> bool {
ffi::channels_bg_default_p(unsafe { ffi::ncplane_channels(plane) })
nc::channels_bg_default_p(unsafe { nc::ncplane_channels(plane) })
}
/// Extract 24 bits of foreground RGB from a plane, split into components.
@ -679,7 +675,7 @@ pub fn ncplane_fg_rgb(
green: &mut Color,
blue: &mut Color,
) -> Channel {
ffi::channels_fg_rgb(unsafe { ffi::ncplane_channels(plane) }, red, green, blue)
nc::channels_fg_rgb(unsafe { nc::ncplane_channels(plane) }, red, green, blue)
}
/// Extract 24 bits of background RGB from a plane, split into components.
@ -691,7 +687,7 @@ pub fn ncplane_bg_rgb(
green: &mut Color,
blue: &mut Color,
) -> Channel {
ffi::channels_bg_rgb(unsafe { ffi::ncplane_channels(plane) }, red, green, blue)
nc::channels_bg_rgb(unsafe { nc::ncplane_channels(plane) }, red, green, blue)
}
// TODO: TEST
@ -715,7 +711,7 @@ pub fn ncplane_rounded_box(
let mut vl = cell_trivial_initializer![];
unsafe {
ret = ffi::cells_rounded_box(
ret = nc::cells_rounded_box(
plane,
stylemask as u32,
channels,
@ -727,15 +723,15 @@ pub fn ncplane_rounded_box(
&mut vl,
);
if ret == 0 {
ret = ffi::ncplane_box(plane, &ul, &ur, &ll, &lr, &hl, &vl, ystop, xstop, ctlword);
ret = nc::ncplane_box(plane, &ul, &ur, &ll, &lr, &hl, &vl, ystop, xstop, ctlword);
}
ffi::cell_release(plane, &mut ul);
ffi::cell_release(plane, &mut ur);
ffi::cell_release(plane, &mut ll);
ffi::cell_release(plane, &mut lr);
ffi::cell_release(plane, &mut hl);
ffi::cell_release(plane, &mut vl);
nc::cell_release(plane, &mut ul);
nc::cell_release(plane, &mut ur);
nc::cell_release(plane, &mut ll);
nc::cell_release(plane, &mut lr);
nc::cell_release(plane, &mut hl);
nc::cell_release(plane, &mut vl);
}
ret
}
@ -752,7 +748,7 @@ pub fn ncplane_rounded_box_sized(
) -> IntResult {
let (mut y, mut x) = (0, 0);
unsafe {
ffi::ncplane_cursor_yx(plane, &mut y, &mut x);
nc::ncplane_cursor_yx(plane, &mut y, &mut x);
}
ncplane_rounded_box(
plane,
@ -819,7 +815,7 @@ pub fn ncplane_rounded_box_sized(
#[cfg(test)]
mod test {
// use super::ffi;
// use super::nc;
// use serial_test::serial;
/*
#[test]

Loading…
Cancel
Save