From 391c58e4ed4646c5d62b65c4438f3eab5166703c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Sat, 19 Jun 2021 08:42:04 +0200 Subject: [PATCH] [rust] - add ncdirect_canget_cursor - made ncplane_notcurses require a non-mutable reference. --- rust/src/bindings.rs | 1 + rust/src/direct/methods.rs | 17 ++++++++++++++++- rust/src/direct/mod.rs | 21 +++++++++++---------- rust/src/plane/methods.rs | 2 +- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/rust/src/bindings.rs b/rust/src/bindings.rs index feef18b67..b73a2f362 100644 --- a/rust/src/bindings.rs +++ b/rust/src/bindings.rs @@ -162,6 +162,7 @@ pub use ffi::{ pub use ffi::{ // functions ncdirect_box, + ncdirect_canget_cursor, ncdirect_canopen_images, ncdirect_canutf8, ncdirect_check_pixel_support, diff --git a/rust/src/direct/methods.rs b/rust/src/direct/methods.rs index 9001bc645..cda4a990f 100644 --- a/rust/src/direct/methods.rs +++ b/rust/src/direct/methods.rs @@ -93,7 +93,14 @@ impl NcDirect { max_x: NcDim, ) -> NcResult<&'a mut NcDirectV> { let res = unsafe { - crate::ncdirect_render_frame(self, cstring![filename], blitter, scale, max_y as i32, max_x as i32) + crate::ncdirect_render_frame( + self, + cstring![filename], + blitter, + scale, + max_y as i32, + max_x as i32, + ) }; error_ref_mut![ res, @@ -276,6 +283,14 @@ impl NcDirect { /// ## NcDirect methods: capabilities, cursor, dimensions impl NcDirect { + /// Is there support for acquiring the cursor's current position? + /// + /// Requires the u7 terminfo capability, and that we are connected to an + /// actual terminal. + pub fn canget_cursor(&self) -> bool { + unsafe { crate::ncdirect_canget_cursor(self) } + } + /// Can we reliably use Unicode braille? /// /// *C style function: [ncdirect_canbraille()][crate::ncdirect_canbraille].* diff --git a/rust/src/direct/mod.rs b/rust/src/direct/mod.rs index cd6b08700..54ebee2c3 100644 --- a/rust/src/direct/mod.rs +++ b/rust/src/direct/mod.rs @@ -1,15 +1,15 @@ //! `NcDirect` -// total: 61 +// total: 62 // --------------------------------------------------- // (X) 1 : wont do // (~) 3 : TODO / WIP // -// (f) 45 : unsafe ffi function exported by bindgen +// (f) 46 : unsafe ffi function exported by bindgen // (w) 1 : safely wrapped ffi function // (r) 11 : static function manually reimplemented // -// (m) 45 : method implemented +// (m) 55 : method implemented // // (t) 0 : unit test done for the function // (T) 0 : unit test done also for the method @@ -18,14 +18,15 @@ // fm ncdirect_bg_palindex // fm ncdirect_bg_rgb // fm ncdirect_box -// r ncdirect_canbraille -// r ncdirect_canchangecolor -// r ncdirect_canfade -// r ncdirect_canhalfblock +// rm ncdirect_canbraille +// rm ncdirect_canchangecolor +// fm ncdirect_canget_cursor +// rm ncdirect_canfade +// rm ncdirect_canhalfblock // fm ncdirect_canopen_images // rm ncdirect_canopen_videos -// r ncdirect_canquadrant -// r ncdirect_cantruecolor +// rm ncdirect_canquadrant +// rm ncdirect_cantruecolor // fm ncdirect_canutf8 // wm ncdirect_capabilities // fm ncdirect_check_pixel_support @@ -41,7 +42,7 @@ // fm ncdirect_cursor_right // fm ncdirect_cursor_up // fm ncdirect_cursor_yx -// ncdirect_detected_terminal +// fm ncdirect_detected_terminal // fm ncdirect_dim_x // fm ncdirect_dim_y // fm ncdirect_double_box diff --git a/rust/src/plane/methods.rs b/rust/src/plane/methods.rs index 8ddd310e4..efdf418d9 100644 --- a/rust/src/plane/methods.rs +++ b/rust/src/plane/methods.rs @@ -1171,7 +1171,7 @@ impl NcPlane { /// Gets a mutable reference to the [`Nc`] context of this NcPlane. /// /// *C style function: [ncplane_notcurses()][crate::ncplane_notcurses].* - pub fn notcurses<'a>(&mut self) -> NcResult<&'a mut Nc> { + pub fn notcurses<'a>(&self) -> NcResult<&'a mut Nc> { error_ref_mut![ unsafe { crate::ncplane_notcurses(self) }, "NcPlane.notcurses()"