[rust] fix check_pixel_support; #2162

- add new type `NcPixelImpl`.
- change `check_pixel_support` return type to `NcPixelImpl`.
- update `pixel-cell` example.
- remove remaining reference to removed `blink`.
- remove reference to removed `ncvisual_default_blitter`.
- rustfmt
This commit is contained in:
joseLuís 2021-09-13 11:45:37 +02:00
parent be1dc5f2f9
commit 123c0d6307
4 changed files with 35 additions and 21 deletions

View File

@ -14,7 +14,7 @@ use libnotcurses_sys::*;
fn main() -> NcResult<()> {
let mut nc = Nc::new()?;
if !nc.check_pixel_support()? {
if nc.check_pixel_support() == NCPIXEL_NONE {
nc.stop()?;
return Err(NcError::new_msg("Current terminal doesn't support pixels."));
}

View File

@ -4,10 +4,10 @@ use core::ptr::{null, null_mut};
use crate::{
cstring, error, error_ref_mut, notcurses_init, rstring, Nc, NcAlign, NcBlitter, NcChannels,
NcDim, NcError, NcFile, NcInput, NcLogLevel, NcOptions, NcPlane, NcResult, NcScale, NcStats,
NcStyle, NcStyleMethods, NcTime, NCOPTION_NO_ALTERNATE_SCREEN, NCOPTION_SUPPRESS_BANNERS,
NCRESULT_ERR, NCSTYLE_BOLD, NCSTYLE_ITALIC, NCSTYLE_NONE, NCSTYLE_STRUCK,
NCSTYLE_UNDERCURL, NCSTYLE_UNDERLINE,
NcDim, NcError, NcFile, NcInput, NcLogLevel, NcOptions, NcPixelImpl, NcPlane, NcResult,
NcScale, NcStats, NcStyle, NcStyleMethods, NcTime, NCOPTION_NO_ALTERNATE_SCREEN,
NCOPTION_SUPPRESS_BANNERS, NCRESULT_ERR, NCSTYLE_BOLD, NCSTYLE_ITALIC, NCSTYLE_NONE,
NCSTYLE_STRUCK, NCSTYLE_UNDERCURL, NCSTYLE_UNDERLINE,
};
/// # `NcOptions` Constructors
@ -251,22 +251,14 @@ impl Nc {
/// Checks for pixel support.
///
/// Returns `false` for no support, or `true` if pixel output is supported.
///
/// This function must successfully return before
/// [NCBLIT_PIXEL][crate::NCBLIT_PIXEL] is available.
///
/// Must not be called concurrently with either input or rasterization.
/// Returns [`NcPixelImpl`] with a non-zero constant corresponding to some
/// pixel-blitting mechanism if bitmap support (via any mechanism) has been
/// detected, or else 0 (NCPIXEL_NONE).
///
/// *C style function: [notcurses_check_pixel_support()][crate::notcurses_check-pixel_support].*
#[allow(clippy::wildcard_in_or_patterns)]
pub fn check_pixel_support(&self) -> NcResult<bool> {
let res: i32 = unsafe { crate::notcurses_check_pixel_support(self) as i32 };
match res {
0 => Ok(false),
1 => Ok(true),
NCRESULT_ERR | _ => Err(NcError::with_msg(res, "Notcuses.check_pixel_support()")),
}
pub fn check_pixel_support(&self) -> NcPixelImpl {
unsafe { crate::notcurses_check_pixel_support(self) }
}
/// Disables the terminal's cursor, if supported.
@ -432,7 +424,7 @@ impl Nc {
/// spaces.
///
/// The supported styles are: `italic`, `underline`, `undercurl`,
/// `struck`, `bold`, `blink` and `none`.
/// `struck`, `bold`, and `none`.
///
/// If a style is are not recognized returns an error.
///

View File

@ -196,7 +196,7 @@ pub const NCLOGLEVEL_VERBOSE: NcLogLevel = crate::bindings::ffi::ncloglevel_e_NC
/// you probably don't want what's happening to happen
pub const NCLOGLEVEL_WARNING: NcLogLevel = crate::bindings::ffi::ncloglevel_e_NCLOGLEVEL_WARNING;
// NcAlign -- ------------------------------------------------------------------
// NcAlign ---------------------------------------------------------------------
/// Alignment within a plane or terminal.
/// Left/right-justified, or centered.

View File

@ -10,7 +10,6 @@
//W ncvisual_at_yx
//W ncvisual_decode
//W ncvisual_decode_loop
// ncvisual_default_blitter
//W ncvisual_destroy
//W ncvisual_from_bgra
//W ncvisual_from_file
@ -236,6 +235,29 @@ 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;
/// Pixel blitting implementations. (Informative only).
///
/// Returned by [`check_pixel_support`][Notcurses#method.check_pixel_support].
pub type NcPixelImpl = crate::bindings::ffi::ncpixelimpl_e;
/// No pixel support.
pub const NCPIXEL_NONE: NcPixelImpl = crate::bindings::ffi::ncpixelimpl_e_NCPIXEL_NONE;
/// Sixel
pub const NCPIXEL_SIXEL: NcPixelImpl = crate::bindings::ffi::ncpixelimpl_e_NCPIXEL_SIXEL;
/// Linux framebuffer.
pub const NCPIXEL_LINUXFB: NcPixelImpl = crate::bindings::ffi::ncpixelimpl_e_NCPIXEL_LINUXFB;
/// iTerm2
pub const NCPIXEL_ITERM2: NcPixelImpl = crate::bindings::ffi::ncpixelimpl_e_NCPIXEL_ITERM2;
/// Kitty prior to C=1 and animation.
pub const NCPIXEL_KITTY_STATIC: NcPixelImpl =
crate::bindings::ffi::ncpixelimpl_e_NCPIXEL_KITTY_STATIC;
/// Kitty with animation but not reflexive composition.
pub const NCPIXEL_KITTY_ANIMATED: NcPixelImpl =
crate::bindings::ffi::ncpixelimpl_e_NCPIXEL_KITTY_ANIMATED;
/// Kitty with reflexive composition.
pub const NCPIXEL_KITTY_SELFREF: NcPixelImpl =
crate::bindings::ffi::ncpixelimpl_e_NCPIXEL_KITTY_SELFREF;
/// Contains the pixel geometry information as returned by the
/// NcPlane.[pixelgeom()][crate::NcPlane#method.pixelgeom] method.
///