- fix bugs in macros: error, error_ref & error_ref_mut
- remove issue-1509 example
- minor improvements
- rustfmt
pull/1521/head
joseLuís 3 years ago
parent fada4148b5
commit 48ab7e0945

@ -1,31 +0,0 @@
//! https://github.com/dankamongmen/notcurses/issues/1509
//! strange color behaviour when moving planes
//
// TODO
// -
//
use std::collections::BTreeMap;
use libnotcurses_sys::*;
fn main() -> NcResult<()> {
let mut nc = FullMode::new()?;
// get the stdplane and color it green
let green = nc.stdplane();
let mut channels = NcChannelPair::with_rgb8(0xFF, 0, 0, 0, 0x88, 0);
green.set_base("-", 0, channels)?;
// create one 1x1 blue plane at 1,1
let blue = NcPlane::new_bound(green, 1, 1, 1, 1)?;
blue.set_base("B", 0, channels.set_bg_rgb8(0, 0, 0x88))?;
rsleep![&mut nc, 1];
// move it to 4,4
// BUG: here it shows something is wrong
blue.move_yx(4, 4)?;
rsleep![&mut nc, 1];
Ok(())
}

@ -3,7 +3,7 @@
use libc::strcmp;
use crate::{
nccell_release, cstring, NcAlphaBits, NcCell, NcChannel, NcChannelPair, NcColor, NcEgc,
cstring, nccell_release, NcAlphaBits, NcCell, NcChannel, NcChannelPair, NcColor, NcEgc,
NcIntResult, NcPaletteIndex, NcPlane, NcRgb, NcStyleMask, NCCELL_ALPHA_OPAQUE,
NCCELL_BGDEFAULT_MASK, NCCELL_BG_PALETTE, NCCELL_FGDEFAULT_MASK, NCCELL_FG_PALETTE,
NCRESULT_ERR, NCRESULT_OK, NCSTYLE_MASK,

@ -120,13 +120,14 @@ macro_rules! printf {
/// type `()`, and an empty `&str` `""`, respectively.
#[macro_export]
macro_rules! error {
($res:expr, $msg:expr, $ok:expr) => {
if $res >= crate::NCRESULT_OK {
($res:expr, $msg:expr, $ok:expr) => {{
let res = $res;
if res >= crate::NCRESULT_OK {
return Ok($ok);
} else {
return Err(crate::NcError::with_msg($res, $msg));
return Err(crate::NcError::with_msg(res, $msg));
}
};
}};
($res:expr, $msg:expr) => {
error![$res, $msg, ()];
};
@ -145,20 +146,23 @@ macro_rules! error {
/// `$msg` is optional. By default it will be an empty `&str` `""`.
#[macro_export]
macro_rules! error_ref {
($ptr:expr, $msg:expr, $ok:expr) => {
if $ptr != core::ptr::null() {
($ptr:expr, $msg:expr, $ok:expr) => {{
let ptr = $ptr; // avoid calling a function multiple times
if ptr.is_null() {
return Err(crate::NcError::with_msg(crate::NCRESULT_ERR, $msg));
} else {
#[allow(unused_unsafe)]
return Ok(unsafe { $ok });
} else {
return Err(crate::NcError::with_msg(crate::NCRESULT_ERR, $msg));
}
};
($ptr:expr, $msg:expr) => {
error_ref![$ptr, $msg, &*$ptr];
};
($ptr:expr) => {
error_ref![$ptr, "", &*$ptr];
};
}};
($ptr:expr, $msg:expr) => {{
let ptr = $ptr;
error_ref![$ptr, $msg, unsafe { &*ptr }];
}};
($ptr:expr) => {{
let ptr = $ptr;
error_ref![$ptr, "", unsafe { &*ptr }];
}};
}
/// Returns an `Ok(&mut T)` from a `*mut T` pointer,
@ -171,20 +175,23 @@ macro_rules! error_ref {
/// `$msg` is optional. By default it will be an empty `&str` `""`.
#[macro_export]
macro_rules! error_ref_mut {
($ptr:expr, $msg:expr, $ok:expr) => {
if $ptr != core::ptr::null_mut() {
($ptr:expr, $msg:expr, $ok:expr) => {{
let ptr = $ptr; // avoid calling a function multiple times
if ptr.is_null() {
return Err(crate::NcError::with_msg(crate::NCRESULT_ERR, $msg));
} else {
#[allow(unused_unsafe)]
return Ok(unsafe { $ok });
} else {
return Err(crate::NcError::with_msg(crate::NCRESULT_ERR, $msg));
}
};
($ptr:expr, $msg:expr) => {
error_ref_mut![$ptr, $msg, &mut *$ptr];
};
($ptr:expr) => {
error_ref_mut![$ptr, "", &mut *$ptr];
};
}};
($ptr:expr, $msg:expr) => {{
let ptr = $ptr;
error_ref_mut![ptr, $msg, unsafe { &mut *ptr }];
}};
($ptr:expr) => {{
let ptr = $ptr;
error_ref_mut![ptr, "", unsafe { &mut *ptr }];
}};
}
/// Returns an `Ok(String)` from a `*const` pointer to a C string,

@ -1,5 +1,4 @@
//! `NcPlane*` methods and associated functions.
use core::{
ptr::{null, null_mut},
slice::from_raw_parts_mut,
@ -105,7 +104,7 @@ impl NcPlane {
) -> NcResult<&'a mut NcPlane> {
error_ref_mut![
unsafe { crate::ncpile_create(nc, &options) },
&format!["NcPlane::with_options(Notcurses, {:?})", options]
&format!["NcPlane::with_options(Notcurses, {:?})", &options]
]
}
@ -131,7 +130,7 @@ impl NcPlane {
) -> NcResult<&'a mut NcPlane> {
error_ref_mut![
unsafe { crate::ncplane_create(bound_to, &options) },
&format!("NcPlane::with_options_bound(NcPlane, {:?})", options)
&format!("NcPlane::with_options_bound(NcPlane, {:?})", &options)
]
}

@ -327,7 +327,7 @@ pub const NCBLIT_DEFAULT: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_D
/// See [Sixel in Wikipedia](https://en.wikipedia.org/wiki/Sixel).
pub const NCBLIT_PIXEL: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_PIXEL;
/// Contains the pixel geometry information as returned by the
/// Contains the pixel geometry information as returned by the
/// NcPlane.[pixelgeom()][NcPlane#method.pixelgeom] method.
///
/// If bitmaps are not supported, the fields `max_bitmap_*` will be 0.

@ -4,7 +4,7 @@ use core::ptr::null_mut;
use crate::ffi::__va_list_tag;
use crate::{
nccell_release, cstring, ncplane_channels, NcAlign, NcAlphaBits, NcBoxMask, NcCell, NcChannel,
cstring, nccell_release, ncplane_channels, NcAlign, NcAlphaBits, NcBoxMask, NcCell, NcChannel,
NcChannelPair, NcColor, NcDim, NcEgc, NcIntResult, NcPlane, NcRgb, NcStyleMask, NCRESULT_ERR,
NCRESULT_OK,
};

Loading…
Cancel
Save