diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 7ec32a1c9..c6ddad15d 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -19,7 +19,7 @@ categories = [ keywords = ["tui", "cli", "terminal", "ncurses", "ffi"] [dependencies] -libc = {version = "0.2.74", default-features = false} +libc = {version = "0.2.76", default-features = false} cty = "0.2.1" cstr_core = "0.2.1" libc-print = "0.1.13" diff --git a/rust/src/cells.rs b/rust/src/cells.rs index 570e3bfb4..c5f277cfc 100644 --- a/rust/src/cells.rs +++ b/rust/src/cells.rs @@ -57,9 +57,9 @@ use crate as nc; use nc::types::{ - AlphaBits, CellGcluster, Channel, ChannelPair, Color, IntResult, PaletteIndex, StyleMask, EGC, + AlphaBits, Cell, CellGcluster, Channel, ChannelPair, Color, IntResult, PaletteIndex, Plane, + StyleMask, EGC, }; -use nc::{cell, ncplane}; /// cell_load(), plus blast the styling with 'style' and 'channels'. /// @@ -83,9 +83,7 @@ pub unsafe fn cell_prime( ) -> IntResult { cell.stylemask = style; cell.channels = channels; - unsafe { - nc::cell_load(plane, cell, gcluster as u32 as *const i8) - } + unsafe { nc::cell_load(plane, cell, gcluster as u32 as *const i8) } } /// load up six cells with the EGCs necessary to draw a box. @@ -102,15 +100,15 @@ pub unsafe fn cell_prime( // TODO: TEST! #[allow(unused_unsafe)] pub unsafe fn cells_load_box( - plane: &mut ncplane, + plane: &mut Plane, style: StyleMask, channels: ChannelPair, - ul: &mut cell, - ur: &mut cell, - ll: &mut cell, - lr: &mut cell, - hl: &mut cell, - vl: &mut cell, + ul: &mut Cell, + ur: &mut Cell, + ll: &mut Cell, + lr: &mut Cell, + hl: &mut Cell, + vl: &mut Cell, gcluster: EGC, ) -> IntResult { // mutable copy for pointer arithmetics: @@ -169,7 +167,7 @@ pub unsafe fn cells_load_box( /// // TODO: TEST #[inline] -pub fn cell_init(cell: &mut cell) { +pub fn cell_init(cell: &mut Cell) { *cell = unsafe { core::mem::zeroed() } } @@ -178,14 +176,14 @@ pub fn cell_init(cell: &mut cell) { /// static inline void // TODO: TEST #[inline] -pub fn cell_styles_set(cell: &mut cell, stylebits: StyleMask) { +pub fn cell_styles_set(cell: &mut Cell, stylebits: StyleMask) { cell.stylemask = stylebits & nc::NCSTYLE_MASK as u16; } /// Extract the style bits from the cell. // TODO: TEST #[inline] -pub fn cell_styles(cell: &cell) -> StyleMask { +pub fn cell_styles(cell: &Cell) -> StyleMask { cell.stylemask } @@ -193,42 +191,42 @@ pub fn cell_styles(cell: &cell) -> StyleMask { /// they're actively supported or not. // TODO: TEST #[inline] -pub fn cell_styles_on(cell: &mut cell, stylebits: StyleMask) { +pub fn cell_styles_on(cell: &mut Cell, stylebits: StyleMask) { cell.stylemask |= stylebits & nc::NCSTYLE_MASK as u16; } /// Remove the specified styles (in the LSBs) from the cell's existing spec. // TODO: TEST #[inline] -pub fn cell_styles_off(cell: &mut cell, stylebits: StyleMask) { +pub fn cell_styles_off(cell: &mut Cell, stylebits: StyleMask) { cell.stylemask &= !(stylebits & nc::NCSTYLE_MASK as u16); } /// Use the default color for the foreground. // TODO: TEST #[inline] -pub fn cell_set_fg_default(cell: &mut cell) { +pub fn cell_set_fg_default(cell: &mut Cell) { nc::channels_set_fg_default(&mut cell.channels); } /// Use the default color for the background. // TODO: TEST #[inline] -pub fn cell_set_bg_default(cell: &mut cell) { +pub fn cell_set_bg_default(cell: &mut Cell) { nc::channels_set_bg_default(&mut cell.channels); } /// Set the foreground alpha. // TODO: TEST #[inline] -pub fn cell_set_fg_alpha(cell: &mut cell, alpha: AlphaBits) { +pub fn cell_set_fg_alpha(cell: &mut Cell, alpha: AlphaBits) { nc::channels_set_fg_alpha(&mut cell.channels, alpha); } /// Set the background alpha. // TODO: TEST #[inline] -pub fn cell_set_bg_alpha(cell: &mut cell, alpha: AlphaBits) { +pub fn cell_set_bg_alpha(cell: &mut Cell, alpha: AlphaBits) { nc::channels_set_bg_alpha(&mut cell.channels, alpha); } @@ -236,21 +234,21 @@ pub fn cell_set_bg_alpha(cell: &mut cell, alpha: AlphaBits) { // TODO: TEST // NOTE: remove casting when fixed: https://github.com/rust-lang/rust-bindgen/issues/1875 #[inline] -pub fn cell_double_wide_p(cell: &cell) -> bool { +pub fn cell_double_wide_p(cell: &Cell) -> bool { (cell.channels & nc::CELL_WIDEASIAN_MASK as u64) != 0 } /// Is this the right half of a wide character? // TODO: TEST #[inline] -pub fn cell_wide_right_p(cell: &cell) -> bool { +pub fn cell_wide_right_p(cell: &Cell) -> bool { cell_double_wide_p(cell) && cell.gcluster == 0 } /// Is this the left half of a wide character? // TODO: TEST #[inline] -pub fn cell_wide_left_p(cell: &cell) -> bool { +pub fn cell_wide_left_p(cell: &Cell) -> bool { cell_double_wide_p(cell) && cell.gcluster != 0 } @@ -258,7 +256,7 @@ pub fn cell_wide_left_p(cell: &cell) -> bool { /// result is not tied to the ncplane, and persists across erases / destruction. // TODO: TEST #[inline] -pub fn cell_strdup(plane: &ncplane, cell: &cell) -> EGC { +pub fn cell_strdup(plane: &Plane, cell: &Cell) -> EGC { core::char::from_u32( unsafe { libc::strdup(nc::cell_extended_gcluster(plane, cell)) } as i32 as u32, ) @@ -274,8 +272,8 @@ pub fn cell_strdup(plane: &ncplane, cell: &cell) -> EGC { // TODO: TEST #[inline] pub fn cell_extract( - plane: &ncplane, - cell: &cell, + plane: &Plane, + cell: &Cell, stylemask: &mut StyleMask, channels: &mut ChannelPair, ) -> EGC { @@ -294,7 +292,7 @@ pub fn cell_extract( /// it would probably be better to test whether they're Unicode-equal FIXME. // TODO: TEST #[inline] -pub fn cellcmp(plane1: &ncplane, cell1: &cell, plane2: &ncplane, cell2: &cell) -> bool { +pub fn cellcmp(plane1: &Plane, cell1: &Cell, plane2: &Plane, cell2: &Cell) -> bool { if cell1.stylemask != cell2.stylemask { return true; } @@ -312,7 +310,7 @@ pub fn cellcmp(plane1: &ncplane, cell1: &cell, plane2: &ncplane, cell2: &cell) - // TODO: TEST // 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 Plane, cell: &mut Cell, ch: EGC) -> i32 { unsafe { nc::cell_release(plane, cell); } @@ -324,70 +322,70 @@ pub fn cell_load_simple(plane: &mut ncplane, cell: &mut cell, ch: EGC) -> i32 { /// Extract the 32-bit background channel from a cell. // TODO: TEST #[inline] -pub fn cell_bchannel(cell: &cell) -> Channel { +pub fn cell_bchannel(cell: &Cell) -> Channel { nc::channels_bchannel(cell.channels) } /// Extract the 32-bit foreground channel from a cell. // TODO: TEST #[inline] -pub fn cell_fchannel(cell: &cell) -> Channel { +pub fn cell_fchannel(cell: &Cell) -> Channel { nc::channels_fchannel(cell.channels) } /// Set the 32-bit background channel of a cell. // TODO: TEST #[inline] -pub fn cell_set_bchannel(cell: &mut cell, channel: Channel) -> ChannelPair { +pub fn cell_set_bchannel(cell: &mut Cell, channel: Channel) -> ChannelPair { nc::channels_set_bchannel(&mut cell.channels, channel) } /// Set the 32-bit foreground channel of a cell. // TODO: TEST #[inline] -pub fn cell_set_fchannel(cell: &mut cell, channel: Channel) -> ChannelPair { +pub fn cell_set_fchannel(cell: &mut Cell, channel: Channel) -> ChannelPair { nc::channels_set_fchannel(&mut cell.channels, channel) } /// Extract 24 bits of foreground RGB from 'cell', shifted to LSBs. // TODO: TEST #[inline] -pub fn cell_fg(cell: &cell) -> Channel { +pub fn cell_fg(cell: &Cell) -> Channel { nc::channels_fg(cell.channels) } /// Extract 24 bits of background RGB from 'cell', shifted to LSBs. // TODO: TEST #[inline] -pub fn cell_bg(cell: &cell) -> Channel { +pub fn cell_bg(cell: &Cell) -> Channel { nc::channels_bg(cell.channels) } /// Extract 2 bits of foreground alpha from 'cell', shifted to LSBs. // TODO: TEST #[inline] -pub fn cell_fg_alpha(cell: &cell) -> AlphaBits { +pub fn cell_fg_alpha(cell: &Cell) -> AlphaBits { nc::channels_fg_alpha(cell.channels) } /// Extract 2 bits of background alpha from 'cell', shifted to LSBs. // TODO: TEST #[inline] -pub fn cell_bg_alpha(cell: &cell) -> AlphaBits { +pub fn cell_bg_alpha(cell: &Cell) -> AlphaBits { nc::channels_bg_alpha(cell.channels) } /// Extract 24 bits of foreground RGB from 'cell', split into components. // TODO: TEST #[inline] -pub fn cell_fg_rgb(cell: &cell, red: &mut Color, green: &mut Color, blue: &mut Color) -> Channel { +pub fn cell_fg_rgb(cell: &Cell, red: &mut Color, green: &mut Color, blue: &mut Color) -> Channel { nc::channels_fg_rgb(cell.channels, red, green, blue) } /// Extract 24 bits of background RGB from 'cell', split into components. // TODO: TEST #[inline] -pub fn cell_bg_rgb(cell: &cell, red: &mut Color, green: &mut Color, blue: &mut Color) -> Channel { +pub fn cell_bg_rgb(cell: &Cell, red: &mut Color, green: &mut Color, blue: &mut Color) -> Channel { nc::channels_bg_rgb(cell.channels, red, green, blue) } @@ -395,14 +393,14 @@ pub fn cell_bg_rgb(cell: &cell, red: &mut Color, green: &mut Color, blue: &mut C /// 'cell' variable, and mark it as not using the default color. // TODO: TEST #[inline] -pub fn cell_set_fg_rgb(cell: &mut cell, red: Color, green: Color, blue: Color) { +pub fn cell_set_fg_rgb(cell: &mut Cell, red: Color, green: Color, blue: Color) { nc::channels_set_fg_rgb(&mut cell.channels, red, green, blue); } /// Same as `cell_set_fg_rgb()` but with an assembled 24-bit RGB value. // TODO: TEST #[inline] -pub fn cell_set_fg(cell: &mut cell, channel: Channel) { +pub fn cell_set_fg(cell: &mut Cell, channel: Channel) { nc::channels_set_fg(&mut cell.channels, channel); } @@ -412,7 +410,7 @@ pub fn cell_set_fg(cell: &mut cell, channel: Channel) { // TODO: TEST // NOTE: this function now can't fail #[inline] -pub fn cell_set_fg_palindex(cell: &mut cell, index: PaletteIndex) { +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); @@ -422,7 +420,7 @@ pub fn cell_set_fg_palindex(cell: &mut cell, index: PaletteIndex) { // TODO: TEST #[inline] -pub fn cell_fg_palindex(cell: &cell) -> PaletteIndex { +pub fn cell_fg_palindex(cell: &Cell) -> PaletteIndex { ((cell.channels & 0xff00000000_u64) >> 32) as PaletteIndex } @@ -431,7 +429,7 @@ pub fn cell_fg_palindex(cell: &cell) -> PaletteIndex { /// // TODO: TEST #[inline] -pub fn cell_set_bg_rgb(cell: &mut cell, red: Color, green: Color, blue: Color) { +pub fn cell_set_bg_rgb(cell: &mut Cell, red: Color, green: Color, blue: Color) { nc::channels_set_bg_rgb(&mut cell.channels, red, green, blue); } @@ -439,7 +437,7 @@ pub fn cell_set_bg_rgb(cell: &mut cell, red: Color, green: Color, blue: Color) { /// // TODO: TEST #[inline] -pub fn cell_set_bg(cell: &mut cell, channel: Channel) { +pub fn cell_set_bg(cell: &mut Cell, channel: Channel) { nc::channels_set_bg(&mut cell.channels, channel); } @@ -449,7 +447,7 @@ pub fn cell_set_bg(cell: &mut cell, channel: Channel) { // TODO: TEST // NOTE: this function now can't fail #[inline] -pub fn cell_set_bg_palindex(cell: &mut cell, index: PaletteIndex) { +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); @@ -459,19 +457,19 @@ pub fn cell_set_bg_palindex(cell: &mut cell, index: PaletteIndex) { // TODO: TEST #[inline] -pub fn cell_bg_palindex(cell: &cell) -> PaletteIndex { +pub fn cell_bg_palindex(cell: &Cell) -> PaletteIndex { (cell.channels & 0xff) as PaletteIndex } /// Is the foreground using the "default foreground color"? // TODO: TEST #[inline] -pub fn cell_fg_default_p(cell: &cell) -> bool { +pub fn cell_fg_default_p(cell: &Cell) -> bool { nc::channels_fg_default_p(cell.channels) } // TODO: TEST #[inline] -pub fn cell_fg_palindex_p(cell: &cell) -> bool { +pub fn cell_fg_palindex_p(cell: &Cell) -> bool { nc::channels_fg_palindex_p(cell.channels) } @@ -480,13 +478,13 @@ pub fn cell_fg_palindex_p(cell: &cell) -> bool { /// terminal-effected transparency. // TODO: TEST #[inline] -pub fn cell_bg_default_p(cell: &cell) -> bool { +pub fn cell_bg_default_p(cell: &Cell) -> bool { nc::channels_bg_default_p(cell.channels) } // TODO: TEST #[inline] -pub fn cell_bg_palindex_p(cell: &cell) -> bool { +pub fn cell_bg_palindex_p(cell: &Cell) -> bool { nc::channels_bg_palindex_p(cell.channels) } diff --git a/rust/src/channel.rs b/rust/src/channel.rs index 10a1dfa11..1247644e5 100644 --- a/rust/src/channel.rs +++ b/rust/src/channel.rs @@ -57,11 +57,9 @@ //+channels_set_fg_rgb //xchannels_set_fg_rgb_clipped -#![allow(dead_code)] - use crate as nc; -use crate::types::{AlphaBits, Channel, ChannelPair, Color, Rgb}; +use nc::types::{AlphaBits, Channel, ChannelPair, Color, Rgb}; /// Extract the 8-bit red component from a 32-bit channel. #[inline] diff --git a/rust/src/direct.rs b/rust/src/direct.rs index f09573b05..b5f9ee997 100644 --- a/rust/src/direct.rs +++ b/rust/src/direct.rs @@ -38,7 +38,7 @@ // use crate as nc; -use nc::ncdirect; +use nc::types::DirectMode; extern "C" { fn libc_stdout() -> *mut nc::_IO_FILE; @@ -52,7 +52,7 @@ extern "C" { /// and neither supports nor requires notcurses_render(). /// This can be 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_start() -> *mut ncdirect { +pub unsafe fn ncdirect_start() -> *mut DirectMode { nc::ncdirect_init(core::ptr::null(), libc_stdout()) } diff --git a/rust/src/macros.rs b/rust/src/macros.rs index 474f8e50a..89f90c8a8 100644 --- a/rust/src/macros.rs +++ b/rust/src/macros.rs @@ -1,8 +1,12 @@ -// #define CELL_INITIALIZER(c, s, chan) { .gcluster = (c), .gcluster_backstop = 0, .reserved = 0, .stylemask = (s), .channels = (chan), } +use crate as nc; + +#[allow(unused_imports)] +use nc::Cell; + #[macro_export] macro_rules! cell_initializer { ( $c:expr, $s:expr, $chan:expr ) => { - cell { + Cell { gcluster: $c as u32, gcluster_backstop: 0 as EGCBackstop, reserved: 0, @@ -12,7 +16,6 @@ macro_rules! cell_initializer { }; } -//#define CELL_SIMPLE_INITIALIZER(c) { .gcluster = (c), .gcluster_backstop = 0, .reserved = 0, .stylemask = 0, .channels = 0, } #[macro_export] macro_rules! cell_simple_initializer { ( $c:expr ) => { @@ -20,7 +23,6 @@ macro_rules! cell_simple_initializer { }; } -// #define CELL_TRIVIAL_INITIALIZER { } #[macro_export] macro_rules! cell_trivial_initializer { ( ) => { diff --git a/rust/src/palette.rs b/rust/src/palette.rs index 517a082da..3f3bb8241 100644 --- a/rust/src/palette.rs +++ b/rust/src/palette.rs @@ -18,14 +18,13 @@ //+palette256_set_rgb use crate as nc; -use crate::types::Color; -use nc::{Channel, PaletteIndex, Rgb}; +use nc::types::{Channel, Color, Palette, PaletteIndex, Rgb}; /// Set the different color components of an entry inside a palette store. // TODO: TEST #[inline] pub fn palette256_set_rgb( - palette: &mut nc::palette256, + palette: &mut Palette, idx: PaletteIndex, red: Color, green: Color, @@ -37,7 +36,7 @@ pub fn palette256_set_rgb( /// Same as `palette256_set_rgb()` but set an assembled 24 bit channel at once. // TODO: TEST #[inline] -pub fn palette256_set(palette: &mut nc::palette256, idx: PaletteIndex, rgb: Rgb) { +pub fn palette256_set(palette: &mut Palette, idx: PaletteIndex, rgb: Rgb) { nc::channel_set(&mut palette.chans[idx as usize], rgb); } @@ -45,7 +44,7 @@ pub fn palette256_set(palette: &mut nc::palette256, idx: PaletteIndex, rgb: Rgb) // TODO: TEST #[inline] pub fn palette256_get_rgb( - palette: &nc::palette256, + palette: &Palette, idx: PaletteIndex, red: &mut Color, green: &mut Color, diff --git a/rust/src/pixel.rs b/rust/src/pixel.rs index 888573369..c6cbb6708 100644 --- a/rust/src/pixel.rs +++ b/rust/src/pixel.rs @@ -28,7 +28,7 @@ //+ncpixel_set_rgb use crate as nc; -use nc::{Color, Pixel}; +use nc::types::{Color, Pixel}; // Pixel Structure: // diff --git a/rust/src/plane.rs b/rust/src/plane.rs index afc195c09..36b3ff635 100644 --- a/rust/src/plane.rs +++ b/rust/src/plane.rs @@ -142,8 +142,10 @@ use core::ptr::null_mut; use cstr_core::CString; use crate as nc; -use nc::types::{AlphaBits, Channel, ChannelPair, Color, EGCBackstop, IntResult, StyleMask, EGC}; -use nc::{cell, ncalign_e, ncplane}; +use nc::types::{ + Align, AlphaBits, Cell, Channel, ChannelPair, Color, EGCBackstop, IntResult, Plane, StyleMask, + ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, EGC, +}; /// Return the column at which 'cols' columns ought start in order to be aligned /// according to 'align' within ncplane 'n'. Returns INT_MAX on invalid 'align'. @@ -152,8 +154,8 @@ use nc::{cell, ncalign_e, ncplane}; // NOTE: [leave cols as i32](https://github.com/dankamongmen/notcurses/issues/904) // TODO: TEST #[inline] -pub fn ncplane_align(plane: &ncplane, align: ncalign_e, cols: i32) -> i32 { - if align == nc::ncalign_e_NCALIGN_LEFT { +pub fn ncplane_align(plane: &Plane, align: Align, cols: i32) -> i32 { + if align == ALIGN_LEFT { return 0; } @@ -162,9 +164,9 @@ pub fn ncplane_align(plane: &ncplane, align: ncalign_e, cols: i32) -> i32 { return 0; } - if align == nc::ncalign_e_NCALIGN_CENTER { + if align == ALIGN_CENTER { return plane_cols - cols / 2; - } else if align == nc::ncalign_e_NCALIGN_RIGHT { + } else if align == ALIGN_RIGHT { return plane_cols - cols; } core::i32::MAX @@ -174,7 +176,7 @@ pub fn ncplane_align(plane: &ncplane, align: ncalign_e, cols: i32) -> i32 { /// This cell is invalidated if the associated plane is destroyed. // TODO: TEST #[inline] -pub fn nplane_at_cursor_cell(plane: &mut ncplane, cell: &mut cell) -> IntResult { +pub fn nplane_at_cursor_cell(plane: &mut Plane, 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; @@ -192,7 +194,7 @@ pub fn nplane_at_cursor_cell(plane: &mut ncplane, cell: &mut cell) -> IntResult /// This cell is invalidated if the associated plane is destroyed. // TODO: TEST #[inline] -pub fn ncplane_at_yx_cell(plane: &mut ncplane, y: i32, x: i32, cell: &mut cell) -> IntResult { +pub fn ncplane_at_yx_cell(plane: &mut Plane, 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() { @@ -213,13 +215,13 @@ pub fn ncplane_at_yx_cell(plane: &mut ncplane, y: i32, x: i32, cell: &mut cell) // TODO: TEST #[inline] pub fn ncplane_box_sized( - plane: &mut ncplane, - ul: &cell, - ur: &cell, - ll: &cell, - lr: &cell, - hline: &cell, - vline: &cell, + plane: &mut Plane, + ul: &Cell, + ur: &Cell, + ll: &Cell, + lr: &Cell, + hline: &Cell, + vline: &Cell, ylen: i32, xlen: i32, ctlword: u32, @@ -245,7 +247,7 @@ pub fn ncplane_box_sized( /// // TODO: TEST #[inline] -pub fn ncplane_dim_x(plane: &ncplane) -> i32 { +pub fn ncplane_dim_x(plane: &Plane) -> i32 { unsafe { let mut x = 0; nc::ncplane_dim_yx(plane, null_mut(), &mut x); @@ -256,7 +258,7 @@ pub fn ncplane_dim_x(plane: &ncplane) -> i32 { /// // TODO: TEST #[inline] -pub fn ncplane_dim_y(plane: &ncplane) -> i32 { +pub fn ncplane_dim_y(plane: &Plane) -> i32 { unsafe { let mut y = 0; nc::ncplane_dim_yx(plane, &mut y, null_mut()); @@ -267,7 +269,7 @@ pub fn ncplane_dim_y(plane: &ncplane) -> i32 { // TODO: TEST #[inline] pub fn ncplane_double_box( - plane: &mut ncplane, + plane: &mut Plane, stylemask: StyleMask, channels: ChannelPair, ystop: i32, @@ -313,7 +315,7 @@ pub fn ncplane_double_box( // TODO: TEST #[inline] pub fn ncplane_double_box_sized( - plane: &mut ncplane, + plane: &mut Plane, stylemask: StyleMask, channels: ChannelPair, ylen: i32, @@ -337,7 +339,7 @@ pub fn ncplane_double_box_sized( /// On error, return the negative number of cells drawn. // TODO: TEST #[inline] -pub fn ncplane_hline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 { +pub fn ncplane_hline(plane: &mut Plane, cell: &Cell, len: i32) -> i32 { unsafe { nc::ncplane_hline_interp(plane, cell, len, cell.channels, cell.channels) } } @@ -345,13 +347,13 @@ pub fn ncplane_hline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 { // TODO: TEST #[inline] pub fn ncplane_perimeter( - plane: &mut ncplane, - ul: &cell, - ur: &cell, - ll: &cell, - lr: &cell, - hline: &cell, - vline: &cell, + plane: &mut Plane, + ul: &Cell, + ur: &Cell, + ll: &Cell, + lr: &Cell, + hline: &Cell, + vline: &Cell, ctlword: u32, ) -> IntResult { unsafe { @@ -365,7 +367,7 @@ pub fn ncplane_perimeter( // TODO: TEST #[inline] pub fn ncplane_perimeter_double( - plane: &mut ncplane, + plane: &mut Plane, stylemask: StyleMask, channels: ChannelPair, ctlword: u32, @@ -414,7 +416,7 @@ pub fn ncplane_perimeter_double( // TODO: TEST! #[inline] pub fn ncplane_perimeter_rounded( - plane: &mut ncplane, + plane: &mut Plane, stylemask: StyleMask, channels: ChannelPair, ctlword: u32, @@ -463,21 +465,21 @@ pub fn ncplane_perimeter_rounded( /// Call ncplane_putc_yx() for the current cursor location. // TODO: TEST #[inline] -pub fn ncplane_putc(plane: &mut ncplane, cell: &cell) -> IntResult { +pub fn ncplane_putc(plane: &mut Plane, cell: &Cell) -> IntResult { unsafe { nc::ncplane_putc_yx(plane, -1, -1, cell) } } /// Call ncplane_putsimple_yx() at the current cursor location. // TODO: TEST #[inline] -pub fn ncplane_putsimple(plane: &mut ncplane, ch: EGC) -> IntResult { +pub fn ncplane_putsimple(plane: &mut Plane, ch: EGC) -> IntResult { nc::ncplane_putsimple_yx(plane, -1, -1, ch) } /// Call ncplane_putegc() at the current cursor location. // TODO: TEST #[inline] -pub fn ncplane_putegc(plane: &mut ncplane, gcluster: i8, sbytes: &mut i32) -> IntResult { +pub fn ncplane_putegc(plane: &mut Plane, gcluster: i8, sbytes: &mut i32) -> IntResult { unsafe { nc::ncplane_putegc_yx(plane, -1, -1, &gcluster, sbytes) } } @@ -489,7 +491,7 @@ pub fn ncplane_putegc(plane: &mut ncplane, gcluster: i8, sbytes: &mut i32) -> In /// // TODO: TEST #[inline] -pub fn ncplane_putsimple_yx(plane: &mut ncplane, y: i32, x: i32, ch: EGC) -> IntResult { +pub fn ncplane_putsimple_yx(plane: &mut Plane, y: i32, x: i32, ch: EGC) -> IntResult { let newcell = cell_initializer![ch, unsafe { nc::ncplane_attr(plane) }, unsafe { nc::ncplane_channels(plane) }]; @@ -499,7 +501,7 @@ pub fn ncplane_putsimple_yx(plane: &mut ncplane, y: i32, x: i32, ch: EGC) -> Int /// // TODO: TEST #[inline] -pub fn ncplane_putstr(plane: &mut ncplane, gclustarr: &[u8]) -> IntResult { +pub fn ncplane_putstr(plane: &mut Plane, gclustarr: &[u8]) -> IntResult { unsafe { nc::ncplane_putstr_yx( plane, @@ -513,7 +515,7 @@ pub fn ncplane_putstr(plane: &mut ncplane, gclustarr: &[u8]) -> IntResult { /// // TODO: TEST #[inline] -pub fn ncplane_putnstr(plane: &mut ncplane, size: nc::size_t, gclustarr: &[u8]) -> IntResult { +pub fn ncplane_putnstr(plane: &mut Plane, size: nc::size_t, gclustarr: &[u8]) -> IntResult { unsafe { nc::ncplane_putnstr_yx( plane, @@ -529,7 +531,7 @@ pub fn ncplane_putnstr(plane: &mut ncplane, size: nc::size_t, gclustarr: &[u8]) /// shrinking in some dimension). Keep the origin where it is. // TODO: TEST #[inline] -pub fn ncplane_resize_simple(plane: &mut ncplane, ylen: i32, xlen: i32) -> IntResult { +pub fn ncplane_resize_simple(plane: &mut Plane, ylen: i32, xlen: i32) -> IntResult { let (mut oldy, mut oldx) = (0, 0); unsafe { nc::ncplane_dim_yx(plane, &mut oldy, &mut oldx); @@ -555,13 +557,13 @@ pub fn ncplane_resize_simple(plane: &mut ncplane, ylen: i32, xlen: i32) -> IntRe /// On error, return the negative number of cells drawn. // TODO: TEST #[inline] -pub fn ncplane_vline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 { +pub fn ncplane_vline(plane: &mut Plane, cell: &Cell, len: i32) -> i32 { unsafe { nc::ncplane_vline_interp(plane, cell, len, cell.channels, cell.channels) } } // TODO: TEST #[inline] -pub fn ncplane_vprintf(plane: &mut ncplane, format: &str, ap: &mut nc::__va_list_tag) -> IntResult { +pub fn ncplane_vprintf(plane: &mut Plane, format: &str, ap: &mut nc::__va_list_tag) -> IntResult { unsafe { nc::ncplane_vprintf_yx( plane, @@ -580,7 +582,7 @@ pub fn ncplane_vprintf(plane: &mut ncplane, format: &str, ap: &mut nc::__va_list // XXX receive cells as u32? https://github.com/dankamongmen/notcurses/issues/920 #[inline] pub fn ncplane_gradient_sized( - plane: &mut ncplane, + plane: &mut Plane, egc: &[u8], stylemask: StyleMask, ul: u64, @@ -613,56 +615,56 @@ pub fn ncplane_gradient_sized( /// Extract the 32-bit working foreground channel from an ncplane. // TODO: TEST #[inline] -pub fn ncplane_fchannel(plane: &ncplane) -> Channel { +pub fn ncplane_fchannel(plane: &Plane) -> Channel { nc::channels_fchannel(unsafe { nc::ncplane_channels(plane) }) } /// Extract the 32-bit working background channel from an ncplane. // TODO: TEST #[inline] -pub fn ncplane_bchannel(plane: &ncplane) -> Channel { +pub fn ncplane_bchannel(plane: &Plane) -> Channel { nc::channels_bchannel(unsafe { nc::ncplane_channels(plane) }) } /// Extract 24 bits of working foreground RGB from an ncplane, shifted to LSBs. // TODO: TEST #[inline] -pub fn ncplane_fg(plane: &ncplane) -> Channel { +pub fn ncplane_fg(plane: &Plane) -> Channel { nc::channels_fg(unsafe { nc::ncplane_channels(plane) }) } /// Extract 24 bits of working background RGB from an ncplane, shifted to LSBs. // TODO: TEST #[inline] -pub fn ncplane_bg(plane: &ncplane) -> Channel { +pub fn ncplane_bg(plane: &Plane) -> Channel { nc::channels_bg(unsafe { nc::ncplane_channels(plane) }) } /// Extract 2 bits of foreground alpha from 'struct ncplane', shifted to LSBs. // TODO: TEST #[inline] -pub fn ncplane_fg_alpha(plane: &ncplane) -> AlphaBits { +pub fn ncplane_fg_alpha(plane: &Plane) -> AlphaBits { nc::channels_fg_alpha(unsafe { nc::ncplane_channels(plane) }) } /// Extract 2 bits of background alpha from 'struct ncplane', shifted to LSBs. // TODO: TEST #[inline] -pub fn ncplane_bg_alpha(plane: &ncplane) -> AlphaBits { +pub fn ncplane_bg_alpha(plane: &Plane) -> AlphaBits { nc::channels_bg_alpha(unsafe { nc::ncplane_channels(plane) }) } /// Is the plane's foreground using the "default foreground color"? // TODO: TEST #[inline] -pub fn ncplane_fg_default_p(plane: &ncplane) -> bool { +pub fn ncplane_fg_default_p(plane: &Plane) -> bool { nc::channels_fg_default_p(unsafe { nc::ncplane_channels(plane) }) } /// Is the plane's background using the "default background color"? // TODO: TEST #[inline] -pub fn ncplane_bg_default_p(plane: &ncplane) -> bool { +pub fn ncplane_bg_default_p(plane: &Plane) -> bool { nc::channels_bg_default_p(unsafe { nc::ncplane_channels(plane) }) } @@ -670,7 +672,7 @@ pub fn ncplane_bg_default_p(plane: &ncplane) -> bool { // TODO: TEST #[inline] pub fn ncplane_fg_rgb( - plane: &ncplane, + plane: &Plane, red: &mut Color, green: &mut Color, blue: &mut Color, @@ -682,7 +684,7 @@ pub fn ncplane_fg_rgb( // TODO: TEST #[inline] pub fn ncplane_bg_rgb( - plane: &ncplane, + plane: &Plane, red: &mut Color, green: &mut Color, blue: &mut Color, @@ -693,7 +695,7 @@ pub fn ncplane_bg_rgb( // TODO: TEST #[inline] pub fn ncplane_rounded_box( - plane: &mut ncplane, + plane: &mut Plane, stylemask: StyleMask, channels: ChannelPair, ystop: i32, @@ -739,7 +741,7 @@ pub fn ncplane_rounded_box( // TODO: TEST #[inline] pub fn ncplane_rounded_box_sized( - plane: &mut ncplane, + plane: &mut Plane, stylemask: StyleMask, channels: ChannelPair, ylen: i32, diff --git a/rust/src/types.rs b/rust/src/types.rs index f5182a3d3..8beec6d3f 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -1,5 +1,6 @@ //! The notcurses types are defined and/or explained here //! +use crate as nc; /// RGB: 24 bits broken into 3x 8bpp channels. /// @@ -137,6 +138,7 @@ pub type Pixel = u32; // ~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB|~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB // // type in C: cell (struct) +pub type Cell = nc::cell; /// EGC (Extended Grapheme Cluster) /// @@ -199,6 +201,7 @@ pub type StyleMask = u16; // - EGCPool // // type in C: ncplane (struct) +pub type Plane = nc::ncplane; // EGCPool: contiguous region chopped up into NUL-terminated UTF8 EGCs, one per plane // @@ -210,7 +213,17 @@ pub type StyleMask = u16; /// 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; + +/// +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 DirectMode = nc::ncdirect;