From 3d830f5e7310579988c0e69b7b88018351e6b045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Sun, 13 Jun 2021 13:07:00 +0200 Subject: [PATCH] [rust] updates against 2.3.4 - remove ncvisual_inflate and add ncvisual_resize_noninterpolative & fix example. - add notcurses_detected_terminal & ncdirect_detected_terminal. - take into account new static functions pending to implement: ncdirect_light_box, ncdirect_heavy_box, nccells_light_box, nccells_heavy_box, nccells_ascii_box. - update module info headers notation. --- rust/examples/pixel-cell.rs | 2 +- rust/src/bindings.rs | 4 +++- rust/src/cells/mod.rs | 5 ++++- rust/src/direct/methods.rs | 7 +++++++ rust/src/direct/mod.rs | 9 ++++++--- rust/src/notcurses/methods.rs | 7 +++++++ rust/src/notcurses/mod.rs | 5 +++-- rust/src/visual/methods.rs | 29 +++++++++++++++++++---------- 8 files changed, 50 insertions(+), 18 deletions(-) diff --git a/rust/examples/pixel-cell.rs b/rust/examples/pixel-cell.rs index 5e2adb293..f7ca6007e 100644 --- a/rust/examples/pixel-cell.rs +++ b/rust/examples/pixel-cell.rs @@ -85,7 +85,7 @@ fn main() -> NcResult<()> { // inflate the ncvisual (doesn't use interpolation) let voptions4 = NcVisualOptions::without_plane(7, 33, 0, 0, pg.cell_y, pg.cell_x, NCBLIT_PIXEL, 0, 0); - v1.inflate(4)?; + v1.resize_noninterpolative(pg.cell_y * 4, pg.cell_x * 4)?; v1.render(&mut nc, &voptions4)?; rsleep![&mut nc, 1]; diff --git a/rust/src/bindings.rs b/rust/src/bindings.rs index a2d05a832..43b809fea 100644 --- a/rust/src/bindings.rs +++ b/rust/src/bindings.rs @@ -157,6 +157,7 @@ pub use ffi::{ ncdirect_cursor_right, ncdirect_cursor_up, ncdirect_cursor_yx, + ncdirect_detected_terminal, ncdirect_dim_x, ncdirect_dim_y, ncdirect_double_box, @@ -717,11 +718,11 @@ pub use ffi::{ ncvisual_from_file, ncvisual_from_plane, ncvisual_from_rgba, - ncvisual_inflate, ncvisual_media_defblitter, ncvisual_polyfill_yx, ncvisual_render, ncvisual_resize, + ncvisual_resize_noninterpolative, ncvisual_rotate, ncvisual_set_yx, ncvisual_simple_streamer, @@ -768,6 +769,7 @@ pub use ffi::{ notcurses_cursor_yx, notcurses_debug, notcurses_debug_caps, + notcurses_detected_terminal, notcurses_drop_planes, notcurses_getc, notcurses_init, diff --git a/rust/src/cells/mod.rs b/rust/src/cells/mod.rs index a6ddf40eb..bc2cb703e 100644 --- a/rust/src/cells/mod.rs +++ b/rust/src/cells/mod.rs @@ -13,7 +13,7 @@ //W nccell_duplicate //W nccell_release // -// functions manually reimplemented: 43 +// functions manually reimplemented: 46 // ------------------------------------------ // (X) wont: 2 // (+) done: 38 @@ -61,6 +61,9 @@ //W+ nccell_wide_left_p //W+ nccell_wide_right_p //W+ nccellcmp +// nccells_ascii_box +// nccells_heavy_box +// nccells_light_box //W+ nccells_load_box #[cfg(test)] diff --git a/rust/src/direct/methods.rs b/rust/src/direct/methods.rs index fe1caa101..99c5f8ec2 100644 --- a/rust/src/direct/methods.rs +++ b/rust/src/direct/methods.rs @@ -444,6 +444,13 @@ impl NcDirect { let x = unsafe { crate::ncdirect_dim_x(self) as NcDim }; (y, x) } + + /// Returns the name of the detected terminal. + /// + /// *C style function: [ncdirect_detected_terminal()][crate::ncdirect_detected_terminal].* + pub fn detected_terminal(&self) -> String { + rstring![crate::ncdirect_detected_terminal(self)].to_string() + } } /// ## NcDirect methods: I/O diff --git a/rust/src/direct/mod.rs b/rust/src/direct/mod.rs index bd5bb6407..a177979a8 100644 --- a/rust/src/direct/mod.rs +++ b/rust/src/direct/mod.rs @@ -1,15 +1,15 @@ //! `NcDirect` -// total: 50 +// total: 53 // --------------------------------------------------- // (X) 1 : wont do +// (~) 3 : TODO / WIP // // (f) 45 : unsafe ffi function exported by bindgen // (w) 0 : safely wrapped ffi function // (r) 4 : static function manually reimplemented // // (m) 45 : method implemented -// (~) 1 : work in progress // // (t) 0 : unit test done for the function // (T) 0 : unit test done also for the method @@ -22,7 +22,7 @@ // fm ncdirect_canutf8 // fm ncdirect_check_pixel_support // fm ncdirect_clear -// f~ ncdirect_core_init +//~f ncdirect_core_init // fm ncdirect_cursor_disable // fm ncdirect_cursor_down // fm ncdirect_cursor_enable @@ -33,6 +33,7 @@ // fm ncdirect_cursor_right // fm ncdirect_cursor_up // fm ncdirect_cursor_yx +// ncdirect_detected_terminal // fm ncdirect_dim_x // fm ncdirect_dim_y // fm ncdirect_double_box @@ -41,9 +42,11 @@ // fm ncdirect_fg_rgb // fm ncdirect_flush // fm ncdirect_getc +//~r ncdirect_heavy_box, // fm ncdirect_hline_interp // fm ncdirect_init // fm ncdirect_inputready_fd +//~r ncdirect_light_box, // fm ncplane_on_styles // fm ncplane_off_styles // fm ncdirect_palette_size diff --git a/rust/src/notcurses/methods.rs b/rust/src/notcurses/methods.rs index 1e324a238..1039f10a5 100644 --- a/rust/src/notcurses/methods.rs +++ b/rust/src/notcurses/methods.rs @@ -311,6 +311,13 @@ impl Notcurses { } } + /// Returns the name of the detected terminal. + /// + /// *C style function: [notcurses_detected_terminal()][crate::notcurses_detected_terminal].* + pub fn detected_terminal(&self) -> String { + rstring![crate::notcurses_detected_terminal(self)].to_string() + } + /// Destroys all [NcPlane]s other than the stdplane. /// /// *C style function: [notcurses_drop_planes()][crate::notcurses_drop_planes].* diff --git a/rust/src/notcurses/mod.rs b/rust/src/notcurses/mod.rs index 6c9c73171..5f35fae57 100644 --- a/rust/src/notcurses/mod.rs +++ b/rust/src/notcurses/mod.rs @@ -1,15 +1,15 @@ //! `Notcurses` -// total: 52 +// total: 53 // --------------------------------------------------- // (X) 1 : wont do +// (…) 4 : TODO / WIP // // (f) 45 : unsafe ffi function exported by bindgen // (w) 0 : safely wrapped ffi function // (r) 6 : static function manually reimplemented // // (m) 38 : method implemented -// (~) 3 : work in progress // // (t) 13 : unit test done for the function // (T) 0 : unit test done also for the method @@ -31,6 +31,7 @@ // f notcurses_cursor_yx // fmt notcurses_debug // fm notcurses_debug_caps +//~f notcurses_detected_terminal // fmt notcurses_drop_planes // fm notcurses_getc // fmt notcurses_init diff --git a/rust/src/visual/methods.rs b/rust/src/visual/methods.rs index 8252f7f37..5f132c59a 100644 --- a/rust/src/visual/methods.rs +++ b/rust/src/visual/methods.rs @@ -263,14 +263,6 @@ impl NcVisual { } } - /// Inflates each pixel in the image to 'scale'x'scale' pixels. - /// - /// The original color is retained. - pub fn inflate(&mut self, scale: u32) -> NcResult { - let res = unsafe { crate::ncvisual_inflate(self, scale as i32) }; - error![res, &format!["NcVisual.inflate({})", scale], res] - } - /// Gets the size and ratio of NcVisual pixels to output cells along the /// `y→to_y` and `x→to_x` axes. /// @@ -352,18 +344,35 @@ impl NcVisual { ] } - /// Resizes the visual to `rows` X `columns` pixels. + /// Resizes the visual to `cols` X `rows` pixels. /// /// This is a lossy transformation, unless the size is unchanged. /// /// *C style function: [ncvisual_resize()][crate::ncvisual_resize].* - pub fn resize(&mut self, rows: NcDim, cols: NcDim) -> NcResult<()> { + pub fn resize(&mut self, cols: NcDim, rows: NcDim) -> NcResult<()> { error![ unsafe { crate::ncvisual_resize(self, rows as i32, cols as i32) }, &format!["NcVisual.resize({}, {})", rows, cols] ] } + /// Resizes the visual to in the image to `rows` X `cols` pixels, without + /// interpolating the color values. + /// + /// The original color is retained. + /// + /// *C style function: + /// [ncvisual_resize_noninterpolative()][crate::ncvisual_resize_noninterpolative].* + pub fn resize_noninterpolative(&mut self, cols: NcDim, rows: NcDim) -> NcResult { + let res = + unsafe { crate::ncvisual_resize_noninterpolative(self, rows as i32, cols as i32) }; + error![ + res, + &format!["NcVisual.resize_noninterpolative({}, {})", cols, rows], + res + ] + } + /// Rotates the visual `rads` radians. /// /// Only M_PI/2 and -M_PI/2 are supported at the moment,