diff --git a/python/README.md b/python/README.md index 00b2c5524..70c51f627 100644 --- a/python/README.md +++ b/python/README.md @@ -1,6 +1,6 @@ # notcurses -Python bindings for the C [https://github.com/dankamongmen/notcurses Notcurses] +Python bindings for the C [Notcurses](https://github.com/dankamongmen/notcurses) library. Notcurses is a blingful library for building complex, vibrant textual user interfaces (TUIs) on modern terminal emulators, of which these Python bindings offer nowhere near complete coverage. diff --git a/rust/examples/direct-image.rs b/rust/examples/direct-image.rs index ea5da8e08..5ed1fb17a 100644 --- a/rust/examples/direct-image.rs +++ b/rust/examples/direct-image.rs @@ -6,22 +6,22 @@ fn main() { unsafe { let ncd = nc::ncdirect_new(); - render_image(&mut *ncd, nc::ncblitter_e_NCBLIT_1x1); - render_image(&mut *ncd, nc::ncblitter_e_NCBLIT_2x1); - render_image(&mut *ncd, nc::ncblitter_e_NCBLIT_BRAILLE); + render_image(&mut *ncd, nc::NCBLIT_1x1); + render_image(&mut *ncd, nc::NCBLIT_2x1); + render_image(&mut *ncd, nc::NCBLIT_BRAILLE); nc::ncdirect_stop(ncd); } } -fn render_image(ncd: &mut nc::ncdirect, blit: nc::ncblitter_e) { +fn render_image(ncd: &mut nc::NcDirect, blit: nc::NcBlitter) { unsafe { if nc::ncdirect_render_image( ncd, CString::new("image-16x16.png").unwrap().as_ptr(), - nc::ncalign_e_NCALIGN_CENTER, + nc::NCALIGN_CENTER, blit, - nc::ncscale_e_NCSCALE_NONE, + nc::NCSCALE_NONE, ) != 0 { panic!("ERR: ncdirect_render_image. \ diff --git a/rust/src/bindings.rs b/rust/src/bindings.rs index f7d8a2bcd..f90b7e7b5 100644 --- a/rust/src/bindings.rs +++ b/rust/src/bindings.rs @@ -1,6 +1,7 @@ -//! Curated re-exports of the bindgen generated bindings, +//! Curated re-exports of the `bindgen` bindings //! -//! The full list of bindings is under the bindgen submodule +//! The full list of bindings is under the +//! [`bindgen`](../bindgen/index.html) submodule //! // // WARNING: DO NOT EXECUTE RUSTFMT ON THIS FILE. @@ -10,57 +11,43 @@ // [clippy & bindgen](https://github.com/rust-lang/rust-bindgen/issues/1470) #[allow(clippy::all)] pub mod bindgen { + //! Automatically generated Rust FFI bindings + //! + //! All of the notcurses functions and some of the constants are reexported + //! by the [`bindings`](../bindings/index.html) module. + //! While the structs, enums and some other constants are type aliased in + //! the [`types`](../types/index.html) module, in order to follow the + //! Rust API Guidelines as much as possible. + //! include!(concat!(env!("OUT_DIR"), "/bindings.rs")); } // Miscellaneous --------------------------------------------------------------- + #[doc(inline)] pub use bindgen::{ // structs _IO_FILE, __va_list_tag, - - // functions timespec, }; -// align ----------------------------------------------------------------------- -#[doc(inline)] -pub use bindgen::{ - // type definitions - ncalign_e, +// blitset --------------------------------------------------------------------- - // constants - ncalign_e_NCALIGN_CENTER, - ncalign_e_NCALIGN_LEFT, - ncalign_e_NCALIGN_RIGHT, - ncalign_e_NCALIGN_UNALIGNED, -}; - -// ncblit --------------------------------------------------------------------- -#[doc(inline)] -pub use bindgen::{ - // type definitions - ncblitter_e, - - // constants - ncblitter_e_NCBLIT_1x1, - ncblitter_e_NCBLIT_2x1, - ncblitter_e_NCBLIT_2x2, - ncblitter_e_NCBLIT_3x2, - ncblitter_e_NCBLIT_4x1, - ncblitter_e_NCBLIT_8x1, - ncblitter_e_NCBLIT_BRAILLE, - ncblitter_e_NCBLIT_DEFAULT, - ncblitter_e_NCBLIT_SIXEL, +pub(crate) use bindgen::{ + // structs + blitset }; // cell ------------------------------------------------------------------------ -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ // structs cell, +}; +#[doc(inline)] +pub use bindgen::{ // functions cell_duplicate, cell_extended_gcluster, @@ -87,13 +74,46 @@ pub use bindgen::{ }; // channel --------------------------------------------------------------------- + #[doc(inline)] pub use bindgen::{ // constants CHANNEL_ALPHA_MASK }; +// ncalign --------------------------------------------------------------------- + +pub(crate) use bindgen::{ + // type definitions + ncalign_e, + + // constants + ncalign_e_NCALIGN_CENTER, + ncalign_e_NCALIGN_LEFT, + ncalign_e_NCALIGN_RIGHT, + ncalign_e_NCALIGN_UNALIGNED, +}; + +// ncblitter ------------------------------------------------------------------- + +pub(crate) use bindgen::{ + // type definitions + ncblitter_e, + + // constants + ncblitter_e_NCBLIT_1x1, + ncblitter_e_NCBLIT_2x1, + ncblitter_e_NCBLIT_2x2, + ncblitter_e_NCBLIT_3x2, + ncblitter_e_NCBLIT_4x1, + ncblitter_e_NCBLIT_8x1, + ncblitter_e_NCBLIT_BRAILLE, + ncblitter_e_NCBLIT_DEFAULT, + ncblitter_e_NCBLIT_SIXEL, +}; + // ncbox ----------------------------------------------------------------------- + #[doc(inline)] pub use bindgen::{ // constants @@ -110,11 +130,14 @@ pub use bindgen::{ }; // ncdirect -------------------------------------------------------------------- -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ // structs ncdirect, +}; +#[doc(inline)] +pub use bindgen::{ // functions ncdirect_bg_default, ncdirect_bg_palindex, @@ -162,11 +185,14 @@ pub use bindgen::{ // ncfadectx ------------------------------------------------------------------- -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ // structs ncfadectx, +}; +#[doc(inline)] +pub use bindgen::{ // functions ncfadectx_free, ncfadectx_iterations, @@ -174,15 +200,15 @@ pub use bindgen::{ }; // ncinput --------------------------------------------------------------------- -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ // structs ncinput, }; // ncloglevel ------------------------------------------------------------------ -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ // type definitions ncloglevel_e, @@ -199,12 +225,15 @@ pub use bindgen::{ }; // ncfdplane ------------------------------------------------------------------- -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ // structs ncfdplane, ncfdplane_options, +}; +#[doc(inline)] +pub use bindgen::{ // functions ncfdplane_create, ncfdplane_destroy, @@ -212,13 +241,17 @@ pub use bindgen::{ }; // ncmenu ---------------------------------------------------------------------- -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ + // structs ncmenu, ncmenu_item, ncmenu_options, ncmenu_section, +}; +#[doc(inline)] +pub use bindgen::{ // functions ncmenu_create, ncmenu_destroy, @@ -239,21 +272,25 @@ pub use bindgen::{ NCMENU_OPTION_HIDING, }; -// ncmetric +// ncmetric -------------------------------------------------------------------- + #[doc(inline)] pub use bindgen::{ // structs ncmetric }; -// ncmultiselector -#[doc(inline)] -pub use bindgen::{ +// ncmultiselector ------------------------------------------------------------- + +pub(crate) use bindgen::{ // structs ncmultiselector, ncmselector_item, ncmultiselector_options, +}; +#[doc(inline)] +pub use bindgen::{ // functions ncmultiselector_create, ncmultiselector_destroy, @@ -262,11 +299,15 @@ pub use bindgen::{ ncmultiselector_selected, }; -// ncplane +// ncplane --------------------------------------------------------------------- + +pub(crate) use bindgen::{ + // structs + ncplane, +}; + #[doc(inline)] pub use bindgen::{ - ncplane, - // functions ncplane_above, ncplane_at_cursor, @@ -370,14 +411,17 @@ pub use bindgen::{ NCPLANE_OPTION_HORALIGNED, }; -// ncplot -#[doc(inline)] -pub use bindgen::{ +// ncplot ---------------------------------------------------------------------- + +pub(crate) use bindgen::{ // structs ncdplot, // f64 ncuplot, // u64 ncplot_options, +}; +#[doc(inline)] +pub use bindgen::{ // functions ncdplot_add_sample, ncdplot_create, @@ -401,12 +445,16 @@ pub use bindgen::{ NCPLOT_OPTION_VERTICALI, }; -// ncreader -#[doc(inline)] -pub use bindgen::{ +// ncreader -------------------------------------------------------------------- + +pub(crate) use bindgen::{ + // structs ncreader, ncreader_options, +}; +#[doc(inline)] +pub use bindgen::{ // functions ncreader_clear, ncreader_contents, @@ -427,12 +475,16 @@ pub use bindgen::{ NCREADER_OPTION_VERSCROLL, }; -// ncreel -#[doc(inline)] -pub use bindgen::{ +// ncreel ---------------------------------------------------------------------- + +pub(crate) use bindgen::{ + // structs ncreel, ncreel_options, +}; +#[doc(inline)] +pub use bindgen::{ // functions ncreel_add, ncreel_create, @@ -451,9 +503,9 @@ pub use bindgen::{ NCREEL_OPTION_INFINITESCROLL, }; -// ncscale -#[doc(inline)] -pub use bindgen::{ +// ncscale --------------------------------------------------------------------- + +pub(crate) use bindgen::{ // type definitions ncscale_e, @@ -464,13 +516,16 @@ pub use bindgen::{ }; // ncselector ------------------------------------------------------------------ -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ // structs ncselector, ncselector_item, ncselector_options, +}; +#[doc(inline)] +pub use bindgen::{ // functions ncselector_additem, ncselector_create, @@ -484,13 +539,14 @@ pub use bindgen::{ }; // ncstats --------------------------------------------------------------------- -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ // structs ncstats, }; // ncstyle --------------------------------------------------------------------- + #[doc(inline)] pub use bindgen::{ // constants @@ -508,11 +564,14 @@ pub use bindgen::{ }; // nctablet -------------------------------------------------------------------- -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ // structs nctablet, +}; +#[doc(inline)] +pub use bindgen::{ // functions nctablet_ncplane, nctablet_plane, @@ -520,12 +579,15 @@ pub use bindgen::{ }; // ncvisual -------------------------------------------------------------------- -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ // structs ncvisual, ncvisual_options, +}; +#[doc(inline)] +pub use bindgen::{ // functions ncvisual_at_yx, ncvisual_decode, @@ -547,12 +609,15 @@ pub use bindgen::{ }; // notcurses ------------------------------------------------------------------- -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ // structs notcurses, notcurses_options, +}; +#[doc(inline)] +pub use bindgen::{ // functions notcurses_at_yx, notcurses_bottom, @@ -605,11 +670,14 @@ pub use bindgen::{ }; // palette --------------------------------------------------------------------- -#[doc(inline)] -pub use bindgen::{ + +pub(crate) use bindgen::{ // structs palette256, +}; +#[doc(inline)] +pub use bindgen::{ // functions palette256_free, palette256_new, @@ -620,13 +688,14 @@ pub use bindgen::{ }; // sig ------------------------------------------------------------------------- + #[doc(inline)] pub use bindgen::{ // type definitions sigset_t, // structs - sigaction, + //sigaction, // functions sigaddset, diff --git a/rust/src/cells.rs b/rust/src/cells.rs index 38cd15c5f..90197a9e4 100644 --- a/rust/src/cells.rs +++ b/rust/src/cells.rs @@ -58,10 +58,19 @@ use libc::strcmp; -use crate as nc; -use nc::types::{ - AlphaBits, Cell, CellGcluster, Channel, ChannelPair, Color, IntResult, NcPlane, PaletteIndex, - StyleMask, EGC, +use crate::{ + cell_extended_gcluster, cell_load, cell_release, channels_bchannel, channels_bg_alpha, + channels_bg_default_p, channels_bg_palindex_p, channels_bg_rgb, channels_bg_rgb8, + channels_fchannel, channels_fg_alpha, channels_fg_default_p, channels_fg_palindex_p, + channels_fg_rgb, channels_fg_rgb8, channels_set_bchannel, channels_set_bg_alpha, + channels_set_bg_default, channels_set_bg_rgb, channels_set_bg_rgb8, channels_set_fchannel, + channels_set_fg_alpha, channels_set_fg_default, channels_set_fg_rgb, channels_set_fg_rgb8, + types::{ + AlphaBits, Cell, CellGcluster, Channel, Channels, Color, Egc, IntResult, NcPlane, + PaletteIndex, StyleMask, + }, + CELL_ALPHA_OPAQUE, CELL_BGDEFAULT_MASK, CELL_BG_PALETTE, CELL_FGDEFAULT_MASK, CELL_FG_PALETTE, + CELL_NOBACKGROUND_MASK, CELL_WIDEASIAN_MASK, NCSTYLE_MASK, }; /// cell_load(), plus blast the styling with 'style' and 'channels'. @@ -77,23 +86,23 @@ use nc::types::{ /// #[allow(unused_unsafe)] pub unsafe fn cell_prime( - plane: &mut nc::ncplane, - cell: &mut nc::cell, - gcluster: EGC, + plane: &mut NcPlane, + cell: &mut Cell, + gcluster: Egc, style: StyleMask, - channels: ChannelPair, + channels: Channels, ) -> IntResult { cell.stylemask = style; cell.channels = channels; - unsafe { nc::cell_load(plane, cell, gcluster as u32 as *const i8) } + unsafe { cell_load(plane, cell, gcluster as u32 as *const i8) } } -/// load up six cells with the EGCs necessary to draw a box. +/// load up six cells with the [Egc](type.Egc.html)s necessary to draw a box. /// /// returns 0 on success, -1 on error. /// /// on error, any cells this function might have loaded before the error -/// are cell_release()d. There must be at least six EGCs in gcluster. +/// are cell_release()d. There must be at least six `Egc`s in gcluster. /// /// # Safety /// @@ -103,14 +112,14 @@ pub unsafe fn cell_prime( pub unsafe fn cells_load_box( plane: &mut NcPlane, style: StyleMask, - channels: ChannelPair, + channels: Channels, ul: &mut Cell, ur: &mut Cell, ll: &mut Cell, lr: &mut Cell, hl: &mut Cell, vl: &mut Cell, - gcluster: EGC, + gcluster: Egc, ) -> IntResult { // mutable copy for pointer arithmetics: let mut gclu = gcluster as u32 as *const i8; @@ -143,23 +152,23 @@ pub unsafe fn cells_load_box( return 0; } unsafe { - nc::cell_release(plane, hl); + cell_release(plane, hl); } } unsafe { - nc::cell_release(plane, lr); + cell_release(plane, lr); } } unsafe { - nc::cell_release(plane, ll); + cell_release(plane, ll); } } unsafe { - nc::cell_release(plane, ur); + cell_release(plane, ur); } } unsafe { - nc::cell_release(plane, ul); + cell_release(plane, ul); } } -1 @@ -176,7 +185,7 @@ pub fn cell_init(cell: &mut Cell) { /// static inline void #[inline] pub fn cell_styles_set(cell: &mut Cell, stylebits: StyleMask) { - cell.stylemask = stylebits & nc::NCSTYLE_MASK as u16; + cell.stylemask = stylebits & NCSTYLE_MASK as u16; } /// Extract the style bits from the cell. @@ -189,44 +198,44 @@ pub fn cell_styles(cell: &Cell) -> StyleMask { /// they're actively supported or not. #[inline] pub fn cell_styles_on(cell: &mut Cell, stylebits: StyleMask) { - cell.stylemask |= stylebits & nc::NCSTYLE_MASK as u16; + cell.stylemask |= stylebits & NCSTYLE_MASK as u16; } /// Remove the specified styles (in the LSBs) from the cell's existing spec. #[inline] pub fn cell_styles_off(cell: &mut Cell, stylebits: StyleMask) { - cell.stylemask &= !(stylebits & nc::NCSTYLE_MASK as u16); + cell.stylemask &= !(stylebits & NCSTYLE_MASK as u16); } /// Use the default color for the foreground. #[inline] pub fn cell_set_fg_default(cell: &mut Cell) { - nc::channels_set_fg_default(&mut cell.channels); + channels_set_fg_default(&mut cell.channels); } /// Use the default color for the background. #[inline] pub fn cell_set_bg_default(cell: &mut Cell) { - nc::channels_set_bg_default(&mut cell.channels); + channels_set_bg_default(&mut cell.channels); } /// Set the foreground alpha. #[inline] pub fn cell_set_fg_alpha(cell: &mut Cell, alpha: AlphaBits) { - nc::channels_set_fg_alpha(&mut cell.channels, alpha); + channels_set_fg_alpha(&mut cell.channels, alpha); } /// Set the background alpha. #[inline] pub fn cell_set_bg_alpha(cell: &mut Cell, alpha: AlphaBits) { - nc::channels_set_bg_alpha(&mut cell.channels, alpha); + channels_set_bg_alpha(&mut cell.channels, alpha); } /// Does the cell contain an East Asian Wide codepoint? // NOTE: remove casting when fixed: https://github.com/rust-lang/rust-bindgen/issues/1875 #[inline] pub fn cell_double_wide_p(cell: &Cell) -> bool { - (cell.channels & nc::CELL_WIDEASIAN_MASK as u64) != 0 + (cell.channels & CELL_WIDEASIAN_MASK as u64) != 0 } /// Is this the right half of a wide character? @@ -241,18 +250,16 @@ pub fn cell_wide_left_p(cell: &Cell) -> bool { cell_double_wide_p(cell) && cell.gcluster != 0 } -/// copy the UTF8-encoded EGC out of the cell, whether simple or complex. the +/// 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: &NcPlane, cell: &Cell) -> EGC { - core::char::from_u32( - unsafe { libc::strdup(nc::cell_extended_gcluster(plane, cell)) } as i32 as u32, - ) - .expect("wrong char") +pub fn cell_strdup(plane: &NcPlane, cell: &Cell) -> Egc { + core::char::from_u32(unsafe { libc::strdup(cell_extended_gcluster(plane, cell)) } as i32 as u32) + .expect("wrong char") // unsafer option B (maybe faster, TODO: bench) // unsafe { - // core::char::from_u32_unchecked(libc::strdup(nc::cell_extended_gcluster(plane, cell)) as i32 as u32) + // core::char::from_u32_unchecked(libc::strdup(cell_extended_gcluster(plane, cell)) as i32 as u32) // } } @@ -262,8 +269,8 @@ pub fn cell_extract( plane: &NcPlane, cell: &Cell, stylemask: &mut StyleMask, - channels: &mut ChannelPair, -) -> EGC { + channels: &mut Channels, +) -> Egc { if *stylemask != 0 { *stylemask = cell.stylemask; } @@ -273,9 +280,9 @@ pub fn cell_extract( cell_strdup(plane, cell) } -/// Returns true if the two cells are distinct EGCs, attributes, or channels. +/// Returns true if the two cells are distinct `Egc`s, attributes, or channels. /// The actual egcpool index needn't be the same--indeed, the planes needn't even -/// be the same. Only the expanded EGC must be equal. The EGC must be bit-equal; +/// 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: &NcPlane, cell1: &Cell, plane2: &NcPlane, cell2: &Cell) -> bool { @@ -287,8 +294,8 @@ pub fn cellcmp(plane1: &NcPlane, cell1: &Cell, plane2: &NcPlane, cell2: &Cell) - } unsafe { strcmp( - nc::cell_extended_gcluster(plane1, cell1), - nc::cell_extended_gcluster(plane2, cell2), + cell_extended_gcluster(plane1, cell1), + cell_extended_gcluster(plane2, cell2), ) != 0 } } @@ -296,11 +303,11 @@ pub fn cellcmp(plane1: &NcPlane, cell1: &Cell, plane2: &NcPlane, cell2: &Cell) - /// // 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 NcPlane, 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); + cell_release(plane, cell); } - cell.channels &= !(nc::CELL_WIDEASIAN_MASK as u64 | nc::CELL_NOBACKGROUND_MASK); + cell.channels &= !(CELL_WIDEASIAN_MASK as u64 | CELL_NOBACKGROUND_MASK); cell.gcluster = ch as CellGcluster; 1 } @@ -308,74 +315,74 @@ pub fn cell_load_simple(plane: &mut NcPlane, cell: &mut Cell, ch: EGC) -> i32 { /// Extract the 32-bit background channel from a cell. #[inline] pub fn cell_bchannel(cell: &Cell) -> Channel { - nc::channels_bchannel(cell.channels) + channels_bchannel(cell.channels) } /// Extract the 32-bit foreground channel from a cell. #[inline] pub fn cell_fchannel(cell: &Cell) -> Channel { - nc::channels_fchannel(cell.channels) + channels_fchannel(cell.channels) } /// Set the 32-bit background channel of a cell. #[inline] -pub fn cell_set_bchannel(cell: &mut Cell, channel: Channel) -> ChannelPair { - nc::channels_set_bchannel(&mut cell.channels, channel) +pub fn cell_set_bchannel(cell: &mut Cell, channel: Channel) -> Channels { + channels_set_bchannel(&mut cell.channels, channel) } /// Set the 32-bit foreground channel of a cell. #[inline] -pub fn cell_set_fchannel(cell: &mut Cell, channel: Channel) -> ChannelPair { - nc::channels_set_fchannel(&mut cell.channels, channel) +pub fn cell_set_fchannel(cell: &mut Cell, channel: Channel) -> Channels { + channels_set_fchannel(&mut cell.channels, channel) } /// Extract 24 bits of foreground RGB from 'cell', shifted to LSBs. #[inline] pub fn cell_fg_rgb(cell: &Cell) -> Channel { - nc::channels_fg_rgb(cell.channels) + channels_fg_rgb(cell.channels) } /// Extract 24 bits of background RGB from 'cell', shifted to LSBs. #[inline] pub fn cell_bg_rgb(cell: &Cell) -> Channel { - nc::channels_bg_rgb(cell.channels) + channels_bg_rgb(cell.channels) } /// Extract 2 bits of foreground alpha from 'cell', shifted to LSBs. #[inline] pub fn cell_fg_alpha(cell: &Cell) -> AlphaBits { - nc::channels_fg_alpha(cell.channels) + channels_fg_alpha(cell.channels) } /// Extract 2 bits of background alpha from 'cell', shifted to LSBs. #[inline] pub fn cell_bg_alpha(cell: &Cell) -> AlphaBits { - nc::channels_bg_alpha(cell.channels) + channels_bg_alpha(cell.channels) } /// Extract 24 bits of foreground RGB from 'cell', split into components. #[inline] pub fn cell_fg_rgb8(cell: &Cell, red: &mut Color, green: &mut Color, blue: &mut Color) -> Channel { - nc::channels_fg_rgb8(cell.channels, red, green, blue) + channels_fg_rgb8(cell.channels, red, green, blue) } /// Extract 24 bits of background RGB from 'cell', split into components. #[inline] pub fn cell_bg_rgb8(cell: &Cell, red: &mut Color, green: &mut Color, blue: &mut Color) -> Channel { - nc::channels_bg_rgb8(cell.channels, red, green, blue) + channels_bg_rgb8(cell.channels, red, green, blue) } /// Set the r, g, and b cell for the foreground component of this 64-bit /// 'cell' variable, and mark it as not using the default color. #[inline] pub fn cell_set_fg_rgb8(cell: &mut Cell, red: Color, green: Color, blue: Color) { - nc::channels_set_fg_rgb8(&mut cell.channels, red, green, blue); + channels_set_fg_rgb8(&mut cell.channels, red, green, blue); } /// Same as `cell_set_fg_rgb8()` but with an assembled 24-bit RGB value. #[inline] pub fn cell_set_fg_rgb(cell: &mut Cell, channel: Channel) { - nc::channels_set_fg_rgb(&mut cell.channels, channel); + channels_set_fg_rgb(&mut cell.channels, channel); } /// Set the cell's foreground palette index, set the foreground palette index @@ -384,9 +391,9 @@ pub fn cell_set_fg_rgb(cell: &mut Cell, channel: Channel) { // NOTE: this function now can't fail #[inline] pub fn cell_set_fg_palindex(cell: &mut Cell, index: PaletteIndex) { - cell.channels |= nc::CELL_FGDEFAULT_MASK; - cell.channels |= nc::CELL_FG_PALETTE; - cell_set_fg_alpha(cell, nc::CELL_ALPHA_OPAQUE); + cell.channels |= CELL_FGDEFAULT_MASK; + cell.channels |= CELL_FG_PALETTE; + cell_set_fg_alpha(cell, CELL_ALPHA_OPAQUE); cell.channels &= 0xff000000ffffffff_u64; cell.channels |= (index as u64) << 32; } @@ -402,14 +409,14 @@ pub fn cell_fg_palindex(cell: &Cell) -> PaletteIndex { /// #[inline] pub fn cell_set_bg_rgb8(cell: &mut Cell, red: Color, green: Color, blue: Color) { - nc::channels_set_bg_rgb8(&mut cell.channels, red, green, blue); + channels_set_bg_rgb8(&mut cell.channels, red, green, blue); } /// Same as `cell_set_fg_rgb8()` but with an assembled 24-bit RGB value. /// #[inline] pub fn cell_set_bg_rgb(cell: &mut Cell, channel: Channel) { - nc::channels_set_bg_rgb(&mut cell.channels, channel); + channels_set_bg_rgb(&mut cell.channels, channel); } /// Set the cell's background palette index, set the background palette index @@ -418,9 +425,9 @@ pub fn cell_set_bg_rgb(cell: &mut Cell, channel: Channel) { // NOTE: this function now can't fail #[inline] pub fn cell_set_bg_palindex(cell: &mut Cell, index: PaletteIndex) { - cell.channels |= nc::CELL_BGDEFAULT_MASK as u64; - cell.channels |= nc::CELL_BG_PALETTE as u64; - cell_set_bg_alpha(cell, nc::CELL_ALPHA_OPAQUE); + cell.channels |= CELL_BGDEFAULT_MASK as u64; + cell.channels |= CELL_BG_PALETTE as u64; + cell_set_bg_alpha(cell, CELL_ALPHA_OPAQUE); cell.channels &= 0xffffffffff000000; cell.channels |= index as u64; } @@ -434,13 +441,13 @@ pub fn cell_bg_palindex(cell: &Cell) -> PaletteIndex { /// Is the foreground using the "default foreground color"? #[inline] pub fn cell_fg_default_p(cell: &Cell) -> bool { - nc::channels_fg_default_p(cell.channels) + channels_fg_default_p(cell.channels) } /// #[inline] pub fn cell_fg_palindex_p(cell: &Cell) -> bool { - nc::channels_fg_palindex_p(cell.channels) + channels_fg_palindex_p(cell.channels) } /// Is the background using the "default background color"? The "default @@ -448,13 +455,13 @@ pub fn cell_fg_palindex_p(cell: &Cell) -> bool { /// terminal-effected transparency. #[inline] pub fn cell_bg_default_p(cell: &Cell) -> bool { - nc::channels_bg_default_p(cell.channels) + channels_bg_default_p(cell.channels) } /// #[inline] pub fn cell_bg_palindex_p(cell: &Cell) -> bool { - nc::channels_bg_palindex_p(cell.channels) + channels_bg_palindex_p(cell.channels) } #[cfg(test)] diff --git a/rust/src/channel.rs b/rust/src/channel.rs index dc3d03580..0ee40e22a 100644 --- a/rust/src/channel.rs +++ b/rust/src/channel.rs @@ -60,9 +60,11 @@ //+ channels_set_fg_rgb8 //X channels_set_fg_rgb8_clipped -use crate as nc; - -use nc::types::{AlphaBits, Channel, ChannelPair, Color, Rgb}; +use crate::{ + types::{AlphaBits, Channel, Channels, Color, Rgb}, + CELL_ALPHA_HIGHCONTRAST, CELL_ALPHA_OPAQUE, CELL_BGDEFAULT_MASK, CELL_BG_PALETTE, + CELL_BG_RGB_MASK, CHANNEL_ALPHA_MASK, +}; /// Extract the 8-bit red component from a 32-bit channel. #[inline] @@ -96,82 +98,82 @@ pub fn channel_rgb8(channel: Channel, r: &mut Color, g: &mut Color, b: &mut Colo #[inline] pub fn channel_set_rgb8(channel: &mut Channel, r: Color, g: Color, b: Color) { let rgb: Rgb = (r as Channel) << 16 | (g as Channel) << 8 | (b as Channel); - *channel = (*channel & !nc::CELL_BG_RGB_MASK) | nc::CELL_BGDEFAULT_MASK | rgb; + *channel = (*channel & !CELL_BG_RGB_MASK) | CELL_BGDEFAULT_MASK | rgb; } /// Same as channel_set_rgb8(), but provide an assembled, packed 24 bits of rgb. #[inline] pub fn channel_set(channel: &mut Channel, rgb: Rgb) { - *channel = (*channel & !nc::CELL_BG_RGB_MASK) | nc::CELL_BGDEFAULT_MASK | (rgb & 0x00ffffff); + *channel = (*channel & !CELL_BG_RGB_MASK) | CELL_BGDEFAULT_MASK | (rgb & 0x00ffffff); } /// Extract the 2-bit alpha component from a 32-bit channel. #[inline] pub fn channel_alpha(channel: Channel) -> AlphaBits { - channel & nc::CHANNEL_ALPHA_MASK + channel & CHANNEL_ALPHA_MASK } /// Set the 2-bit alpha component of the 32-bit channel. #[inline] pub fn channel_set_alpha(channel: &mut Channel, alpha: AlphaBits) { - let alpha_clean = alpha & nc::CHANNEL_ALPHA_MASK; - *channel = alpha_clean | (*channel & !nc::CHANNEL_ALPHA_MASK); + let alpha_clean = alpha & CHANNEL_ALPHA_MASK; + *channel = alpha_clean | (*channel & !CHANNEL_ALPHA_MASK); - if alpha != nc::CELL_ALPHA_OPAQUE { + if alpha != CELL_ALPHA_OPAQUE { // indicate that we are *not* using the default background color - *channel |= nc::CELL_BGDEFAULT_MASK; + *channel |= CELL_BGDEFAULT_MASK; } } /// Is this channel using the "default color" rather than RGB/palette-indexed? #[inline] pub fn channel_default_p(channel: Channel) -> bool { - (channel & nc::CELL_BGDEFAULT_MASK) == 0 + (channel & CELL_BGDEFAULT_MASK) == 0 } /// Is this channel using palette-indexed color rather than RGB? #[inline] pub fn channel_palindex_p(channel: Channel) -> bool { - !channel_default_p(channel) && (channel & nc::CELL_BG_PALETTE) == 0 + !channel_default_p(channel) && (channel & CELL_BG_PALETTE) == 0 } /// Mark the channel as using its default color, which also marks it opaque. #[inline] pub fn channel_set_default(channel: &mut Channel) -> Channel { - *channel &= !(nc::CELL_BGDEFAULT_MASK | nc::CELL_ALPHA_HIGHCONTRAST); // < NOTE shouldn't be better CHANNEL_ALPHA_MASK? + *channel &= !(CELL_BGDEFAULT_MASK | CELL_ALPHA_HIGHCONTRAST); // < NOTE shouldn't be better CHANNEL_ALPHA_MASK? *channel } /// Extract the 32-bit background channel from a channel pair. #[inline] -pub fn channels_bchannel(channels: ChannelPair) -> Channel { +pub fn channels_bchannel(channels: Channels) -> Channel { (channels & 0xffffffff_u64) as Channel } /// Extract the 32-bit foreground channel from a channel pair. #[inline] -pub fn channels_fchannel(channels: ChannelPair) -> Channel { +pub fn channels_fchannel(channels: Channels) -> Channel { channels_bchannel(channels >> 32) } /// Set the 32-bit background channel of a channel pair. #[inline] -pub fn channels_set_bchannel(channels: &mut ChannelPair, bchannel: Channel) -> ChannelPair { +pub fn channels_set_bchannel(channels: &mut Channels, bchannel: Channel) -> Channels { *channels = (*channels & 0xffffffff00000000_u64) | bchannel as u64; *channels } /// Set the 32-bit foreground channel of a channel pair. #[inline] -pub fn channels_set_fchannel(channels: &mut ChannelPair, fchannel: Channel) -> ChannelPair { +pub fn channels_set_fchannel(channels: &mut Channels, fchannel: Channel) -> Channels { *channels = (*channels & 0xffffffff_u64) | (fchannel as u64) << 32; *channels } /// Combine two channels into a channel pair. #[inline] -pub fn channels_combine(fchannel: Channel, bchannel: Channel) -> ChannelPair { - let mut channels: ChannelPair = 0; +pub fn channels_combine(fchannel: Channel, bchannel: Channel) -> Channels { + let mut channels: Channels = 0; channels_set_fchannel(&mut channels, fchannel); channels_set_bchannel(&mut channels, bchannel); channels @@ -179,32 +181,32 @@ pub fn channels_combine(fchannel: Channel, bchannel: Channel) -> ChannelPair { /// Extract 24 bits of foreground RGB from 'channels', shifted to LSBs. #[inline] -pub fn channels_fg_rgb(channels: ChannelPair) -> Channel { - channels_fchannel(channels) & nc::CELL_BG_RGB_MASK +pub fn channels_fg_rgb(channels: Channels) -> Channel { + channels_fchannel(channels) & CELL_BG_RGB_MASK } /// Extract 24 bits of background RGB from 'channels', shifted to LSBs. #[inline] -pub fn channels_bg_rgb(channels: ChannelPair) -> Channel { - channels_bchannel(channels) & nc::CELL_BG_RGB_MASK +pub fn channels_bg_rgb(channels: Channels) -> Channel { + channels_bchannel(channels) & CELL_BG_RGB_MASK } /// Extract 2 bits of foreground alpha from 'channels', shifted to LSBs. #[inline] -pub fn channels_fg_alpha(channels: ChannelPair) -> AlphaBits { +pub fn channels_fg_alpha(channels: Channels) -> AlphaBits { channel_alpha(channels_fchannel(channels)) } /// Extract 2 bits of background alpha from 'channels', shifted to LSBs. #[inline] -pub fn channels_bg_alpha(channels: ChannelPair) -> AlphaBits { +pub fn channels_bg_alpha(channels: Channels) -> AlphaBits { channel_alpha(channels_bchannel(channels)) } /// Extract 24 bits of foreground RGB from 'channels', split into subchannels. #[inline] pub fn channels_fg_rgb8( - channels: ChannelPair, + channels: Channels, r: &mut Color, g: &mut Color, b: &mut Color, @@ -215,7 +217,7 @@ pub fn channels_fg_rgb8( /// Extract 24 bits of background RGB from 'channels', split into subchannels. #[inline] pub fn channels_bg_rgb8( - channels: ChannelPair, + channels: Channels, r: &mut Color, g: &mut Color, b: &mut Color, @@ -226,7 +228,7 @@ pub fn channels_bg_rgb8( /// Set the r, g, and b channels for the foreground component of this 64-bit /// 'channels' variable, and mark it as not using the default color. #[inline] -pub fn channels_set_fg_rgb8(channels: &mut ChannelPair, r: Color, g: Color, b: Color) { +pub fn channels_set_fg_rgb8(channels: &mut Channels, r: Color, g: Color, b: Color) { let mut channel = channels_fchannel(*channels); channel_set_rgb8(&mut channel, r, g, b); *channels = (channel as u64) << 32 | *channels & 0xffffffff_u64; @@ -234,7 +236,7 @@ pub fn channels_set_fg_rgb8(channels: &mut ChannelPair, r: Color, g: Color, b: C /// Same as channels_set_fg_rgb8 but set an assembled 24 bit channel at once. #[inline] -pub fn channels_set_fg_rgb(channels: &mut ChannelPair, rgb: Rgb) { +pub fn channels_set_fg_rgb(channels: &mut Channels, rgb: Rgb) { let mut channel = channels_fchannel(*channels); channel_set(&mut channel, rgb); *channels = (channel as u64) << 32 | *channels & 0xffffffff_u64; @@ -243,7 +245,7 @@ pub fn channels_set_fg_rgb(channels: &mut ChannelPair, rgb: Rgb) { /// Set the r, g, and b channels for the background component of this 64-bit /// 'channels' variable, and mark it as not using the default color. #[inline] -pub fn channels_set_bg_rgb8(channels: &mut ChannelPair, r: Color, g: Color, b: Color) { +pub fn channels_set_bg_rgb8(channels: &mut Channels, r: Color, g: Color, b: Color) { let mut channel = channels_bchannel(*channels); channel_set_rgb8(&mut channel, r, g, b); channels_set_bchannel(channels, channel); @@ -251,7 +253,7 @@ pub fn channels_set_bg_rgb8(channels: &mut ChannelPair, r: Color, g: Color, b: C /// Same as channels_set_bg_rgb8 but set an assembled 24 bit channel at once. #[inline] -pub fn channels_set_bg_rgb(channels: &mut ChannelPair, rgb: Rgb) { +pub fn channels_set_bg_rgb(channels: &mut Channels, rgb: Rgb) { let mut channel = channels_bchannel(*channels); channel_set(&mut channel, rgb); channels_set_bchannel(channels, channel); @@ -259,19 +261,19 @@ pub fn channels_set_bg_rgb(channels: &mut ChannelPair, rgb: Rgb) { /// Set the 2-bit alpha component of the foreground channel. #[inline] -pub fn channels_set_fg_alpha(channels: &mut ChannelPair, alpha: AlphaBits) { +pub fn channels_set_fg_alpha(channels: &mut Channels, alpha: AlphaBits) { let mut channel = channels_fchannel(*channels); channel_set_alpha(&mut channel, alpha); - *channels = (channel as ChannelPair) << 32 | *channels & 0xffffffff_u64; + *channels = (channel as Channels) << 32 | *channels & 0xffffffff_u64; } /// Set the 2-bit alpha component of the background channel. #[inline] -pub fn channels_set_bg_alpha(channels: &mut ChannelPair, alpha: AlphaBits) { +pub fn channels_set_bg_alpha(channels: &mut Channels, alpha: AlphaBits) { let mut alpha_clean = alpha; - if alpha == nc::CELL_ALPHA_HIGHCONTRAST { + if alpha == CELL_ALPHA_HIGHCONTRAST { // forbidden for background alpha, so makes it opaque - alpha_clean = nc::CELL_ALPHA_OPAQUE; + alpha_clean = CELL_ALPHA_OPAQUE; } let mut channel = channels_bchannel(*channels); channel_set_alpha(&mut channel, alpha_clean); @@ -280,13 +282,13 @@ pub fn channels_set_bg_alpha(channels: &mut ChannelPair, alpha: AlphaBits) { /// Is the foreground using the "default foreground color"? #[inline] -pub fn channels_fg_default_p(channels: ChannelPair) -> bool { +pub fn channels_fg_default_p(channels: Channels) -> bool { channel_default_p(channels_fchannel(channels)) } /// Is the foreground using indexed palette color? #[inline] -pub fn channels_fg_palindex_p(channels: ChannelPair) -> bool { +pub fn channels_fg_palindex_p(channels: Channels) -> bool { channel_palindex_p(channels_fchannel(channels)) } @@ -294,19 +296,19 @@ pub fn channels_fg_palindex_p(channels: ChannelPair) -> bool { /// background color" must generally be used to take advantage of /// terminal-effected transparency. #[inline] -pub fn channels_bg_default_p(channels: ChannelPair) -> bool { +pub fn channels_bg_default_p(channels: Channels) -> bool { channel_default_p(channels_bchannel(channels)) } /// Is the background using indexed palette color? #[inline] -pub fn channels_bg_palindex_p(channels: ChannelPair) -> bool { +pub fn channels_bg_palindex_p(channels: Channels) -> bool { channel_palindex_p(channels_bchannel(channels)) } /// Mark the foreground channel as using its default color. #[inline] -pub fn channels_set_fg_default(channels: &mut ChannelPair) -> ChannelPair { +pub fn channels_set_fg_default(channels: &mut Channels) -> Channels { let mut channel = channels_fchannel(*channels); channel_set_default(&mut channel); *channels = (channel as u64) << 32 | *channels & 0xffffffff_u64; @@ -315,7 +317,7 @@ pub fn channels_set_fg_default(channels: &mut ChannelPair) -> ChannelPair { /// Mark the background channel as using its default color. #[inline] -pub fn channels_set_bg_default(channels: &mut ChannelPair) -> ChannelPair { +pub fn channels_set_bg_default(channels: &mut Channels) -> Channels { let mut channel = channels_bchannel(*channels); channel_set_default(&mut channel); channels_set_bchannel(channels, channel); @@ -324,7 +326,10 @@ pub fn channels_set_bg_default(channels: &mut ChannelPair) -> ChannelPair { #[cfg(test)] mod test { - use super::{nc, Channel, ChannelPair}; + use super::{Channel, Channels}; + use crate::{ + CELL_ALPHA_BLEND, CELL_ALPHA_HIGHCONTRAST, CELL_ALPHA_OPAQUE, CELL_ALPHA_TRANSPARENT, + }; use serial_test::serial; #[test] @@ -369,25 +374,25 @@ mod test { #[test] #[serial] fn channel_alpha() { - let c: Channel = 0x112233 | nc::CELL_ALPHA_TRANSPARENT; - assert_eq!(super::channel_alpha(c), nc::CELL_ALPHA_TRANSPARENT); + let c: Channel = 0x112233 | CELL_ALPHA_TRANSPARENT; + assert_eq!(super::channel_alpha(c), CELL_ALPHA_TRANSPARENT); } #[test] #[serial] fn channel_set_alpha() { let mut c: Channel = 0x112233; - super::channel_set_alpha(&mut c, nc::CELL_ALPHA_HIGHCONTRAST); - assert_eq!(nc::CELL_ALPHA_HIGHCONTRAST, super::channel_alpha(c)); + super::channel_set_alpha(&mut c, CELL_ALPHA_HIGHCONTRAST); + assert_eq!(CELL_ALPHA_HIGHCONTRAST, super::channel_alpha(c)); - super::channel_set_alpha(&mut c, nc::CELL_ALPHA_TRANSPARENT); - assert_eq!(nc::CELL_ALPHA_TRANSPARENT, super::channel_alpha(c)); + super::channel_set_alpha(&mut c, CELL_ALPHA_TRANSPARENT); + assert_eq!(CELL_ALPHA_TRANSPARENT, super::channel_alpha(c)); - super::channel_set_alpha(&mut c, nc::CELL_ALPHA_BLEND); - assert_eq!(nc::CELL_ALPHA_BLEND, super::channel_alpha(c)); + super::channel_set_alpha(&mut c, CELL_ALPHA_BLEND); + assert_eq!(CELL_ALPHA_BLEND, super::channel_alpha(c)); - super::channel_set_alpha(&mut c, nc::CELL_ALPHA_OPAQUE); - assert_eq!(nc::CELL_ALPHA_OPAQUE, super::channel_alpha(c)); - // TODO: CHECK for nc::CELL_BGDEFAULT_MASK + super::channel_set_alpha(&mut c, CELL_ALPHA_OPAQUE); + assert_eq!(CELL_ALPHA_OPAQUE, super::channel_alpha(c)); + // TODO: CHECK for CELL_BGDEFAULT_MASK } #[test] @@ -395,7 +400,7 @@ mod test { fn channel_set_default() { const DEFAULT: Channel = 0x112233; - let mut c: Channel = DEFAULT | nc::CELL_ALPHA_TRANSPARENT; + let mut c: Channel = DEFAULT | CELL_ALPHA_TRANSPARENT; assert!(c != DEFAULT); super::channel_set_default(&mut c); @@ -409,10 +414,10 @@ mod test { assert_eq!(true, super::channel_default_p(c)); // TODO FIXME: test for the false result - // let _ = super::channel_set_alpha(&mut c, nc::CELL_ALPHA_TRANSPARENT); + // let _ = super::channel_set_alpha(&mut c, CELL_ALPHA_TRANSPARENT); // assert_eq!(false, super::channel_default_p(c)); - let _ = super::channel_set_alpha(&mut c, nc::CELL_ALPHA_OPAQUE); + let _ = super::channel_set_alpha(&mut c, CELL_ALPHA_OPAQUE); assert_eq!(true, super::channel_default_p(c)); } #[test] @@ -420,7 +425,7 @@ mod test { #[allow(non_snake_case)] fn channels_set_fchannel__channels_fchannel() { let fc: Channel = 0x112233; - let mut cp: ChannelPair = 0; + let mut cp: Channels = 0; super::channels_set_fchannel(&mut cp, fc); assert_eq!(super::channels_fchannel(cp), fc); } @@ -429,7 +434,7 @@ mod test { #[allow(non_snake_case)] fn channels_set_bchannel__channels_bchannel() { let bc: Channel = 0x112233; - let mut cp: ChannelPair = 0; + let mut cp: Channels = 0; super::channels_set_bchannel(&mut cp, bc); assert_eq!(super::channels_bchannel(cp), bc); } @@ -438,8 +443,8 @@ mod test { fn channels_combine() { let bc: Channel = 0x112233; let fc: Channel = 0x445566; - let mut cp1: ChannelPair = 0; - let mut _cp2: ChannelPair = 0; + let mut cp1: Channels = 0; + let mut _cp2: Channels = 0; super::channels_set_bchannel(&mut cp1, bc); super::channels_set_fchannel(&mut cp1, fc); _cp2 = super::channels_combine(fc, bc); diff --git a/rust/src/direct.rs b/rust/src/direct.rs index 347b25ecb..b032dcdab 100644 --- a/rust/src/direct.rs +++ b/rust/src/direct.rs @@ -39,11 +39,14 @@ // ncdirect_styles_set // ncdirect_vline_interp -use crate as nc; -use nc::types::{NcDirect, NcDirectFlags}; +use crate::{ + bindgen::_IO_FILE, + ncdirect_init, + types::{NcDirect, NcDirectFlags}, +}; extern "C" { - fn libc_stdout() -> *mut nc::_IO_FILE; + fn libc_stdout() -> *mut _IO_FILE; } /// A simple ncdirect_init() wrapper using the default options. @@ -66,5 +69,5 @@ pub unsafe fn ncdirect_new() -> *mut NcDirect { /// - NCDIRECT_OPTION_INHIBIT_SETLOCALE /// pub unsafe fn ncdirect_with_flags(flags: NcDirectFlags) -> *mut NcDirect { - nc::ncdirect_init(core::ptr::null(), libc_stdout(), flags) + ncdirect_init(core::ptr::null(), libc_stdout(), flags) } diff --git a/rust/src/input.rs b/rust/src/input.rs index 14b274331..42ab3d4d3 100644 --- a/rust/src/input.rs +++ b/rust/src/input.rs @@ -8,8 +8,7 @@ // ------------------------------------------ //+ ncinput_equal_p -use crate as nc; -use nc::types::NcInput; +use crate::types::NcInput; /// Compare two ncinput structs for data equality by doing a field-by-field /// comparison for equality (excepting seqnum). diff --git a/rust/src/key.rs b/rust/src/key.rs index 8cfaba4a5..66a34029e 100644 --- a/rust/src/key.rs +++ b/rust/src/key.rs @@ -9,7 +9,7 @@ //+ nckey_mouse_p //+ nckey_supppuab_p -use crate as nc; +use crate::{NCKEY_BUTTON1, NCKEY_RELEASE}; /// Is this u32 a Supplementary Private Use Area-B codepoint? /// @@ -24,7 +24,7 @@ pub fn nckey_supppuab_p(w: u32) -> bool { /// Is the event a synthesized mouse event? #[inline] pub fn nckey_mouse_p(r: u32) -> bool { - r >= nc::NCKEY_BUTTON1 && r <= nc::NCKEY_RELEASE + r >= NCKEY_BUTTON1 && r <= NCKEY_RELEASE } #[cfg(test)] diff --git a/rust/src/macros.rs b/rust/src/macros.rs index 89f90c8a8..204a89d01 100644 --- a/rust/src/macros.rs +++ b/rust/src/macros.rs @@ -1,14 +1,13 @@ -use crate as nc; - #[allow(unused_imports)] -use nc::Cell; + +use crate::Cell; #[macro_export] macro_rules! cell_initializer { ( $c:expr, $s:expr, $chan:expr ) => { Cell { gcluster: $c as u32, - gcluster_backstop: 0 as EGCBackstop, + gcluster_backstop: 0 as EgcBackstop, reserved: 0, stylemask: $s, channels: $chan, diff --git a/rust/src/notcurses.rs b/rust/src/notcurses.rs index b86425404..8daff9f82 100644 --- a/rust/src/notcurses.rs +++ b/rust/src/notcurses.rs @@ -54,10 +54,18 @@ use core::ptr::null; -use crate as nc; -use nc::types::{NcAlign, NcInput, NcPlane, Notcurses, NCALIGN_CENTER, NCALIGN_LEFT}; - -use nc::timespec; // NOTE: can't use libc::timespec with notcurses_getc(() +use crate::{ + // NOTE: can't use libc::timespec nor libc::sigset_t + // with notcurses_getc(() + bindings::{sigemptyset, sigfillset, sigset_t, timespec}, + ncplane_dim_yx, + notcurses_getc, + notcurses_stdplane, + notcurses_stdplane_const, + types::{NcAlign, NcInput, NcPlane, Notcurses}, + NCALIGN_CENTER, + NCALIGN_LEFT, +}; /// return the offset into 'availcols' at which 'cols' ought be output given the requirements of 'align' #[inline] @@ -76,16 +84,17 @@ pub fn notcurses_align(availcols: i32, align: NcAlign, cols: i32) -> i32 { /// 'input' may be NULL if the caller is uninterested in event details. /// If no event is ready, returns 0. +// TODO: use pakr-signals #[inline] pub fn notcurses_getc_nblock(nc: &mut Notcurses, input: &mut NcInput) -> char { unsafe { - let mut sigmask = nc::sigset_t { __val: [0; 16] }; - nc::sigfillset(&mut sigmask); + let mut sigmask = sigset_t { __val: [0; 16] }; + sigfillset(&mut sigmask); let ts = timespec { tv_sec: 0, tv_nsec: 0, }; - core::char::from_u32_unchecked(nc::notcurses_getc(nc, &ts, &mut sigmask, input)) + core::char::from_u32_unchecked(notcurses_getc(nc, &ts, &mut sigmask, input)) } } @@ -94,9 +103,9 @@ pub fn notcurses_getc_nblock(nc: &mut Notcurses, input: &mut NcInput) -> char { #[inline] pub fn notcurses_getc_nblocking(nc: &mut Notcurses, input: &mut NcInput) -> char { unsafe { - let mut sigmask = nc::sigset_t { __val: [0; 16] }; - nc::sigemptyset(&mut sigmask); - core::char::from_u32_unchecked(nc::notcurses_getc(nc, null(), &mut sigmask, input)) + let mut sigmask = sigset_t { __val: [0; 16] }; + sigemptyset(&mut sigmask); + core::char::from_u32_unchecked(notcurses_getc(nc, null(), &mut sigmask, input)) } } @@ -104,8 +113,8 @@ pub fn notcurses_getc_nblocking(nc: &mut Notcurses, input: &mut NcInput) -> char #[inline] 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); + let s = notcurses_stdplane(nc); + ncplane_dim_yx(s, y, x); *s } } @@ -114,13 +123,13 @@ pub fn notcurses_stddim_yx(nc: &mut Notcurses, y: &mut i32, x: &mut i32) -> NcPl #[inline] 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); + ncplane_dim_yx(notcurses_stdplane_const(nc), rows, cols); } } // TODO // pub unsafe fn notcurses_new() -> *mut Notcurses { -// nc::notcurses_init(core::ptr::null(), libc_stdout()) +// notcurses_init(core::ptr::null(), libc_stdout()) // } #[cfg(test)] diff --git a/rust/src/palette.rs b/rust/src/palette.rs index d162a69db..9bcb6d66a 100644 --- a/rust/src/palette.rs +++ b/rust/src/palette.rs @@ -17,8 +17,10 @@ //+ palette256_set //+ palette256_set_rgb -use crate as nc; -use nc::types::{Channel, Color, Palette, PaletteIndex, Rgb}; +use crate::{ + channel_rgb8, channel_set, channel_set_rgb8, + types::{Channel, Color, Palette, PaletteIndex, Rgb}, +}; /// Set the different color components of an entry inside a palette store. #[inline] @@ -29,13 +31,13 @@ pub fn palette256_set_rgb( green: Color, blue: Color, ) { - nc::channel_set_rgb8(&mut palette.chans[idx as usize], red, green, blue) + channel_set_rgb8(&mut palette.chans[idx as usize], red, green, blue) } /// Same as `palette256_set_rgb()` but set an assembled 24 bit channel at once. #[inline] pub fn palette256_set(palette: &mut Palette, idx: PaletteIndex, rgb: Rgb) { - nc::channel_set(&mut palette.chans[idx as usize], rgb); + channel_set(&mut palette.chans[idx as usize], rgb); } /// Extract the three 8-bit R/G/B components from an entry inside a palette store. @@ -47,7 +49,7 @@ pub fn palette256_get_rgb( green: &mut Color, blue: &mut Color, ) -> Channel { - nc::channel_rgb8(palette.chans[idx as usize], red, green, blue) + channel_rgb8(palette.chans[idx as usize], red, green, blue) } #[cfg(test)] diff --git a/rust/src/pixel.rs b/rust/src/pixel.rs index 546f0388f..bb19322a7 100644 --- a/rust/src/pixel.rs +++ b/rust/src/pixel.rs @@ -27,8 +27,7 @@ //+ ncpixel_set_r //+ ncpixel_set_rgb -use crate as nc; -use nc::types::{Color, Pixel}; +use crate::types::{Color, Pixel}; // Pixel Structure: // diff --git a/rust/src/plane.rs b/rust/src/plane.rs index 5fb138db1..77d81b364 100644 --- a/rust/src/plane.rs +++ b/rust/src/plane.rs @@ -155,10 +155,19 @@ use core::ptr::null_mut; use cstr_core::CString; use libc::free; -use crate as nc; -use nc::types::{ - AlphaBits, Cell, Channel, ChannelPair, Color, EGCBackstop, IntResult, NcAlign, NcPlane, - StyleMask, +use crate::{ + bindgen::__va_list_tag, + cell_load, cell_release, cells_double_box, cells_rounded_box, channels_bchannel, + channels_bg_alpha, channels_bg_default_p, channels_bg_rgb, channels_bg_rgb8, channels_fchannel, + channels_fg_alpha, channels_fg_default_p, channels_fg_rgb, channels_fg_rgb8, ncplane_at_cursor, + ncplane_at_yx, ncplane_box, ncplane_channels, ncplane_cursor_move_yx, ncplane_cursor_yx, + ncplane_dim_yx, ncplane_gradient, ncplane_hline_interp, ncplane_putc_yx, ncplane_putegc_yx, + ncplane_putnstr_yx, ncplane_putstr_yx, ncplane_resize, ncplane_vline_interp, + ncplane_vprintf_yx, notcurses_align, + types::{ + AlphaBits, Cell, Channel, Channels, Color, EgcBackstop, IntResult, NcAlign, NcPlane, + StyleMask, + }, }; /// Return the column at which 'cols' columns ought start in order to be aligned @@ -168,18 +177,18 @@ use nc::types::{ // NOTE: [leave cols as i32](https://github.com/dankamongmen/notcurses/issues/904) #[inline] pub fn ncplane_align(plane: &NcPlane, align: NcAlign, cols: i32) -> i32 { - nc::notcurses_align(nc::ncplane_dim_x(plane), align, cols) + notcurses_align(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 NcPlane, cell: &mut Cell) -> IntResult { - let mut egc = unsafe { nc::ncplane_at_cursor(plane, &mut cell.stylemask, &mut cell.channels) }; + let mut egc = unsafe { ncplane_at_cursor(plane, &mut cell.stylemask, &mut cell.channels) }; if egc.is_null() { return -1; } - let result: IntResult = unsafe { nc::cell_load(plane, cell, egc) }; + let result: IntResult = unsafe { cell_load(plane, cell, egc) }; if result < 0 { unsafe { free(&mut egc as *mut _ as *mut c_void); @@ -192,13 +201,12 @@ pub fn nplane_at_cursor_cell(plane: &mut NcPlane, cell: &mut Cell) -> IntResult /// This cell is invalidated if the associated plane is destroyed. #[inline] 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) }; + let mut egc = unsafe { ncplane_at_yx(plane, y, x, &mut cell.stylemask, &mut cell.channels) }; if egc.is_null() { return -1; } let channels = cell.channels; // need to preserve wide flag - let result: IntResult = unsafe { nc::cell_load(plane, cell, egc) }; + let result: IntResult = unsafe { cell_load(plane, cell, egc) }; cell.channels = channels; unsafe { free(&mut egc as *mut _ as *mut c_void); @@ -224,8 +232,8 @@ pub fn ncplane_box_sized( ) -> IntResult { let (mut y, mut x) = (0, 0); unsafe { - nc::ncplane_cursor_yx(plane, &mut y, &mut x); - nc::ncplane_box( + ncplane_cursor_yx(plane, &mut y, &mut x); + ncplane_box( plane, ul, ur, @@ -245,7 +253,7 @@ pub fn ncplane_box_sized( pub fn ncplane_dim_x(plane: &NcPlane) -> i32 { unsafe { let mut x = 0; - nc::ncplane_dim_yx(plane, null_mut(), &mut x); + ncplane_dim_yx(plane, null_mut(), &mut x); x } } @@ -255,7 +263,7 @@ pub fn ncplane_dim_x(plane: &NcPlane) -> i32 { pub fn ncplane_dim_y(plane: &NcPlane) -> i32 { unsafe { let mut y = 0; - nc::ncplane_dim_yx(plane, &mut y, null_mut()); + ncplane_dim_yx(plane, &mut y, null_mut()); y } } @@ -265,7 +273,7 @@ pub fn ncplane_dim_y(plane: &NcPlane) -> i32 { pub fn ncplane_double_box( plane: &mut NcPlane, stylemask: StyleMask, - channels: ChannelPair, + channels: Channels, ystop: i32, xstop: i32, ctlword: u32, @@ -281,7 +289,7 @@ pub fn ncplane_double_box( let mut vl = cell_trivial_initializer![]; unsafe { - ret = nc::cells_double_box( + ret = cells_double_box( plane, stylemask as u32, channels, @@ -293,15 +301,15 @@ pub fn ncplane_double_box( &mut vl, ); if ret == 0 { - ret = nc::ncplane_box(plane, &ul, &ur, &ll, &lr, &hl, &vl, ystop, xstop, ctlword); + ret = ncplane_box(plane, &ul, &ur, &ll, &lr, &hl, &vl, ystop, xstop, ctlword); } - nc::cell_release(plane, &mut ul); - nc::cell_release(plane, &mut ur); - nc::cell_release(plane, &mut ll); - nc::cell_release(plane, &mut lr); - nc::cell_release(plane, &mut hl); - nc::cell_release(plane, &mut vl); + cell_release(plane, &mut ul); + cell_release(plane, &mut ur); + cell_release(plane, &mut ll); + cell_release(plane, &mut lr); + cell_release(plane, &mut hl); + cell_release(plane, &mut vl); } ret } @@ -311,14 +319,14 @@ pub fn ncplane_double_box( pub fn ncplane_double_box_sized( plane: &mut NcPlane, stylemask: StyleMask, - channels: ChannelPair, + channels: Channels, ylen: i32, xlen: i32, ctlword: u32, ) -> IntResult { let (mut y, mut x) = (0, 0); unsafe { - nc::ncplane_cursor_yx(plane, &mut y, &mut x); + ncplane_cursor_yx(plane, &mut y, &mut x); } ncplane_double_box( plane, @@ -333,7 +341,7 @@ pub fn ncplane_double_box_sized( /// On error, return the negative number of cells drawn. #[inline] pub fn ncplane_hline(plane: &mut NcPlane, cell: &Cell, len: i32) -> i32 { - unsafe { nc::ncplane_hline_interp(plane, cell, len, cell.channels, cell.channels) } + unsafe { ncplane_hline_interp(plane, cell, len, cell.channels, cell.channels) } } /// @@ -349,9 +357,9 @@ pub fn ncplane_perimeter( ctlword: u32, ) -> IntResult { unsafe { - nc::ncplane_cursor_move_yx(plane, 0, 0); + ncplane_cursor_move_yx(plane, 0, 0); let (mut dimy, mut dimx) = (0, 0); - nc::ncplane_dim_yx(plane, &mut dimy, &mut dimx); + ncplane_dim_yx(plane, &mut dimy, &mut dimx); ncplane_box_sized(plane, ul, ur, ll, lr, hline, vline, dimy, dimx, ctlword) } } @@ -361,15 +369,15 @@ pub fn ncplane_perimeter( pub fn ncplane_perimeter_double( plane: &mut NcPlane, stylemask: StyleMask, - channels: ChannelPair, + channels: Channels, ctlword: u32, ) -> IntResult { - if unsafe { nc::ncplane_cursor_move_yx(plane, 0, 0) } != 0 { + if unsafe { ncplane_cursor_move_yx(plane, 0, 0) } != 0 { return -1; } let (mut dimy, mut dimx) = (0, 0); unsafe { - nc::ncplane_dim_yx(plane, &mut dimy, &mut dimx); + ncplane_dim_yx(plane, &mut dimy, &mut dimx); } let mut ul = cell_trivial_initializer![]; let mut ur = cell_trivial_initializer![]; @@ -378,7 +386,7 @@ pub fn ncplane_perimeter_double( let mut hl = cell_trivial_initializer![]; let mut vl = cell_trivial_initializer![]; if unsafe { - nc::cells_double_box( + cells_double_box( plane, stylemask as u32, channels, @@ -395,12 +403,12 @@ pub fn ncplane_perimeter_double( } let ret = ncplane_box_sized(plane, &ul, &ur, &ll, &lr, &hl, &vl, dimy, dimx, ctlword); unsafe { - nc::cell_release(plane, &mut ul); - nc::cell_release(plane, &mut ur); - nc::cell_release(plane, &mut ll); - nc::cell_release(plane, &mut lr); - nc::cell_release(plane, &mut hl); - nc::cell_release(plane, &mut vl); + cell_release(plane, &mut ul); + cell_release(plane, &mut ur); + cell_release(plane, &mut ll); + cell_release(plane, &mut lr); + cell_release(plane, &mut hl); + cell_release(plane, &mut vl); } ret } @@ -410,15 +418,15 @@ pub fn ncplane_perimeter_double( pub fn ncplane_perimeter_rounded( plane: &mut NcPlane, stylemask: StyleMask, - channels: ChannelPair, + channels: Channels, ctlword: u32, ) -> IntResult { - if unsafe { nc::ncplane_cursor_move_yx(plane, 0, 0) } != 0 { + if unsafe { ncplane_cursor_move_yx(plane, 0, 0) } != 0 { return -1; } let (mut dimy, mut dimx) = (0, 0); unsafe { - nc::ncplane_dim_yx(plane, &mut dimy, &mut dimx); + ncplane_dim_yx(plane, &mut dimy, &mut dimx); } let mut ul = cell_trivial_initializer![]; let mut ur = cell_trivial_initializer![]; @@ -427,7 +435,7 @@ pub fn ncplane_perimeter_rounded( let mut hl = cell_trivial_initializer![]; let mut vl = cell_trivial_initializer![]; if unsafe { - nc::cells_rounded_box( + cells_rounded_box( plane, stylemask as u32, channels, @@ -444,12 +452,12 @@ pub fn ncplane_perimeter_rounded( } let ret = ncplane_box_sized(plane, &ul, &ur, &ll, &lr, &hl, &vl, dimy, dimx, ctlword); unsafe { - nc::cell_release(plane, &mut ul); - nc::cell_release(plane, &mut ur); - nc::cell_release(plane, &mut ll); - nc::cell_release(plane, &mut lr); - nc::cell_release(plane, &mut hl); - nc::cell_release(plane, &mut vl); + cell_release(plane, &mut ul); + cell_release(plane, &mut ur); + cell_release(plane, &mut ll); + cell_release(plane, &mut lr); + cell_release(plane, &mut hl); + cell_release(plane, &mut vl); } ret } @@ -457,20 +465,20 @@ pub fn ncplane_perimeter_rounded( /// Call ncplane_putc_yx() for the current cursor location. #[inline] pub fn ncplane_putc(plane: &mut NcPlane, cell: &Cell) -> IntResult { - unsafe { nc::ncplane_putc_yx(plane, -1, -1, cell) } + unsafe { ncplane_putc_yx(plane, -1, -1, cell) } } /// Call ncplane_putegc() at the current cursor location. #[inline] pub fn ncplane_putegc(plane: &mut NcPlane, gcluster: i8, sbytes: &mut i32) -> IntResult { - unsafe { nc::ncplane_putegc_yx(plane, -1, -1, &gcluster, sbytes) } + unsafe { ncplane_putegc_yx(plane, -1, -1, &gcluster, sbytes) } } /// #[inline] pub fn ncplane_putstr(plane: &mut NcPlane, gclustarr: &[u8]) -> IntResult { unsafe { - nc::ncplane_putstr_yx( + ncplane_putstr_yx( plane, -1, -1, @@ -483,7 +491,7 @@ pub fn ncplane_putstr(plane: &mut NcPlane, gclustarr: &[u8]) -> IntResult { #[inline] pub fn ncplane_putnstr(plane: &mut NcPlane, size: u64, gclustarr: &[u8]) -> IntResult { unsafe { - nc::ncplane_putnstr_yx( + ncplane_putnstr_yx( plane, -1, -1, @@ -499,7 +507,7 @@ pub fn ncplane_putnstr(plane: &mut NcPlane, size: u64, gclustarr: &[u8]) -> IntR 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); + ncplane_dim_yx(plane, &mut oldy, &mut oldx); } let keepleny = { if oldy > ylen { @@ -515,21 +523,21 @@ pub fn ncplane_resize_simple(plane: &mut NcPlane, ylen: i32, xlen: i32) -> IntRe oldx } }; - unsafe { nc::ncplane_resize(plane, 0, 0, keepleny, keeplenx, 0, 0, ylen, xlen) } + unsafe { ncplane_resize(plane, 0, 0, keepleny, keeplenx, 0, 0, ylen, xlen) } } /// /// On error, return the negative number of cells drawn. #[inline] pub fn ncplane_vline(plane: &mut NcPlane, cell: &Cell, len: i32) -> i32 { - unsafe { nc::ncplane_vline_interp(plane, cell, len, cell.channels, cell.channels) } + unsafe { ncplane_vline_interp(plane, cell, len, cell.channels, cell.channels) } } /// #[inline] -pub fn ncplane_vprintf(plane: &mut NcPlane, format: &str, ap: &mut nc::__va_list_tag) -> IntResult { +pub fn ncplane_vprintf(plane: &mut NcPlane, format: &str, ap: &mut __va_list_tag) -> IntResult { unsafe { - nc::ncplane_vprintf_yx( + ncplane_vprintf_yx( plane, -1, -1, @@ -560,8 +568,8 @@ pub fn ncplane_gradient_sized( } let (mut y, mut x) = (0, 0); unsafe { - nc::ncplane_cursor_yx(plane, &mut y, &mut x); - nc::ncplane_gradient( + ncplane_cursor_yx(plane, &mut y, &mut x); + ncplane_gradient( plane, CString::new(egc).expect("Bad EGC").as_ptr(), stylemask as u32, @@ -578,49 +586,49 @@ pub fn ncplane_gradient_sized( /// Extract the 32-bit working foreground channel from an ncplane. #[inline] pub fn ncplane_fchannel(plane: &NcPlane) -> Channel { - nc::channels_fchannel(unsafe { nc::ncplane_channels(plane) }) + channels_fchannel(unsafe { ncplane_channels(plane) }) } /// Extract the 32-bit working background channel from an ncplane. #[inline] pub fn ncplane_bchannel(plane: &NcPlane) -> Channel { - nc::channels_bchannel(unsafe { nc::ncplane_channels(plane) }) + channels_bchannel(unsafe { ncplane_channels(plane) }) } /// Extract 24 bits of working foreground RGB from an ncplane, shifted to LSBs. #[inline] pub fn ncplane_fg_rgb(plane: &NcPlane) -> Channel { - nc::channels_fg_rgb(unsafe { nc::ncplane_channels(plane) }) + channels_fg_rgb(unsafe { ncplane_channels(plane) }) } /// Extract 24 bits of working background RGB from an ncplane, shifted to LSBs. #[inline] pub fn ncplane_bg_rgb(plane: &NcPlane) -> Channel { - nc::channels_bg_rgb(unsafe { nc::ncplane_channels(plane) }) + channels_bg_rgb(unsafe { ncplane_channels(plane) }) } /// Extract 2 bits of foreground alpha from 'struct ncplane', shifted to LSBs. #[inline] pub fn ncplane_fg_alpha(plane: &NcPlane) -> AlphaBits { - nc::channels_fg_alpha(unsafe { nc::ncplane_channels(plane) }) + channels_fg_alpha(unsafe { ncplane_channels(plane) }) } /// Extract 2 bits of background alpha from 'struct ncplane', shifted to LSBs. #[inline] pub fn ncplane_bg_alpha(plane: &NcPlane) -> AlphaBits { - nc::channels_bg_alpha(unsafe { nc::ncplane_channels(plane) }) + channels_bg_alpha(unsafe { ncplane_channels(plane) }) } /// Is the plane's foreground using the "default foreground color"? #[inline] pub fn ncplane_fg_default_p(plane: &NcPlane) -> bool { - nc::channels_fg_default_p(unsafe { nc::ncplane_channels(plane) }) + channels_fg_default_p(unsafe { ncplane_channels(plane) }) } /// Is the plane's background using the "default background color"? #[inline] pub fn ncplane_bg_default_p(plane: &NcPlane) -> bool { - nc::channels_bg_default_p(unsafe { nc::ncplane_channels(plane) }) + channels_bg_default_p(unsafe { ncplane_channels(plane) }) } /// Extract 24 bits of foreground RGB from a plane, split into components. @@ -631,7 +639,7 @@ pub fn ncplane_fg_rgb8( green: &mut Color, blue: &mut Color, ) -> Channel { - nc::channels_fg_rgb8(unsafe { nc::ncplane_channels(plane) }, red, green, blue) + channels_fg_rgb8(unsafe { ncplane_channels(plane) }, red, green, blue) } /// Extract 24 bits of background RGB from a plane, split into components. @@ -642,7 +650,7 @@ pub fn ncplane_bg_rgb8( green: &mut Color, blue: &mut Color, ) -> Channel { - nc::channels_bg_rgb8(unsafe { nc::ncplane_channels(plane) }, red, green, blue) + channels_bg_rgb8(unsafe { ncplane_channels(plane) }, red, green, blue) } /// @@ -650,7 +658,7 @@ pub fn ncplane_bg_rgb8( pub fn ncplane_rounded_box( plane: &mut NcPlane, stylemask: StyleMask, - channels: ChannelPair, + channels: Channels, ystop: i32, xstop: i32, ctlword: u32, @@ -666,7 +674,7 @@ pub fn ncplane_rounded_box( let mut vl = cell_trivial_initializer![]; unsafe { - ret = nc::cells_rounded_box( + ret = cells_rounded_box( plane, stylemask as u32, channels, @@ -678,15 +686,15 @@ pub fn ncplane_rounded_box( &mut vl, ); if ret == 0 { - ret = nc::ncplane_box(plane, &ul, &ur, &ll, &lr, &hl, &vl, ystop, xstop, ctlword); + ret = ncplane_box(plane, &ul, &ur, &ll, &lr, &hl, &vl, ystop, xstop, ctlword); } - nc::cell_release(plane, &mut ul); - nc::cell_release(plane, &mut ur); - nc::cell_release(plane, &mut ll); - nc::cell_release(plane, &mut lr); - nc::cell_release(plane, &mut hl); - nc::cell_release(plane, &mut vl); + cell_release(plane, &mut ul); + cell_release(plane, &mut ur); + cell_release(plane, &mut ll); + cell_release(plane, &mut lr); + cell_release(plane, &mut hl); + cell_release(plane, &mut vl); } ret } @@ -696,14 +704,14 @@ pub fn ncplane_rounded_box( pub fn ncplane_rounded_box_sized( plane: &mut NcPlane, stylemask: StyleMask, - channels: ChannelPair, + channels: Channels, ylen: i32, xlen: i32, ctlword: u32, ) -> IntResult { let (mut y, mut x) = (0, 0); unsafe { - nc::ncplane_cursor_yx(plane, &mut y, &mut x); + ncplane_cursor_yx(plane, &mut y, &mut x); } ncplane_rounded_box( plane, diff --git a/rust/src/types.rs b/rust/src/types.rs index 3bf4de0bf..514ca13cd 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -1,57 +1,76 @@ -//! The notcurses types are defined and/or explained here +//! Idiomatic Rust Type Aliases //! -//! Existing types are wrapped to make them follow the Rust API Guidelines -//! and to enforce type check whenever possible +//! These types wrap the ones used in the C library, including structs, +//! constants, and primitives when used as parameters or return values. +//! +//! This is in order to enforce type checking when possible and also to follow +//! the [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/naming.html) //! -//! 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. +// Rgb +// +/// 24 bits broken into 3x 8bpp channels. /// +/// ```txt /// -------- RRRRRRRR GGGGGGGG BBBBBBBB +/// ``` /// -/// type in C: no data type +/// `type in C: no data type` /// pub type Rgb = u32; +// Color +// /// 8 bpp channel /// +/// ```txt /// CCCCCCCC (1 Byte) +/// ``` /// /// Used both for R/G/B color and 8 bit alpha /// -/// type in C: no data type +/// `type in C: no data type` /// pub type Color = u8; -/// Channel: 32 bits of context-dependent info +// Channel +// +/// 32 bits of context-dependent info /// containing RGB + 2 bits of alpha + crap /// +/// ```txt /// ~~AA~~~~ RRRRRRRR GGGGGGGG BBBBBBBB +/// ``` /// /// It is: /// - an RGB value /// - plus 2 bits of alpha /// - plus context-dependent info /// -/// The context details are documented in ChannelPair, +/// The context details are documented in [`Channels`](type.Channels.html) /// -/// type in C: channel (uint32_t) +/// `type in C: channel (uint32_t)` /// pub type Channel = u32; +// AlphaBits +// /// 2 bits of alpha (surrounded by context dependent bits). /// It is part of a Channel. /// +/// ```txt /// ~~AA~~~~ -------- -------- -------- +/// ``` /// -/// type in C: no data type +/// `type in C: no data type` /// pub type AlphaBits = u32; -/// Channels: 64 bits containing a foreground and background channel +// Channels +// +/// 64 bits containing a foreground and background channel /// +/// ```txt /// ~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB|~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB /// ↑↑↑↑↑↑↑↑↑↑↑↑ foreground ↑↑↑↑↑↑↑↑↑↑↑|↑↑↑↑↑↑↑↑↑↑↑↑ background ↑↑↑↑↑↑↑↑↑↑↑ /// @@ -97,7 +116,7 @@ pub type AlphaBits = u32; /// /// background in 3x8 RGB (rrggbb): /// 0········ ········ ········ ········ ········11111111 11111111 11111111 = ········ ··FFFFFF -/// +/// ``` /// /// At render time, these 24-bit values are quantized down to terminal /// capabilities, if necessary. There's a clear path to 10-bit support should @@ -105,13 +124,16 @@ pub type AlphaBits = u32; /// best explained by color(3NCURSES). ours is the same concept. until the /// "not default color" bit is set, any color you load will be ignored. /// -/// type in C: channels (uint64_t) +/// `type in C: channels (uint64_t)` /// -pub type ChannelPair = u64; +pub type Channels = u64; -/// Pixel (RGBA): 32 bits broken into RGB + 8-bit alpha +// Pixel (RGBA) +/// 32 bits broken into RGB + 8-bit alpha /// +/// ```txt /// AAAAAAAA GGGGGGGG BBBBBBBB RRRRRRRR +/// ``` /// /// ncpixel has 8 bits of alpha, more or less linear, contributing /// directly to the usual alpha blending equation @@ -119,40 +141,86 @@ pub type ChannelPair = u64; /// we map the 8 bits of alpha to 2 bits of alpha via a level function: /// https://nick-black.com/dankwiki/index.php?title=Notcurses#Transparency.2FContrasting /// -/// type in C: ncpixel (uint32_t) +/// `type in C: ncpixel (uint32_t)` /// // NOTE: the order of the colors is different than channel. Why. pub type Pixel = u32; -// Cell: 128 bits tying together a: -// -// 1. GCluster, 32b, either or: -// UUUUUUUU UUUUUUUU UUUUUUUU UUUUUUUU -// 00000001 IIIIIIII IIIIIIII IIIIIIII -// -// 2. GCluster backstop, 8b, (zero) -// 00000000 -// -// 3. reserved, 8b (ought to be zero) -// ~~~~~~~~ -// -// 4. Stylemask, 16b -// 11111111 11111111 -// -// 5. Channels (64b) -// ~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB|~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB -// -// type in C: cell (struct) -pub type Cell = nc::cell; +// Cell +/// A coordinate on an [`NcPlane`](type.NcPlane.html) +/// +/// ```txt +/// Cell: 128 bits tying together a: +/// +/// 1. GCluster, 32b, either or: +/// UUUUUUUU UUUUUUUU UUUUUUUU UUUUUUUU +/// 00000001 IIIIIIII IIIIIIII IIIIIIII +/// +/// 2. GCluster backstop, 8b, (zero) +/// 00000000 +/// +/// 3. reserved, 8b (ought to be zero) +/// ~~~~~~~~ +/// +/// 4. Stylemask, 16b +/// 11111111 11111111 +/// +/// 5. Channels (64b) +/// ~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB|~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB +/// ``` +/// +/// A Cell corresponds to a single character cell on some plane, which can be occupied by a single grapheme cluster (some root spacing glyph, along with possible combining characters, which might span multiple columns). At any cell, we can have a theoretically arbitrarily long UTF-8 string, a foreground color, a background color, and an attribute set. Valid grapheme cluster contents include: +/// +/// - A NUL terminator, +/// - A single control character, followed by a NUL terminator, +/// - At most one spacing character, followed by zero or more nonspacing +/// characters, followed by a NUL terminator. +/// +/// Multi-column characters can only have a single style/color throughout. +/// wcwidth() is not reliable. It's just quoting whether or not the Egc +/// contains a "Wide Asian" double-width character. +/// This is set for some things, like most emoji, and not set for +/// other things, like cuneiform. +/// +/// Each cell occupies 16 static bytes (128 bits). The surface is thus ~1.6MB +/// for a (pretty large) 500x200 terminal. At 80x43, it's less than 64KB. +/// Dynamic requirements (the egcpool) can add up to 16MB to an ncplane, but +/// such large pools are unlikely in common use. +/// +/// We implement some small alpha compositing. Foreground and background both +/// have two bits of inverted alpha. The actual grapheme written to a cell is +/// the topmost non-zero grapheme. If its alpha is 00, its foreground color is +/// used unchanged. If its alpha is 10, its foreground color is derived entirely +/// from cells underneath it. Otherwise, the result will be a composite. +/// Likewise for the background. If the bottom of a coordinate's zbuffer is +/// reached with a cumulative alpha of zero, the default is used. In this way, +/// a terminal configured with transparent background can be supported through +/// multiple occluding ncplanes. A foreground alpha of 11 requests high-contrast +/// text (relative to the computed background). A background alpha of 11 is +/// currently forbidden. +/// +/// Default color takes precedence over palette or RGB, and cannot be used with +/// transparency. Indexed palette takes precedence over RGB. It cannot +/// meaningfully set transparency, but it can be mixed into a cascading color. +/// RGB is used if neither default terminal colors nor palette indexing are in +/// play, and fully supports all transparency options. +/// +/// `type in C: cell (struct)` +/// +pub type Cell = crate::cell; -/// EGC (Extended Grapheme Cluster) +// Egc +// +/// 32-bit Char, Extended Grapheme Cluster /// /// This 32 bit char, together with the associated plane's associated egcpool, -/// completely define this cell's EGC. Unless the EGC requires more than four -/// bytes to encode as UTF-8, it will be inlined here: +/// completely define this cell's `Egc`. Unless the `Egc` requires more than +/// four bytes to encode as UTF-8, it will be inlined here: /// +/// ```txt /// UUUUUUUU UUUUUUUU UUUUUUUU UUUUUUUU /// extended grapheme cluster <= 4bytes +/// ``` /// /// If more than four bytes are required, it will be spilled into the egcpool. /// In either case, there's a NUL-terminated string available without copying, @@ -160,64 +228,90 @@ pub type Cell = nc::cell; /// byte of this struct (the GClusterBackStop field, see below) is /// guaranteed to be zero, as are any unused bytes in gcluster. /// -/// A spilled EGC is indicated by the value 0x01iiiiii. This cannot alias a -/// true supra-ASCII EGC, because UTF-8 only encodes bytes <= 0x80 when they -/// are single-byte ASCII-derived values. The iiiiii is interpreted as a 24-bit +/// A spilled Egc is indicated by the value `0x01iiiiii`. This cannot alias a +/// true supra-ASCII Egc, because UTF-8 only encodes bytes <= 0x80 when they +/// are single-byte ASCII-derived values. The `iiiiii` is interpreted as a 24-bit /// index into the egcpool (which may thus be up to 16MB): /// +/// ```txt /// 00000001 iiiiiiii iiiiiiii iiiiiiii -/// sign 24bit index to egpool +/// sign 24bit index to egcpool +/// ``` /// /// The cost of this scheme is that the character 0x01 (SOH) cannot be encoded /// in a cell, and therefore it must not be allowed through the API. /// /// ----- -/// NOTE that even if the EGC is <= 4 bytes and inlined, is still interpreted a +/// NOTE that even if the `Egc` is <= 4 bytes and inlined, is still interpreted /// a NUL-terminated char * (technically, &cell->gcluster is treated as a char*). /// If it is more than 4 bytes, cell->gcluster has a first byte of 0x01, /// and the remaining 24 bits are an index into the plane's egcpool, /// which is carved into NUL-terminated chunks of arbitrary length. /// -/// type in C: gcluster (uint32_t) +/// `type in C: gcluster (uint32_t)` /// // WIP towards a safe abstraction for Cell & functions receiving -pub type EGC = char; -// pub type EGCPool<'a> = &'a[u8]; +pub type Egc = char; +// pub type EgcPool<'a> = &'a[u8]; + pub type CellGcluster = u32; // the type cell.gcluster expects the EGB to be -/// EGC BackStop +/// Egc BackStop /// -/// type in C: cell.gcluster_backstop -pub type EGCBackstop = u8; +/// `type in C: cell.gcluster_backstop` +/// +pub type EgcBackstop = u8; -/// StyleMask +// StyleMask /// -/// 16 bits NCSTYLE_* of boolean styling attributes: +/// 16 bits `NCSTYLE_*` of boolean styling attributes: /// +/// ```txt /// 11111111 11111111 +/// ``` /// -/// type in C: stylemask (uint16_t) +/// `type in C: stylemask (uint16_t)` /// pub type StyleMask = u16; -/// Type alias of ncplane -// Plane: fundamental drawing surface. unites a: -// -// - CellMatrix -// - EGCPool -// -// type in C: ncplane (struct) -pub type NcPlane = nc::ncplane; +// NcPlane +/// Fundamental drawing surface. +/// +/// Unites a: +/// +/// - CellMatrix +/// - EgcPool +/// +/// `type in C: ncplane (struct)` +pub type NcPlane = crate::ncplane; -// EGCPool: contiguous region chopped up into NUL-terminated UTF8 EGCs, one per plane +/// I/O wrapper to dump file descriptor to [`NcPlane`](type.NcPlane.html) +pub type NcFdPlane = crate::ncfdplane; + +/// Options struct for [`NcFdPlane`](type.NcFdPlane.html) +/// +/// `type in C: ncplane_options (struct)` +pub type NcFdPlaneOptions = crate::ncfdplane_options; + +// EGCPool: // -// type in C: egcpool (struct) +// Contiguous region chopped up into NUL-terminated UTF8 EGCs, one per plane +// +// `type in C: egcpool (struct)` +// TODO // CellMatrix: rectilinear array of Cells // one -- fb per plane, and transients show up ? -/// Typle alias of palette256 -pub type Palette = nc::palette256; +/// Palette structure consisting of an array of 256 [`Channel`](type.Channel.html)s +/// +/// Some terminals only support 256 colors, but allow the full +/// palette to be specified with arbitrary RGB colors. In all cases, it's more +/// performant to use indexed colors, since it's much less data to write to the +/// terminal. If you can limit yourself to 256 colors, that's probably best. +/// +/// `type in C: ncpalette256 (struct)` +pub type Palette = crate::palette256; /// 8-bit value used for indexing into a palette /// @@ -227,81 +321,159 @@ pub type PaletteIndex = u8; /// pub type IntResult = i32; -/// Type alias of ncalign_e -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; +/// the [`Egc`](type.Egc.html)s which form the various levels +/// of a given geometry. +/// +/// If the geometry is wide, things are arranged with the rightmost side +/// increasing most quickly, i.e. it can be indexed as height arrays of +/// 1 + height glyphs. +/// i.e. The first five braille EGCs are all 0 on the left, +/// [0..4] on the right. +/// +/// `type in C: blitset (struct)` +pub type BlitSet = crate::blitset; -/// Type alias of ncblitter_e -pub type NcBlitter = nc::ncblitter_e; +/// Alignment within a plane or terminal. +/// Left/right-justified, or centered. +pub type NcAlign = crate::ncalign_e; +/// Align an NcPlane or NcTerm +pub const NCALIGN_LEFT: NcAlign = crate::ncalign_e_NCALIGN_LEFT; +/// +pub const NCALIGN_RIGHT: NcAlign = crate::ncalign_e_NCALIGN_RIGHT; +/// +pub const NCALIGN_CENTER: NcAlign = crate::ncalign_e_NCALIGN_CENTER; +/// +pub const NCALIGN_UNALIGNED: NcAlign = crate::ncalign_e_NCALIGN_UNALIGNED; +/// Blitter Mode (`NCBLIT_*`) +/// +/// We never blit full blocks, but instead spaces (more efficient) with the +/// background set to the desired foreground. +pub type NcBlitter = crate::ncblitter_e; /// space, compatible with ASCII -pub const NCBLIT_1x1: NcBlitter = nc::ncblitter_e_NCBLIT_1x1; - +pub const NCBLIT_1x1: NcBlitter = crate::ncblitter_e_NCBLIT_1x1; /// halves + 1x1 (space) /// ▄▀ -pub const NCBLIT_2x1: NcBlitter = nc::ncblitter_e_NCBLIT_2x1; - +pub const NCBLIT_2x1: NcBlitter = crate::ncblitter_e_NCBLIT_2x1; /// quadrants + 2x1 /// ▗▐ ▖▀▟▌▙ -pub const NCBLIT_2x2: NcBlitter = nc::ncblitter_e_NCBLIT_2x2; - +pub const NCBLIT_2x2: NcBlitter = crate::ncblitter_e_NCBLIT_2x2; /// sextants (NOT 2x2) /// 🬀🬁🬂🬃🬄🬅🬆🬇🬈🬉🬊🬋🬌🬍🬎🬏🬐🬑🬒🬓🬔🬕🬖🬗🬘🬙🬚🬛🬜🬝🬞🬟🬠🬡🬢🬣🬤🬥🬦🬧🬨🬩🬪🬫🬬🬭🬮🬯🬰🬱🬲🬳🬴🬵🬶🬷🬸🬹🬺🬻 -pub const NCBLIT_3x2: NcBlitter = nc::ncblitter_e_NCBLIT_3x2; - +pub const NCBLIT_3x2: NcBlitter = crate::ncblitter_e_NCBLIT_3x2; /// four vertical levels /// █▆▄▂ -pub const NCBLIT_4x1: NcBlitter = nc::ncblitter_e_NCBLIT_4x1; - +pub const NCBLIT_4x1: NcBlitter = crate::ncblitter_e_NCBLIT_4x1; /// eight vertical levels /// █▇▆▅▄▃▂▁ -pub const NCBLIT_8x1: NcBlitter = nc::ncblitter_e_NCBLIT_8x1; - +pub const NCBLIT_8x1: NcBlitter = crate::ncblitter_e_NCBLIT_8x1; /// 4 rows, 2 cols (braille) /// ⡀⡄⡆⡇⢀⣀⣄⣆⣇⢠⣠⣤⣦⣧⢰⣰⣴⣶⣷⢸⣸⣼⣾⣿ -pub const NCBLIT_BRAILLE: NcBlitter = nc::ncblitter_e_NCBLIT_BRAILLE; - +pub const NCBLIT_BRAILLE: NcBlitter = crate::ncblitter_e_NCBLIT_BRAILLE; /// the blitter is automatically chosen -pub const NCBLIT_DEFAULT: NcBlitter = nc::ncblitter_e_NCBLIT_DEFAULT; - +pub const NCBLIT_DEFAULT: NcBlitter = crate::ncblitter_e_NCBLIT_DEFAULT; /// 6 rows, 1 col (RGB), spotty support among terminals -pub const NCBLIT_SIXEL: NcBlitter = nc::ncblitter_e_NCBLIT_SIXEL; +pub const NCBLIT_SIXEL: NcBlitter = crate::ncblitter_e_NCBLIT_SIXEL; -/// Type alias of ncscale_e -pub type NcScale = nc::ncscale_e; - -/// Maintain original size -pub const NCSCALE_NONE: NcScale = nc::ncscale_e_NCSCALE_NONE; - -/// Maintain aspect ratio -pub const NCSCALE_SCALE: NcScale = nc::ncscale_e_NCSCALE_SCALE; - -/// Throw away aspect ratio -pub const NCSCALE_STRETCH: NcScale = nc::ncscale_e_NCSCALE_STRETCH; - -/// Type alias of ncdirect (direct mode) -pub type NcDirect = nc::ncdirect; - -/// Type alias of -pub type NcDirectFlags = u64; - -/// Avoids placing the terminal into cbreak mode (disabling echo and line buffering) -pub const NCDIRECT_INHIBIT_CBREAK: NcDirectFlags = - nc::NCDIRECT_OPTION_INHIBIT_CBREAK as NcDirectFlags; - -/// Avoids calling setlocale(LC_ALL, NULL). +/// Log level for [`NotcursesOptions`](type.NotcursesOptions.html) +pub type NcLogLevel = crate::ncloglevel_e; /// -/// If the result is either "C" or "POSIX", it will print a diagnostic to stderr, -/// 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 NCDIRECT_INHIBIT_SETLOCALE: NcDirectFlags = - nc::NCDIRECT_OPTION_INHIBIT_SETLOCALE as NcDirectFlags; +pub const NCLOGLEVEL_DEBUG: NcLogLevel = crate::ncloglevel_e_NCLOGLEVEL_DEBUG; +pub const NCLOGLEVEL_ERROR: NcLogLevel = crate::ncloglevel_e_NCLOGLEVEL_ERROR; +pub const NCLOGLEVEL_FATAL: NcLogLevel = crate::ncloglevel_e_NCLOGLEVEL_FATAL; +pub const NCLOGLEVEL_INFO: NcLogLevel = crate::ncloglevel_e_NCLOGLEVEL_INFO; +pub const NCLOGLEVEL_PANIC: NcLogLevel = crate::ncloglevel_e_NCLOGLEVEL_PANIC; +pub const NCLOGLEVEL_SILENT: NcLogLevel = crate::ncloglevel_e_NCLOGLEVEL_SILENT; +pub const NCLOGLEVEL_TRACE: NcLogLevel = crate::ncloglevel_e_NCLOGLEVEL_TRACE; +pub const NCLOGLEVEL_VERBOSE: NcLogLevel = crate::ncloglevel_e_NCLOGLEVEL_VERBOSE; +pub const NCLOGLEVEL_WARNING: NcLogLevel = crate::ncloglevel_e_NCLOGLEVEL_WARNING; -/// Type alias of notcurses (full mode) -pub type Notcurses = nc::bindings::notcurses; +/// How to scale an [`NcVisual`](type.NcVisual.html) during rendering +/// +/// - NCSCALE_NONE will apply no scaling. +/// - NCSCALE_SCALE scales a visual to the plane's size, +/// maintaining aspect ratio. +/// - NCSCALE_STRETCH stretches and scales the image in an +/// attempt to fill the entirety of the plane. +pub type NcScale = crate::ncscale_e; +/// Maintain original size +pub const NCSCALE_NONE: NcScale = crate::ncscale_e_NCSCALE_NONE; +/// Maintain aspect ratio +pub const NCSCALE_SCALE: NcScale = crate::ncscale_e_NCSCALE_SCALE; +/// Throw away aspect ratio +pub const NCSCALE_STRETCH: NcScale = crate::ncscale_e_NCSCALE_STRETCH; -/// Type alias of ncinput -pub type NcInput = nc::ncinput; +/// Reads and decodes input events +/// +/// Reads from stdin and decodes the input to stdout, +/// including synthesized events and mouse events. +/// +/// To exit, generate EOF (usually Ctrl+‘d’). +pub type NcInput = crate::ncinput; + +/// A visual bit of multimedia opened with LibAV|OIIO +pub type NcVisual = crate::ncvisual; +/// Options struct for [`NcVisual`](type.NcVisual.html) +pub type NcVisualOptions = crate::ncvisual_options; + +// Terminal -------------------------------------------------------------------- + +/// Minimal notcurses instances for styling text +pub type NcDirect = crate::ncdirect; + +/// Flags for NcDirect +pub type NcDirectFlags = u64; +/// Flag that avoids placing the terminal into cbreak mode +/// (disabling echo and line buffering) +pub const NCDIRECT_OPTION_INHIBIT_CBREAK: NcDirectFlags = + crate::bindings::NCDIRECT_OPTION_INHIBIT_CBREAK as NcDirectFlags; +/// Flag that avoids calling setlocale(LC_ALL, NULL) +/// +/// If the result is either "C" or "POSIX", it will print a +/// diagnostic to stderr, 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 NCDIRECT_OPTION_INHIBIT_SETLOCALE: NcDirectFlags = + crate::bindings::NCDIRECT_OPTION_INHIBIT_SETLOCALE as NcDirectFlags; + +/// TUI library for modern terminal emulators +/// +/// Notcurses builds atop the terminfo abstraction layer to +/// provide reasonably portable vivid character displays. +pub type Notcurses = crate::bindings::notcurses; +/// Options struct for [`Notcurses`](type.Notcurses.html) +pub type NotcursesOptions = crate::bindings::notcurses_options; + +/// Context for a palette fade operation +pub type NcFadeCtx = crate::ncfadectx; + + +// Widgets + +pub type NcMenu = crate::ncmenu; +pub type NcMenuItem = crate::ncmenu_item; +pub type NcMenuOptions = crate::ncmenu_options; +pub type NcMenuSection = crate::ncmenu_section; + +pub type NcReader = crate::ncreader; +pub type NcReaderOptions = crate::ncreader_options; + +pub type NcReel = crate::ncreel; +pub type NcReelOptions = crate::ncreel_options; + +pub type NcPlotF64 = crate::ncdplot; +pub type NcPlotU64 = crate::ncuplot; +pub type NcPlotOptions = crate::ncplot_options; + +pub type NcSelector = crate::ncselector; +pub type NcSelectorItem = crate::ncselector_item; +pub type NcSelectorOptions = crate::ncselector_options; + +pub type NcStats = crate::ncstats; + +pub type NcTablet = crate::nctablet; + +pub type NcMultiSelector = crate::ncmultiselector; +pub type NcMultiSelectorItem = crate::ncmselector_item; +pub type NcMultiSelectorOptions = crate::ncmultiselector_options; diff --git a/rust/src/visual.rs b/rust/src/visual.rs index 6dce240fd..15d4764ec 100644 --- a/rust/src/visual.rs +++ b/rust/src/visual.rs @@ -25,8 +25,7 @@ // ------------------------------------------ // ncvisual_default_blitter -use crate as nc; -use nc::types::{NCBLIT_1x1, NCBLIT_2x1, NCBLIT_2x2, NcBlitter, NcScale, NCSCALE_STRETCH}; +use crate::types::{NCBLIT_1x1, NCBLIT_2x1, NCBLIT_2x2, NcBlitter, NcScale, NCSCALE_STRETCH}; /// Returns the best default blitter available /// diff --git a/rust/tests/notcurses.rs b/rust/tests/notcurses.rs index 85242ed18..d28aaf25c 100644 --- a/rust/tests/notcurses.rs +++ b/rust/tests/notcurses.rs @@ -23,7 +23,7 @@ fn get_notcurses_version() { fn create_notcurses_context() { unsafe { let _ = libc::setlocale(libc::LC_ALL, CString::new("").unwrap().as_ptr()); - let opts = nc::notcurses_options { + let opts = nc::NotcursesOptions { loglevel: 0, termtype: null(), renderfp: null_mut(),