From 9e2add4e4689bf16699f05632050ceb141af16d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Thu, 22 Apr 2021 12:25:24 +0200 Subject: [PATCH] [rust] update capabilities, support new functions. - add new Notcurses methods: `canhalfblock()` and `canquadrant()`. - add doc links to NCBLIT_* flags from the capabilities methods. - update the full-capabilites example to include `canhalfblock`, `canquadrant`, `canchangecolor` and `canfade` functions. - rustfmt --- rust/examples/full-capabilities.rs | 18 +++++++++++++----- rust/src/bindings.rs | 2 ++ rust/src/channel/mod.rs | 2 +- rust/src/notcurses/methods.rs | 25 ++++++++++++++++++++++++- rust/src/visual/mod.rs | 2 +- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/rust/examples/full-capabilities.rs b/rust/examples/full-capabilities.rs index f7b90bb07..b215fb467 100644 --- a/rust/examples/full-capabilities.rs +++ b/rust/examples/full-capabilities.rs @@ -10,19 +10,27 @@ fn main() -> NcResult<()> { "Can display UTF-8: {0} Can display braille characters: {1} Can display sextant characters: {2} -Can open images: {3} -Can open videos: {4} -Supports Pixels: {5:?} -Supports True Color: {6} -Palette size: {7:?} +Can display quadrant characters: {3} +Can display half block characters: {4} +Can open images: {5} +Can open videos: {6} +Supports Pixels: {7:?} +Supports True Color: {8} +Supports fading: {9} +Supports changing the palette: {10} +Palette size: {11:?} ", nc.canutf8(), nc.canbraille(), nc.cansextant(), + nc.canquadrant(), + nc.canhalfblock(), nc.canopen_images(), nc.canopen_videos(), nc.check_pixel_support(), nc.cantruecolor(), + nc.canfade(), + nc.canchangecolor(), nc.palette_size(), ); diff --git a/rust/src/bindings.rs b/rust/src/bindings.rs index f845a180e..521003a1e 100644 --- a/rust/src/bindings.rs +++ b/rust/src/bindings.rs @@ -711,8 +711,10 @@ pub use ffi::{ notcurses_canbraille, notcurses_canchangecolor, notcurses_canfade, + notcurses_canhalfblock, notcurses_canopen_images, notcurses_canopen_videos, + notcurses_canquadrant, notcurses_cansextant, notcurses_cantruecolor, notcurses_canutf8, diff --git a/rust/src/channel/mod.rs b/rust/src/channel/mod.rs index b62965d5e..608106a40 100644 --- a/rust/src/channel/mod.rs +++ b/rust/src/channel/mod.rs @@ -61,7 +61,7 @@ // X channels_set_fg_rgb8_clipped // not needed #[allow(unused_imports)] // for the doc comments -use crate::{NcRgba}; +use crate::NcRgba; #[cfg(test)] mod test; diff --git a/rust/src/notcurses/methods.rs b/rust/src/notcurses/methods.rs index b19620b7c..11c303509 100644 --- a/rust/src/notcurses/methods.rs +++ b/rust/src/notcurses/methods.rs @@ -162,6 +162,8 @@ impl Notcurses { /// Returns true if we can reliably use Unicode Braille. /// + /// See also [NCBLIT_BRAILLE][crate::NCBLIT_BRAILLE]. + /// /// *C style function: [notcurses_canbraille()][crate::notcurses_canbraille].* pub fn canbraille(&self) -> bool { unsafe { crate::notcurses_canbraille(self) } @@ -185,6 +187,15 @@ impl Notcurses { unsafe { crate::notcurses_canfade(self) } } + /// Returns true if we can reliably use Unicode half blocks. + /// + /// See also [NCBLIT_2x1][crate::NCBLIT_2x1]. + /// + /// *C style function: [notcurses_canhalfblock()][crate::notcurses_canhalfblock].* + pub fn canhalfblock(&self) -> bool { + unsafe { crate::notcurses_canhalfblock(self) } + } + /// Returns true if loading images is possible. /// /// This requires being built against FFmpeg/OIIO. @@ -203,8 +214,19 @@ impl Notcurses { unsafe { crate::notcurses_canopen_videos(self) } } + /// Returns true if we can reliably use Unicode quadrant blocks. + /// + /// See also [NCBLIT_2x2][crate::NCBLIT_2x2]. + /// + /// *C style function: [notcurses_canquadrant()][crate::notcurses_canquadrant].* + pub fn canquadrant(&self) -> bool { + unsafe { crate::notcurses_canquadrant(self) } + } + /// Returns true if we can reliably use Unicode 13 sextants. /// + /// See also [NCBLIT_3x2][crate::NCBLIT_3x2]. + /// /// *C style function: [notcurses_cansextant()][crate::notcurses_cansextant].* pub fn cansextant(&self) -> bool { unsafe { crate::notcurses_cansextant(self) } @@ -231,7 +253,8 @@ impl Notcurses { /// /// Returns `false` for no support, or `true` if pixel output is supported. /// - /// This function must successfully return before NCBLIT_PIXEL is available. + /// This function must successfully return before + /// [NCBLIT_PIXEL][crate::NCBLIT_PIXEL] is available. /// /// Must not be called concurrently with either input or rasterization. /// diff --git a/rust/src/visual/mod.rs b/rust/src/visual/mod.rs index 02ac3840e..5a45b8f80 100644 --- a/rust/src/visual/mod.rs +++ b/rust/src/visual/mod.rs @@ -142,7 +142,7 @@ pub const NCVISUAL_OPTION_HORALIGNED: u32 = crate::bindings::ffi::NCVISUAL_OPTIO /// - without sextant support, NCBLIT_3x2 decays to NCBLIT_2x2 /// - without quadrant support, NCBLIT_2x2 decays to NCBLIT_2x1 /// - the only viable blitters in ASCII are NCBLIT_1x1 and NCBLIT_PIXEL -/// +/// /// If you don't want this behaviour you have to use [NCVISUAL_OPTION_NODEGRADE] /// pub type NcBlitter = crate::bindings::ffi::ncblitter_e;