From 4beec0845fae6a23fa57ceaf12a6382610defe7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Thu, 5 Nov 2020 18:34:06 +0100 Subject: [PATCH] rust: type changes - rename types in order to make them more similar to the original ones, and so that they play better alongside the higher types defined by notcurses-rs. - Plane -> NcPlane - DirectMode -> NcDirect - DirectModeFlags -> NcDirectFlags - FullMode -> Notcurses - Align -> NcAlign - Blitter -> NcBlitter - Scale -> NcScale - make `types` module re-exportable. - rename nc module to notcurses. - improve comments. --- rust/src/cells.rs | 12 +++--- rust/src/direct.rs | 8 ++-- rust/src/lib.rs | 7 ++-- rust/src/{nc.rs => notcurses.rs} | 20 +++++----- rust/src/plane.rs | 67 ++++++++++++++++---------------- rust/src/types.rs | 64 +++++++++++++++--------------- rust/src/visual.rs | 12 +++--- 7 files changed, 97 insertions(+), 93 deletions(-) rename rust/src/{nc.rs => notcurses.rs} (81%) diff --git a/rust/src/cells.rs b/rust/src/cells.rs index 174ebd30c..7c6f0f472 100644 --- a/rust/src/cells.rs +++ b/rust/src/cells.rs @@ -58,7 +58,7 @@ use crate as nc; use nc::types::{ - AlphaBits, Cell, CellGcluster, Channel, ChannelPair, Color, IntResult, PaletteIndex, Plane, + AlphaBits, Cell, CellGcluster, Channel, ChannelPair, Color, IntResult, NcPlane, PaletteIndex, StyleMask, EGC, }; @@ -99,7 +99,7 @@ pub unsafe fn cell_prime( /// #[allow(unused_unsafe)] pub unsafe fn cells_load_box( - plane: &mut Plane, + plane: &mut NcPlane, style: StyleMask, channels: ChannelPair, ul: &mut Cell, @@ -242,7 +242,7 @@ pub fn cell_wide_left_p(cell: &Cell) -> bool { /// copy the UTF8-encoded EGC out of the cell, whether simple or complex. the /// result is not tied to the ncplane, and persists across erases / destruction. #[inline] -pub fn cell_strdup(plane: &Plane, cell: &Cell) -> EGC { +pub fn cell_strdup(plane: &NcPlane, cell: &Cell) -> EGC { core::char::from_u32( unsafe { libc::strdup(nc::cell_extended_gcluster(plane, cell)) } as i32 as u32, ) @@ -257,7 +257,7 @@ pub fn cell_strdup(plane: &Plane, cell: &Cell) -> EGC { /// Extract the three elements of a cell. #[inline] pub fn cell_extract( - plane: &Plane, + plane: &NcPlane, cell: &Cell, stylemask: &mut StyleMask, channels: &mut ChannelPair, @@ -276,7 +276,7 @@ pub fn cell_extract( /// be the same. Only the expanded EGC must be equal. The EGC must be bit-equal; /// it would probably be better to test whether they're Unicode-equal FIXME. #[inline] -pub fn cellcmp(plane1: &Plane, cell1: &Cell, plane2: &Plane, cell2: &Cell) -> bool { +pub fn cellcmp(plane1: &NcPlane, cell1: &Cell, plane2: &NcPlane, cell2: &Cell) -> bool { if cell1.stylemask != cell2.stylemask { return true; } @@ -294,7 +294,7 @@ pub fn cellcmp(plane1: &Plane, cell1: &Cell, plane2: &Plane, cell2: &Cell) -> bo /// // NOTE: remove casting for CELL_WIEDASIAN_MASK when fixed: https://github.com/rust-lang/rust-bindgen/issues/1875 #[inline] -pub fn cell_load_simple(plane: &mut Plane, cell: &mut Cell, ch: EGC) -> i32 { +pub fn cell_load_simple(plane: &mut NcPlane, cell: &mut Cell, ch: EGC) -> i32 { unsafe { nc::cell_release(plane, cell); } diff --git a/rust/src/direct.rs b/rust/src/direct.rs index 1894efa9f..347b25ecb 100644 --- a/rust/src/direct.rs +++ b/rust/src/direct.rs @@ -26,7 +26,7 @@ // ncdirect_flush // ncdirect_getc // ncdirect_hline_interp -// ncdirect_init // wrapped at start() +// ncdirect_init // wrapped at _new() & _with_flags() // ncdirect_inputready_fd // ncdirect_palette_size // ncdirect_printf_aligned @@ -40,7 +40,7 @@ // ncdirect_vline_interp use crate as nc; -use nc::types::{DirectMode, DirectModeFlags}; +use nc::types::{NcDirect, NcDirectFlags}; extern "C" { fn libc_stdout() -> *mut nc::_IO_FILE; @@ -55,7 +55,7 @@ extern "C" { /// used to add color and styling to text in the standard output paradigm. /// /// Returns NULL on error, including any failure initializing terminfo. -pub unsafe fn ncdirect_new() -> *mut DirectMode { +pub unsafe fn ncdirect_new() -> *mut NcDirect { ncdirect_with_flags(0) } @@ -65,6 +65,6 @@ pub unsafe fn ncdirect_new() -> *mut DirectMode { /// - NCDIRECT_OPTION_INHIBIT_CBREAK /// - NCDIRECT_OPTION_INHIBIT_SETLOCALE /// -pub unsafe fn ncdirect_with_flags(flags: DirectModeFlags) -> *mut DirectMode { +pub unsafe fn ncdirect_with_flags(flags: NcDirectFlags) -> *mut NcDirect { nc::ncdirect_init(core::ptr::null(), libc_stdout(), flags) } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index aed71ba13..56bc64c2f 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -21,19 +21,20 @@ mod direct; mod input; mod key; mod keycodes; -mod nc; +mod notcurses; mod palette; mod pixel; mod plane; -mod types; +pub mod types; // re-exportable mod visual; + pub use cells::*; pub use channel::*; pub use direct::*; pub use input::*; pub use key::*; pub use keycodes::*; -pub use nc::*; +pub use notcurses::*; pub use palette::*; pub use pixel::*; pub use plane::*; diff --git a/rust/src/nc.rs b/rust/src/notcurses.rs similarity index 81% rename from rust/src/nc.rs rename to rust/src/notcurses.rs index fa8dfa36b..49f957bd6 100644 --- a/rust/src/nc.rs +++ b/rust/src/notcurses.rs @@ -55,27 +55,27 @@ use core::ptr::null; use crate as nc; -use nc::types::{Align, FullMode, Input, Plane, ALIGN_CENTER, ALIGN_LEFT}; +use nc::types::{Input, NcAlign, NcPlane, Notcurses, NCALIGN_CENTER, NCALIGN_LEFT}; /// return the offset into 'availcols' at which 'cols' ought be output given the requirements of 'align' #[inline] -pub fn notcurses_align(availcols: i32, align: Align, cols: i32) -> i32 { - if align == ALIGN_LEFT { +pub fn notcurses_align(availcols: i32, align: NcAlign, cols: i32) -> i32 { + if align == NCALIGN_LEFT { return 0; } if cols > availcols { return 0; } - if align == ALIGN_CENTER { + if align == NCALIGN_CENTER { return (availcols - cols) / 2; } - availcols - cols // ALIGN_RIGHT + availcols - cols // NCALIGN_RIGHT } /// 'input' may be NULL if the caller is uninterested in event details. /// If no event is ready, returns 0. #[inline] -pub fn notcurses_getc_nblock(nc: &mut FullMode, input: &mut Input) -> nc::char32_t { +pub fn notcurses_getc_nblock(nc: &mut Notcurses, input: &mut Input) -> nc::char32_t { unsafe { let mut sigmask = nc::sigset_t { __val: [0; 16] }; nc::sigfillset(&mut sigmask); @@ -90,7 +90,7 @@ pub fn notcurses_getc_nblock(nc: &mut FullMode, input: &mut Input) -> nc::char32 /// 'input' may be NULL if the caller is uninterested in event details. /// Blocks until an event is processed or a signal is received. #[inline] -pub fn notcurses_getc_nblocking(nc: &mut FullMode, input: &mut Input) -> nc::char32_t { +pub fn notcurses_getc_nblocking(nc: &mut Notcurses, input: &mut Input) -> nc::char32_t { unsafe { let mut sigmask = nc::sigset_t { __val: [0; 16] }; nc::sigemptyset(&mut sigmask); @@ -100,7 +100,7 @@ pub fn notcurses_getc_nblocking(nc: &mut FullMode, input: &mut Input) -> nc::cha /// notcurses_stdplane(), plus free bonus dimensions written to non-NULL y/x! #[inline] -pub fn notcurses_stddim_yx(nc: &mut FullMode, y: &mut i32, x: &mut i32) -> Plane { +pub fn notcurses_stddim_yx(nc: &mut Notcurses, y: &mut i32, x: &mut i32) -> NcPlane { unsafe { let s = nc::notcurses_stdplane(nc); nc::ncplane_dim_yx(s, y, x); @@ -110,14 +110,14 @@ pub fn notcurses_stddim_yx(nc: &mut FullMode, y: &mut i32, x: &mut i32) -> Plane /// Return our current idea of the terminal dimensions in rows and cols. #[inline] -pub fn notcurses_term_dim_yx(nc: &FullMode, rows: &mut i32, cols: &mut i32) { +pub fn notcurses_term_dim_yx(nc: &Notcurses, rows: &mut i32, cols: &mut i32) { unsafe { nc::ncplane_dim_yx(nc::notcurses_stdplane_const(nc), rows, cols); } } // TODO -// pub unsafe fn notcurses_start() -> *mut FullMode { +// pub unsafe fn notcurses_start() -> *mut Notcurses { // nc::notcurses_init(core::ptr::null(), libc_stdout()) // } diff --git a/rust/src/plane.rs b/rust/src/plane.rs index 268bb798c..6ea03e240 100644 --- a/rust/src/plane.rs +++ b/rust/src/plane.rs @@ -156,7 +156,8 @@ use cstr_core::CString; use crate as nc; use nc::types::{ - Align, AlphaBits, Cell, Channel, ChannelPair, Color, EGCBackstop, IntResult, Plane, StyleMask, + AlphaBits, Cell, Channel, ChannelPair, Color, EGCBackstop, IntResult, NcAlign, NcPlane, + StyleMask, }; /// Return the column at which 'cols' columns ought start in order to be aligned @@ -165,14 +166,14 @@ use nc::types::{ // // NOTE: [leave cols as i32](https://github.com/dankamongmen/notcurses/issues/904) #[inline] -pub fn ncplane_align(plane: &Plane, align: Align, cols: i32) -> i32 { +pub fn ncplane_align(plane: &NcPlane, align: NcAlign, cols: i32) -> i32 { nc::notcurses_align(nc::ncplane_dim_x(plane), align, cols) } /// Retrieve the current contents of the cell under the cursor into 'cell'. /// This cell is invalidated if the associated plane is destroyed. #[inline] -pub fn nplane_at_cursor_cell(plane: &mut Plane, cell: &mut Cell) -> IntResult { +pub fn nplane_at_cursor_cell(plane: &mut NcPlane, cell: &mut Cell) -> IntResult { let mut egc = unsafe { nc::ncplane_at_cursor(plane, &mut cell.stylemask, &mut cell.channels) }; if egc.is_null() { return -1; @@ -189,7 +190,7 @@ pub fn nplane_at_cursor_cell(plane: &mut Plane, cell: &mut Cell) -> IntResult { /// Retrieve the current contents of the specified cell into 'cell'. /// This cell is invalidated if the associated plane is destroyed. #[inline] -pub fn ncplane_at_yx_cell(plane: &mut Plane, y: i32, x: i32, cell: &mut Cell) -> IntResult { +pub fn ncplane_at_yx_cell(plane: &mut NcPlane, y: i32, x: i32, cell: &mut Cell) -> IntResult { let mut egc = unsafe { nc::ncplane_at_yx(plane, y, x, &mut cell.stylemask, &mut cell.channels) }; if egc.is_null() { @@ -209,7 +210,7 @@ pub fn ncplane_at_yx_cell(plane: &mut Plane, y: i32, x: i32, cell: &mut Cell) -> /// minimum box size is 2x2, and it cannot be drawn off-screen. #[inline] pub fn ncplane_box_sized( - plane: &mut Plane, + plane: &mut NcPlane, ul: &Cell, ur: &Cell, ll: &Cell, @@ -240,7 +241,7 @@ pub fn ncplane_box_sized( /// #[inline] -pub fn ncplane_dim_x(plane: &Plane) -> i32 { +pub fn ncplane_dim_x(plane: &NcPlane) -> i32 { unsafe { let mut x = 0; nc::ncplane_dim_yx(plane, null_mut(), &mut x); @@ -250,7 +251,7 @@ pub fn ncplane_dim_x(plane: &Plane) -> i32 { /// #[inline] -pub fn ncplane_dim_y(plane: &Plane) -> i32 { +pub fn ncplane_dim_y(plane: &NcPlane) -> i32 { unsafe { let mut y = 0; nc::ncplane_dim_yx(plane, &mut y, null_mut()); @@ -261,7 +262,7 @@ pub fn ncplane_dim_y(plane: &Plane) -> i32 { /// #[inline] pub fn ncplane_double_box( - plane: &mut Plane, + plane: &mut NcPlane, stylemask: StyleMask, channels: ChannelPair, ystop: i32, @@ -307,7 +308,7 @@ pub fn ncplane_double_box( /// #[inline] pub fn ncplane_double_box_sized( - plane: &mut Plane, + plane: &mut NcPlane, stylemask: StyleMask, channels: ChannelPair, ylen: i32, @@ -330,14 +331,14 @@ pub fn ncplane_double_box_sized( /// On error, return the negative number of cells drawn. #[inline] -pub fn ncplane_hline(plane: &mut Plane, cell: &Cell, len: i32) -> i32 { +pub fn ncplane_hline(plane: &mut NcPlane, cell: &Cell, len: i32) -> i32 { unsafe { nc::ncplane_hline_interp(plane, cell, len, cell.channels, cell.channels) } } /// #[inline] pub fn ncplane_perimeter( - plane: &mut Plane, + plane: &mut NcPlane, ul: &Cell, ur: &Cell, ll: &Cell, @@ -357,7 +358,7 @@ pub fn ncplane_perimeter( /// #[inline] pub fn ncplane_perimeter_double( - plane: &mut Plane, + plane: &mut NcPlane, stylemask: StyleMask, channels: ChannelPair, ctlword: u32, @@ -406,7 +407,7 @@ pub fn ncplane_perimeter_double( /// #[inline] pub fn ncplane_perimeter_rounded( - plane: &mut Plane, + plane: &mut NcPlane, stylemask: StyleMask, channels: ChannelPair, ctlword: u32, @@ -454,19 +455,19 @@ pub fn ncplane_perimeter_rounded( /// Call ncplane_putc_yx() for the current cursor location. #[inline] -pub fn ncplane_putc(plane: &mut Plane, cell: &Cell) -> IntResult { +pub fn ncplane_putc(plane: &mut NcPlane, cell: &Cell) -> IntResult { unsafe { nc::ncplane_putc_yx(plane, -1, -1, cell) } } /// Call ncplane_putegc() at the current cursor location. #[inline] -pub fn ncplane_putegc(plane: &mut Plane, gcluster: i8, sbytes: &mut i32) -> IntResult { +pub fn ncplane_putegc(plane: &mut NcPlane, gcluster: i8, sbytes: &mut i32) -> IntResult { unsafe { nc::ncplane_putegc_yx(plane, -1, -1, &gcluster, sbytes) } } /// #[inline] -pub fn ncplane_putstr(plane: &mut Plane, gclustarr: &[u8]) -> IntResult { +pub fn ncplane_putstr(plane: &mut NcPlane, gclustarr: &[u8]) -> IntResult { unsafe { nc::ncplane_putstr_yx( plane, @@ -479,7 +480,7 @@ pub fn ncplane_putstr(plane: &mut Plane, gclustarr: &[u8]) -> IntResult { /// #[inline] -pub fn ncplane_putnstr(plane: &mut Plane, size: nc::size_t, gclustarr: &[u8]) -> IntResult { +pub fn ncplane_putnstr(plane: &mut NcPlane, size: nc::size_t, gclustarr: &[u8]) -> IntResult { unsafe { nc::ncplane_putnstr_yx( plane, @@ -494,7 +495,7 @@ pub fn ncplane_putnstr(plane: &mut Plane, size: nc::size_t, gclustarr: &[u8]) -> /// Resize the plane, retaining what data we can (everything, unless we're /// shrinking in some dimension). Keep the origin where it is. #[inline] -pub fn ncplane_resize_simple(plane: &mut Plane, ylen: i32, xlen: i32) -> IntResult { +pub fn ncplane_resize_simple(plane: &mut NcPlane, ylen: i32, xlen: i32) -> IntResult { let (mut oldy, mut oldx) = (0, 0); unsafe { nc::ncplane_dim_yx(plane, &mut oldy, &mut oldx); @@ -519,13 +520,13 @@ pub fn ncplane_resize_simple(plane: &mut Plane, ylen: i32, xlen: i32) -> IntResu /// /// On error, return the negative number of cells drawn. #[inline] -pub fn ncplane_vline(plane: &mut Plane, cell: &Cell, len: i32) -> i32 { +pub fn ncplane_vline(plane: &mut NcPlane, cell: &Cell, len: i32) -> i32 { unsafe { nc::ncplane_vline_interp(plane, cell, len, cell.channels, cell.channels) } } /// #[inline] -pub fn ncplane_vprintf(plane: &mut Plane, format: &str, ap: &mut nc::__va_list_tag) -> IntResult { +pub fn ncplane_vprintf(plane: &mut NcPlane, format: &str, ap: &mut nc::__va_list_tag) -> IntResult { unsafe { nc::ncplane_vprintf_yx( plane, @@ -543,7 +544,7 @@ pub fn ncplane_vprintf(plane: &mut Plane, format: &str, ap: &mut nc::__va_list_t // XXX receive cells as u32? https://github.com/dankamongmen/notcurses/issues/920 #[inline] pub fn ncplane_gradient_sized( - plane: &mut Plane, + plane: &mut NcPlane, egc: &[u8], stylemask: StyleMask, ul: u64, @@ -575,56 +576,56 @@ pub fn ncplane_gradient_sized( /// Extract the 32-bit working foreground channel from an ncplane. #[inline] -pub fn ncplane_fchannel(plane: &Plane) -> Channel { +pub fn ncplane_fchannel(plane: &NcPlane) -> Channel { nc::channels_fchannel(unsafe { nc::ncplane_channels(plane) }) } /// Extract the 32-bit working background channel from an ncplane. #[inline] -pub fn ncplane_bchannel(plane: &Plane) -> Channel { +pub fn ncplane_bchannel(plane: &NcPlane) -> Channel { nc::channels_bchannel(unsafe { nc::ncplane_channels(plane) }) } /// Extract 24 bits of working foreground RGB from an ncplane, shifted to LSBs. #[inline] -pub fn ncplane_fg_rgb(plane: &Plane) -> Channel { +pub fn ncplane_fg_rgb(plane: &NcPlane) -> Channel { nc::channels_fg_rgb(unsafe { nc::ncplane_channels(plane) }) } /// Extract 24 bits of working background RGB from an ncplane, shifted to LSBs. #[inline] -pub fn ncplane_bg_rgb(plane: &Plane) -> Channel { +pub fn ncplane_bg_rgb(plane: &NcPlane) -> Channel { nc::channels_bg_rgb(unsafe { nc::ncplane_channels(plane) }) } /// Extract 2 bits of foreground alpha from 'struct ncplane', shifted to LSBs. #[inline] -pub fn ncplane_fg_alpha(plane: &Plane) -> AlphaBits { +pub fn ncplane_fg_alpha(plane: &NcPlane) -> AlphaBits { nc::channels_fg_alpha(unsafe { nc::ncplane_channels(plane) }) } /// Extract 2 bits of background alpha from 'struct ncplane', shifted to LSBs. #[inline] -pub fn ncplane_bg_alpha(plane: &Plane) -> AlphaBits { +pub fn ncplane_bg_alpha(plane: &NcPlane) -> AlphaBits { nc::channels_bg_alpha(unsafe { nc::ncplane_channels(plane) }) } /// Is the plane's foreground using the "default foreground color"? #[inline] -pub fn ncplane_fg_default_p(plane: &Plane) -> bool { +pub fn ncplane_fg_default_p(plane: &NcPlane) -> bool { nc::channels_fg_default_p(unsafe { nc::ncplane_channels(plane) }) } /// Is the plane's background using the "default background color"? #[inline] -pub fn ncplane_bg_default_p(plane: &Plane) -> bool { +pub fn ncplane_bg_default_p(plane: &NcPlane) -> bool { nc::channels_bg_default_p(unsafe { nc::ncplane_channels(plane) }) } /// Extract 24 bits of foreground RGB from a plane, split into components. #[inline] pub fn ncplane_fg_rgb8( - plane: &Plane, + plane: &NcPlane, red: &mut Color, green: &mut Color, blue: &mut Color, @@ -635,7 +636,7 @@ pub fn ncplane_fg_rgb8( /// Extract 24 bits of background RGB from a plane, split into components. #[inline] pub fn ncplane_bg_rgb8( - plane: &Plane, + plane: &NcPlane, red: &mut Color, green: &mut Color, blue: &mut Color, @@ -646,7 +647,7 @@ pub fn ncplane_bg_rgb8( /// #[inline] pub fn ncplane_rounded_box( - plane: &mut Plane, + plane: &mut NcPlane, stylemask: StyleMask, channels: ChannelPair, ystop: i32, @@ -692,7 +693,7 @@ pub fn ncplane_rounded_box( /// #[inline] pub fn ncplane_rounded_box_sized( - plane: &mut Plane, + plane: &mut NcPlane, stylemask: StyleMask, channels: ChannelPair, ylen: i32, diff --git a/rust/src/types.rs b/rust/src/types.rs index 0ccd16c25..bb5654577 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -1,5 +1,10 @@ //! The notcurses types are defined and/or explained here //! +//! Existing types are wrapped to make them follow the Rust API Guidelines +//! and to enforce type check whenever possible +//! +//! See: [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/naming.html) + use crate as nc; /// RGB: 24 bits broken into 3x 8bpp channels. @@ -202,7 +207,7 @@ pub type StyleMask = u16; // - EGCPool // // type in C: ncplane (struct) -pub type Plane = nc::ncplane; +pub type NcPlane = nc::ncplane; // EGCPool: contiguous region chopped up into NUL-terminated UTF8 EGCs, one per plane // @@ -211,82 +216,80 @@ pub type Plane = nc::ncplane; // CellMatrix: rectilinear array of Cells // one -- fb per plane, and transients show up ? +/// Typle alias of palette256 +pub type Palette = nc::palette256; + /// 8-bit value used for indexing into a palette /// pub type PaletteIndex = u8; -pub type Palette = nc::palette256; /// 32-bit signed value used to return errors, when value < 0, (usually -1) /// pub type IntResult = i32; - /// Type alias of ncalign_e -pub type Align = nc::ncalign_e; -pub const ALIGN_LEFT: Align = nc::ncalign_e_NCALIGN_LEFT; -pub const ALIGN_RIGHT: Align = nc::ncalign_e_NCALIGN_RIGHT; -pub const ALIGN_CENTER: Align = nc::ncalign_e_NCALIGN_CENTER; - +pub type NcAlign = nc::ncalign_e; +pub const NCALIGN_LEFT: NcAlign = nc::ncalign_e_NCALIGN_LEFT; +pub const NCALIGN_RIGHT: NcAlign = nc::ncalign_e_NCALIGN_RIGHT; +pub const NCALIGN_CENTER: NcAlign = nc::ncalign_e_NCALIGN_CENTER; /// Type alias of ncblitter_e -pub type Blitter = nc::ncblitter_e; +pub type NcBlitter = nc::ncblitter_e; /// space, compatible with ASCII -pub const BLIT_1x1: Blitter = nc::ncblitter_e_NCBLIT_1x1; +pub const NCBLIT_1x1: NcBlitter = nc::ncblitter_e_NCBLIT_1x1; /// halves + 1x1 (space) /// ▄▀ -pub const BLIT_2x1: Blitter = nc::ncblitter_e_NCBLIT_2x1; +pub const NCBLIT_2x1: NcBlitter = nc::ncblitter_e_NCBLIT_2x1; /// quadrants + 2x1 /// ▗▐ ▖▀▟▌▙ -pub const BLIT_2x2: Blitter = nc::ncblitter_e_NCBLIT_2x2; +pub const NCBLIT_2x2: NcBlitter = nc::ncblitter_e_NCBLIT_2x2; /// sextants (NOT 2x2) /// 🬀🬁🬂🬃🬄🬅🬆🬇🬈🬉🬊🬋🬌🬍🬎🬏🬐🬑🬒🬓🬔🬕🬖🬗🬘🬙🬚🬛🬜🬝🬞🬟🬠🬡🬢🬣🬤🬥🬦🬧🬨🬩🬪🬫🬬🬭🬮🬯🬰🬱🬲🬳🬴🬵🬶🬷🬸🬹🬺🬻 -pub const BLIT_3x2: Blitter = nc::ncblitter_e_NCBLIT_3x2; +pub const NCBLIT_3x2: NcBlitter = nc::ncblitter_e_NCBLIT_3x2; /// four vertical levels /// █▆▄▂ -pub const BLIT_4x1: Blitter = nc::ncblitter_e_NCBLIT_4x1; +pub const NCBLIT_4x1: NcBlitter = nc::ncblitter_e_NCBLIT_4x1; /// eight vertical levels /// █▇▆▅▄▃▂▁ -pub const BLIT_8x1: Blitter = nc::ncblitter_e_NCBLIT_8x1; +pub const NCBLIT_8x1: NcBlitter = nc::ncblitter_e_NCBLIT_8x1; /// 4 rows, 2 cols (braille) /// ⡀⡄⡆⡇⢀⣀⣄⣆⣇⢠⣠⣤⣦⣧⢰⣰⣴⣶⣷⢸⣸⣼⣾⣿ -pub const BLIT_BRAILLE: Blitter = nc::ncblitter_e_NCBLIT_BRAILLE; +pub const NCBLIT_BRAILLE: NcBlitter = nc::ncblitter_e_NCBLIT_BRAILLE; /// the blitter is automatically chosen -pub const BLIT_DEFAULT: Blitter = nc::ncblitter_e_NCBLIT_DEFAULT; +pub const NCBLIT_DEFAULT: NcBlitter = nc::ncblitter_e_NCBLIT_DEFAULT; /// 6 rows, 1 col (RGB), spotty support among terminals -pub const BLIT_SIXEL: Blitter = nc::ncblitter_e_NCBLIT_SIXEL; - +pub const NCBLIT_SIXEL: NcBlitter = nc::ncblitter_e_NCBLIT_SIXEL; /// Type alias of ncscale_e pub type Scale = nc::ncscale_e; /// Maintain original size -pub const SCALE_NONE: Scale = nc::ncscale_e_NCSCALE_NONE; +pub const NCSCALE_NONE: Scale = nc::ncscale_e_NCSCALE_NONE; /// Maintain aspect ratio -pub const SCALE_SCALE: Scale = nc::ncscale_e_NCSCALE_SCALE; +pub const NCSCALE_SCALE: Scale = nc::ncscale_e_NCSCALE_SCALE; /// Throw away aspect ratio -pub const SCALE_STRETCH: Scale = nc::ncscale_e_NCSCALE_STRETCH; - +pub const NCSCALE_STRETCH: Scale = nc::ncscale_e_NCSCALE_STRETCH; /// Type alias of ncdirect (direct mode) -pub type DirectMode = nc::ncdirect; - +pub type NcDirect = nc::ncdirect; /// Type alias of -pub type DirectModeFlags = u64; +pub type NcDirectFlags = u64; /// Avoids placing the terminal into cbreak mode (disabling echo and line buffering) -pub const DIRECTMODE_INHIBIT_CBREAK: DirectModeFlags = nc::NCDIRECT_OPTION_INHIBIT_CBREAK as DirectModeFlags; +pub const NCDIRECT_INHIBIT_CBREAK: NcDirectFlags = + nc::NCDIRECT_OPTION_INHIBIT_CBREAK as NcDirectFlags; /// Avoids calling setlocale(LC_ALL, NULL). /// @@ -294,12 +297,11 @@ pub const DIRECTMODE_INHIBIT_CBREAK: DirectModeFlags = nc::NCDIRECT_OPTION_INHIB /// and then call setlocale(LC_ALL, ""). This will attempt to set the locale based /// off the LANG environment variable. Your program should call setlocale(3) itself, /// usually as one of the first lines. -pub const DIRECTMODE_INHIBIT_SETLOCALE: DirectModeFlags = nc::NCDIRECT_OPTION_INHIBIT_SETLOCALE as DirectModeFlags; - +pub const NCDIRECT_INHIBIT_SETLOCALE: NcDirectFlags = + nc::NCDIRECT_OPTION_INHIBIT_SETLOCALE as NcDirectFlags; /// Type alias of notcurses (full mode) -pub type FullMode = nc::notcurses; - +pub type Notcurses = nc::bindings::notcurses; /// Type alias of ncinput pub type Input = nc::ncinput; diff --git a/rust/src/visual.rs b/rust/src/visual.rs index 24fd2ae3d..fbdf0ed06 100644 --- a/rust/src/visual.rs +++ b/rust/src/visual.rs @@ -26,21 +26,21 @@ // ncvisual_default_blitter use crate as nc; -use nc::types::{BLIT_1x1, BLIT_2x1, BLIT_2x2, Blitter, Scale, SCALE_STRETCH}; +use nc::types::{NCBLIT_1x1, NCBLIT_2x1, NCBLIT_2x2, NcBlitter, Scale, NCSCALE_STRETCH}; /// Returns the best default blitter available /// /// NCBLIT_3x2 is better image quality, especially for large images, but /// it's not the general default because it doesn't preserve aspect ratio. /// NCSCALE_STRETCH throws away aspect ratio, and can safely use NCBLIT_3x2. -pub fn ncvisual_default_blitter(utf8: bool, scale: Scale) -> Blitter { +pub fn ncvisual_default_blitter(utf8: bool, scale: Scale) -> NcBlitter { if utf8 { - if scale == SCALE_STRETCH { - return BLIT_2x2; + if scale == NCSCALE_STRETCH { + return NCBLIT_2x2; } - return BLIT_2x1; + return NCBLIT_2x1; } - BLIT_1x1 + NCBLIT_1x1 } #[cfg(test)]