rust: rename type aliases for consistency

Rename all bound types so that they start by Nc (and constants by NC),
except Notcurses:

- rename Cell to NcCell.
- rename CELL_* constants to NCCELL_*.
- rename Channel to NcChannel & Channels to NcChannels.
- rename CHANNEL_* constants to NCCHANNEL_*.
- rename Egc to NcChar & EgcBackstop to NcCharBackstop.
- rename Palette to NcPalette & PaletteIndex to NcPaletteIndex.
- rename IntResult to NcResult.
- rename Color to NcColor.
- rename Rgb to NcRgb.
- rename AlphaBits to NcAlphaBits.
- rename StyleMask to NcStyleMask.
- rename LIBC_FILE to FILE_LIBC & NC_FILE to FILE_NC.

Also:
- new type NcTime for timespec.
- rustfmt.
pull/1142/head
joseLuís 4 years ago
parent 1dda2d7d58
commit 8b6495a894

@ -27,11 +27,15 @@ pub mod bindgen {
// Miscellaneous ---------------------------------------------------------------
pub(crate) use bindgen::{
// structs
timespec,
};
#[doc(inline)]
pub use bindgen::{
// structs
__va_list_tag,
timespec,
// functions
ncstrwidth,

@ -66,9 +66,9 @@ use crate::{
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, 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,
NcAlphaBits, NcCell, NcChannel, NcChannels, NcChar, NcColor, NcPaletteIndex, NcPlane,
NcResult, NcStyleMask, NCCELL_ALPHA_OPAQUE, NCCELL_BGDEFAULT_MASK, NCCELL_BG_PALETTE,
NCCELL_FGDEFAULT_MASK, NCCELL_FG_PALETTE, NCCELL_NOBACKGROUND_MASK, NCCELL_WIDEASIAN_MASK,
},
NCSTYLE_MASK,
};
@ -87,22 +87,22 @@ use crate::{
#[allow(unused_unsafe)]
pub unsafe fn cell_prime(
plane: &mut NcPlane,
cell: &mut Cell,
gcluster: Egc,
style: StyleMask,
channels: Channels,
) -> IntResult {
cell: &mut NcCell,
gcluster: NcChar,
style: NcStyleMask,
channels: NcChannels,
) -> NcResult {
cell.stylemask = style;
cell.channels = channels;
unsafe { cell_load(plane, cell, gcluster as u32 as *const i8) }
}
/// load up six cells with the [Egc]s necessary to draw a box.
/// load up six cells with the [NcChar]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 `Egc`s in gcluster.
/// are cell_release()d. There must be at least six `NcChar`s in gcluster.
///
/// # Safety
///
@ -111,19 +111,19 @@ pub unsafe fn cell_prime(
#[allow(unused_unsafe)]
pub unsafe fn cells_load_box(
plane: &mut NcPlane,
style: StyleMask,
channels: Channels,
ul: &mut Cell,
ur: &mut Cell,
ll: &mut Cell,
lr: &mut Cell,
hl: &mut Cell,
vl: &mut Cell,
gcluster: Egc,
) -> IntResult {
style: NcStyleMask,
channels: NcChannels,
ul: &mut NcCell,
ur: &mut NcCell,
ll: &mut NcCell,
lr: &mut NcCell,
hl: &mut NcCell,
vl: &mut NcCell,
gcluster: NcChar,
) -> NcResult {
// mutable copy for pointer arithmetics:
let mut gclu = gcluster as u32 as *const i8;
let mut ulen: IntResult;
let mut ulen: NcResult;
ulen = unsafe { cell_prime(plane, ul, gcluster, style, channels) };
@ -176,7 +176,7 @@ pub unsafe fn cells_load_box(
///
#[inline]
pub fn cell_init(cell: &mut Cell) {
pub fn cell_init(cell: &mut NcCell) {
*cell = unsafe { core::mem::zeroed() }
}
@ -184,76 +184,76 @@ pub fn cell_init(cell: &mut Cell) {
/// supported or not. Only the lower 16 bits are meaningful.
/// static inline void
#[inline]
pub fn cell_styles_set(cell: &mut Cell, stylebits: StyleMask) {
pub fn cell_styles_set(cell: &mut NcCell, stylebits: NcStyleMask) {
cell.stylemask = stylebits & NCSTYLE_MASK as u16;
}
/// Extract the style bits from the cell.
#[inline]
pub fn cell_styles(cell: &Cell) -> StyleMask {
pub fn cell_styles(cell: &NcCell) -> NcStyleMask {
cell.stylemask
}
/// Add the specified styles (in the LSBs) to the cell's existing spec, whether
/// they're actively supported or not.
#[inline]
pub fn cell_styles_on(cell: &mut Cell, stylebits: StyleMask) {
pub fn cell_styles_on(cell: &mut NcCell, stylebits: NcStyleMask) {
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) {
pub fn cell_styles_off(cell: &mut NcCell, stylebits: NcStyleMask) {
cell.stylemask &= !(stylebits & NCSTYLE_MASK as u16);
}
/// Use the default color for the foreground.
#[inline]
pub fn cell_set_fg_default(cell: &mut Cell) {
pub fn cell_set_fg_default(cell: &mut NcCell) {
channels_set_fg_default(&mut cell.channels);
}
/// Use the default color for the background.
#[inline]
pub fn cell_set_bg_default(cell: &mut Cell) {
pub fn cell_set_bg_default(cell: &mut NcCell) {
channels_set_bg_default(&mut cell.channels);
}
/// Set the foreground alpha.
#[inline]
pub fn cell_set_fg_alpha(cell: &mut Cell, alpha: AlphaBits) {
pub fn cell_set_fg_alpha(cell: &mut NcCell, alpha: NcAlphaBits) {
channels_set_fg_alpha(&mut cell.channels, alpha);
}
/// Set the background alpha.
#[inline]
pub fn cell_set_bg_alpha(cell: &mut Cell, alpha: AlphaBits) {
pub fn cell_set_bg_alpha(cell: &mut NcCell, alpha: NcAlphaBits) {
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 & CELL_WIDEASIAN_MASK as Channels) != 0
pub fn cell_double_wide_p(cell: &NcCell) -> bool {
(cell.channels & NCCELL_WIDEASIAN_MASK as NcChannels) != 0
}
/// Is this the right half of a wide character?
#[inline]
pub fn cell_wide_right_p(cell: &Cell) -> bool {
pub fn cell_wide_right_p(cell: &NcCell) -> bool {
cell_double_wide_p(cell) && cell.gcluster == 0
}
/// Is this the left half of a wide character?
#[inline]
pub fn cell_wide_left_p(cell: &Cell) -> bool {
pub fn cell_wide_left_p(cell: &NcCell) -> 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 NcChar 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 {
pub fn cell_strdup(plane: &NcPlane, cell: &NcCell) -> NcChar {
core::char::from_u32(unsafe { libc::strdup(cell_extended_gcluster(plane, cell)) } as i32 as u32)
.expect("wrong char")
@ -267,10 +267,10 @@ pub fn cell_strdup(plane: &NcPlane, cell: &Cell) -> Egc {
#[inline]
pub fn cell_extract(
plane: &NcPlane,
cell: &Cell,
stylemask: &mut StyleMask,
channels: &mut Channels,
) -> Egc {
cell: &NcCell,
stylemask: &mut NcStyleMask,
channels: &mut NcChannels,
) -> NcChar {
if *stylemask != 0 {
*stylemask = cell.stylemask;
}
@ -280,12 +280,12 @@ pub fn cell_extract(
cell_strdup(plane, cell)
}
/// Returns true if the two cells are distinct `Egc`s, attributes, or channels.
/// Returns true if the two cells are distinct `NcChar`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 NcChar must be equal. The NcChar 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 {
pub fn cellcmp(plane1: &NcPlane, cell1: &NcCell, plane2: &NcPlane, cell2: &NcCell) -> bool {
if cell1.stylemask != cell2.stylemask {
return true;
}
@ -301,87 +301,97 @@ pub fn cellcmp(plane1: &NcPlane, cell1: &Cell, plane2: &NcPlane, cell2: &Cell) -
}
///
// NOTE: remove casting for CELL_WIDEASIAN_MASK when fixed: https://github.com/rust-lang/rust-bindgen/issues/1875
// NOTE: remove casting for NCCELL_WIDEASIAN_MASK when fixed: https://github.com/rust-lang/rust-bindgen/issues/1875
#[inline]
pub fn cell_load_char(plane: &mut NcPlane, cell: &mut Cell, ch: Egc) -> i32 {
pub fn cell_load_char(plane: &mut NcPlane, cell: &mut NcCell, ch: NcChar) -> i32 {
unsafe {
cell_release(plane, cell);
}
cell.channels &= !(CELL_WIDEASIAN_MASK as Channels | CELL_NOBACKGROUND_MASK);
cell.channels &= !(NCCELL_WIDEASIAN_MASK as NcChannels | NCCELL_NOBACKGROUND_MASK);
cell.gcluster = ch as u32;
1
}
/// Extract the 32-bit background channel from a cell.
#[inline]
pub fn cell_bchannel(cell: &Cell) -> Channel {
pub fn cell_bchannel(cell: &NcCell) -> NcChannel {
channels_bchannel(cell.channels)
}
/// Extract the 32-bit foreground channel from a cell.
#[inline]
pub fn cell_fchannel(cell: &Cell) -> Channel {
pub fn cell_fchannel(cell: &NcCell) -> NcChannel {
channels_fchannel(cell.channels)
}
/// Set the 32-bit background channel of a cell.
#[inline]
pub fn cell_set_bchannel(cell: &mut Cell, channel: Channel) -> Channels {
pub fn cell_set_bchannel(cell: &mut NcCell, channel: NcChannel) -> NcChannels {
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) -> Channels {
pub fn cell_set_fchannel(cell: &mut NcCell, channel: NcChannel) -> NcChannels {
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 {
pub fn cell_fg_rgb(cell: &NcCell) -> NcChannel {
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 {
pub fn cell_bg_rgb(cell: &NcCell) -> NcChannel {
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 {
pub fn cell_fg_alpha(cell: &NcCell) -> NcAlphaBits {
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 {
pub fn cell_bg_alpha(cell: &NcCell) -> NcAlphaBits {
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 {
pub fn cell_fg_rgb8(
cell: &NcCell,
red: &mut NcColor,
green: &mut NcColor,
blue: &mut NcColor,
) -> NcChannel {
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 {
pub fn cell_bg_rgb8(
cell: &NcCell,
red: &mut NcColor,
green: &mut NcColor,
blue: &mut NcColor,
) -> NcChannel {
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) {
pub fn cell_set_fg_rgb8(cell: &mut NcCell, red: NcColor, green: NcColor, blue: NcColor) {
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) {
pub fn cell_set_fg_rgb(cell: &mut NcCell, channel: NcChannel) {
channels_set_fg_rgb(&mut cell.channels, channel);
}
@ -390,32 +400,32 @@ 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 |= CELL_FGDEFAULT_MASK;
cell.channels |= CELL_FG_PALETTE;
cell_set_fg_alpha(cell, CELL_ALPHA_OPAQUE);
cell.channels &= 0xff000000ffffffff as Channels;
cell.channels |= (index as Channels) << 32;
pub fn cell_set_fg_palindex(cell: &mut NcCell, index: NcPaletteIndex) {
cell.channels |= NCCELL_FGDEFAULT_MASK;
cell.channels |= NCCELL_FG_PALETTE;
cell_set_fg_alpha(cell, NCCELL_ALPHA_OPAQUE);
cell.channels &= 0xff000000ffffffff as NcChannels;
cell.channels |= (index as NcChannels) << 32;
}
///
#[inline]
pub fn cell_fg_palindex(cell: &Cell) -> PaletteIndex {
((cell.channels & 0xff00000000 as Channels) >> 32) as PaletteIndex
pub fn cell_fg_palindex(cell: &NcCell) -> NcPaletteIndex {
((cell.channels & 0xff00000000 as NcChannels) >> 32) as NcPaletteIndex
}
/// Set the r, g, and b cell for the background component of this 64-bit
/// 'cell' variable, and mark it as not using the default color.
///
#[inline]
pub fn cell_set_bg_rgb8(cell: &mut Cell, red: Color, green: Color, blue: Color) {
pub fn cell_set_bg_rgb8(cell: &mut NcCell, red: NcColor, green: NcColor, blue: NcColor) {
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) {
pub fn cell_set_bg_rgb(cell: &mut NcCell, channel: NcChannel) {
channels_set_bg_rgb(&mut cell.channels, channel);
}
@ -424,29 +434,29 @@ 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 |= CELL_BGDEFAULT_MASK as Channels;
cell.channels |= CELL_BG_PALETTE as Channels;
cell_set_bg_alpha(cell, CELL_ALPHA_OPAQUE);
pub fn cell_set_bg_palindex(cell: &mut NcCell, index: NcPaletteIndex) {
cell.channels |= NCCELL_BGDEFAULT_MASK as NcChannels;
cell.channels |= NCCELL_BG_PALETTE as NcChannels;
cell_set_bg_alpha(cell, NCCELL_ALPHA_OPAQUE);
cell.channels &= 0xffffffffff000000;
cell.channels |= index as Channels;
cell.channels |= index as NcChannels;
}
///
#[inline]
pub fn cell_bg_palindex(cell: &Cell) -> PaletteIndex {
(cell.channels & 0xff) as PaletteIndex
pub fn cell_bg_palindex(cell: &NcCell) -> NcPaletteIndex {
(cell.channels & 0xff) as NcPaletteIndex
}
/// Is the foreground using the "default foreground color"?
#[inline]
pub fn cell_fg_default_p(cell: &Cell) -> bool {
pub fn cell_fg_default_p(cell: &NcCell) -> bool {
channels_fg_default_p(cell.channels)
}
///
#[inline]
pub fn cell_fg_palindex_p(cell: &Cell) -> bool {
pub fn cell_fg_palindex_p(cell: &NcCell) -> bool {
channels_fg_palindex_p(cell.channels)
}
@ -454,13 +464,13 @@ pub fn cell_fg_palindex_p(cell: &Cell) -> bool {
/// background color" must generally be used to take advantage of
/// terminal-effected transparency.
#[inline]
pub fn cell_bg_default_p(cell: &Cell) -> bool {
pub fn cell_bg_default_p(cell: &NcCell) -> bool {
channels_bg_default_p(cell.channels)
}
///
#[inline]
pub fn cell_bg_palindex_p(cell: &Cell) -> bool {
pub fn cell_bg_palindex_p(cell: &NcCell) -> bool {
channels_bg_palindex_p(cell.channels)
}

@ -61,31 +61,37 @@
//X channels_set_fg_rgb8_clipped
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,
NcAlphaBits, NcChannel, NcChannels, NcColor, NcRgb, NCCELL_ALPHA_HIGHCONTRAST,
NCCELL_ALPHA_OPAQUE, NCCELL_BGDEFAULT_MASK, NCCELL_BG_PALETTE, NCCELL_BG_RGB_MASK,
NCCHANNEL_ALPHA_MASK,
};
/// Extract the 8-bit red component from a 32-bit channel.
#[inline]
pub fn channel_r(channel: Channel) -> Color {
((channel & 0xff0000) >> 16) as Color
pub fn channel_r(channel: NcChannel) -> NcColor {
((channel & 0xff0000) >> 16) as NcColor
}
/// Extract the 8-bit green component from a 32-bit channel.
#[inline]
pub fn channel_g(channel: Channel) -> Color {
((channel & 0x00ff00) >> 8) as Color
pub fn channel_g(channel: NcChannel) -> NcColor {
((channel & 0x00ff00) >> 8) as NcColor
}
/// Extract the 8-bit blue component from a 32-bit channel.
#[inline]
pub fn channel_b(channel: Channel) -> Color {
(channel & 0x0000ff) as Color
pub fn channel_b(channel: NcChannel) -> NcColor {
(channel & 0x0000ff) as NcColor
}
/// Extract the three 8-bit R/G/B components from a 32-bit channel.
#[inline]
pub fn channel_rgb8(channel: Channel, r: &mut Color, g: &mut Color, b: &mut Color) -> Channel {
pub fn channel_rgb8(
channel: NcChannel,
r: &mut NcColor,
g: &mut NcColor,
b: &mut NcColor,
) -> NcChannel {
*r = channel_r(channel);
*g = channel_g(channel);
*b = channel_b(channel);
@ -95,84 +101,84 @@ pub fn channel_rgb8(channel: Channel, r: &mut Color, g: &mut Color, b: &mut Colo
/// Set the three 8-bit components of a 32-bit channel, and mark it as not using
/// the default color. Retain the other bits unchanged.
#[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 & !CELL_BG_RGB_MASK) | CELL_BGDEFAULT_MASK | rgb;
pub fn channel_set_rgb8(channel: &mut NcChannel, r: NcColor, g: NcColor, b: NcColor) {
let rgb: NcRgb = (r as NcChannel) << 16 | (g as NcChannel) << 8 | (b as NcChannel);
*channel = (*channel & !NCCELL_BG_RGB_MASK) | NCCELL_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 & !CELL_BG_RGB_MASK) | CELL_BGDEFAULT_MASK | (rgb & 0x00ffffff);
pub fn channel_set(channel: &mut NcChannel, rgb: NcRgb) {
*channel = (*channel & !NCCELL_BG_RGB_MASK) | NCCELL_BGDEFAULT_MASK | (rgb & 0x00ffffff);
}
/// Extract the 2-bit alpha component from a 32-bit channel.
#[inline]
pub fn channel_alpha(channel: Channel) -> AlphaBits {
channel & CHANNEL_ALPHA_MASK
pub fn channel_alpha(channel: NcChannel) -> NcAlphaBits {
channel & NCCHANNEL_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 & CHANNEL_ALPHA_MASK;
*channel = alpha_clean | (*channel & !CHANNEL_ALPHA_MASK);
pub fn channel_set_alpha(channel: &mut NcChannel, alpha: NcAlphaBits) {
let alpha_clean = alpha & NCCHANNEL_ALPHA_MASK;
*channel = alpha_clean | (*channel & !NCCHANNEL_ALPHA_MASK);
if alpha != CELL_ALPHA_OPAQUE {
if alpha != NCCELL_ALPHA_OPAQUE {
// indicate that we are *not* using the default background color
*channel |= CELL_BGDEFAULT_MASK;
*channel |= NCCELL_BGDEFAULT_MASK;
}
}
/// Is this channel using the "default color" rather than RGB/palette-indexed?
#[inline]
pub fn channel_default_p(channel: Channel) -> bool {
(channel & CELL_BGDEFAULT_MASK) == 0
pub fn channel_default_p(channel: NcChannel) -> bool {
(channel & NCCELL_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 & CELL_BG_PALETTE) == 0
pub fn channel_palindex_p(channel: NcChannel) -> bool {
!channel_default_p(channel) && (channel & NCCELL_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 &= !(CELL_BGDEFAULT_MASK | CELL_ALPHA_HIGHCONTRAST); // < NOTE shouldn't be better CHANNEL_ALPHA_MASK?
pub fn channel_set_default(channel: &mut NcChannel) -> NcChannel {
*channel &= !(NCCELL_BGDEFAULT_MASK | NCCELL_ALPHA_HIGHCONTRAST); // < NOTE shouldn't be better NCCHANNEL_ALPHA_MASK?
*channel
}
/// Extract the 32-bit background channel from a channel pair.
#[inline]
pub fn channels_bchannel(channels: Channels) -> Channel {
(channels & 0xffffffff_u64) as Channel
pub fn channels_bchannel(channels: NcChannels) -> NcChannel {
(channels & 0xffffffff_u64) as NcChannel
}
/// Extract the 32-bit foreground channel from a channel pair.
#[inline]
pub fn channels_fchannel(channels: Channels) -> Channel {
pub fn channels_fchannel(channels: NcChannels) -> NcChannel {
channels_bchannel(channels >> 32)
}
/// Set the 32-bit background channel of a channel pair.
#[inline]
pub fn channels_set_bchannel(channels: &mut Channels, bchannel: Channel) -> Channels {
pub fn channels_set_bchannel(channels: &mut NcChannels, bchannel: NcChannel) -> NcChannels {
*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 Channels, fchannel: Channel) -> Channels {
pub fn channels_set_fchannel(channels: &mut NcChannels, fchannel: NcChannel) -> NcChannels {
*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) -> Channels {
let mut channels: Channels = 0;
pub fn channels_combine(fchannel: NcChannel, bchannel: NcChannel) -> NcChannels {
let mut channels: NcChannels = 0;
channels_set_fchannel(&mut channels, fchannel);
channels_set_bchannel(&mut channels, bchannel);
channels
@ -180,54 +186,54 @@ pub fn channels_combine(fchannel: Channel, bchannel: Channel) -> Channels {
/// Extract 24 bits of foreground RGB from 'channels', shifted to LSBs.
#[inline]
pub fn channels_fg_rgb(channels: Channels) -> Channel {
channels_fchannel(channels) & CELL_BG_RGB_MASK
pub fn channels_fg_rgb(channels: NcChannels) -> NcChannel {
channels_fchannel(channels) & NCCELL_BG_RGB_MASK
}
/// Extract 24 bits of background RGB from 'channels', shifted to LSBs.
#[inline]
pub fn channels_bg_rgb(channels: Channels) -> Channel {
channels_bchannel(channels) & CELL_BG_RGB_MASK
pub fn channels_bg_rgb(channels: NcChannels) -> NcChannel {
channels_bchannel(channels) & NCCELL_BG_RGB_MASK
}
/// Extract 2 bits of foreground alpha from 'channels', shifted to LSBs.
#[inline]
pub fn channels_fg_alpha(channels: Channels) -> AlphaBits {
pub fn channels_fg_alpha(channels: NcChannels) -> NcAlphaBits {
channel_alpha(channels_fchannel(channels))
}
/// Extract 2 bits of background alpha from 'channels', shifted to LSBs.
#[inline]
pub fn channels_bg_alpha(channels: Channels) -> AlphaBits {
pub fn channels_bg_alpha(channels: NcChannels) -> NcAlphaBits {
channel_alpha(channels_bchannel(channels))
}
/// Extract 24 bits of foreground RGB from 'channels', split into subchannels.
#[inline]
pub fn channels_fg_rgb8(
channels: Channels,
r: &mut Color,
g: &mut Color,
b: &mut Color,
) -> Channel {
channels: NcChannels,
r: &mut NcColor,
g: &mut NcColor,
b: &mut NcColor,
) -> NcChannel {
channel_rgb8(channels_fchannel(channels), r, g, b)
}
/// Extract 24 bits of background RGB from 'channels', split into subchannels.
#[inline]
pub fn channels_bg_rgb8(
channels: Channels,
r: &mut Color,
g: &mut Color,
b: &mut Color,
) -> Channel {
channels: NcChannels,
r: &mut NcColor,
g: &mut NcColor,
b: &mut NcColor,
) -> NcChannel {
channel_rgb8(channels_bchannel(channels), r, g, b)
}
/// 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 Channels, r: Color, g: Color, b: Color) {
pub fn channels_set_fg_rgb8(channels: &mut NcChannels, r: NcColor, g: NcColor, b: NcColor) {
let mut channel = channels_fchannel(*channels);
channel_set_rgb8(&mut channel, r, g, b);
*channels = (channel as u64) << 32 | *channels & 0xffffffff_u64;
@ -235,7 +241,7 @@ pub fn channels_set_fg_rgb8(channels: &mut Channels, r: Color, g: Color, b: Colo
/// Same as channels_set_fg_rgb8 but set an assembled 24 bit channel at once.
#[inline]
pub fn channels_set_fg_rgb(channels: &mut Channels, rgb: Rgb) {
pub fn channels_set_fg_rgb(channels: &mut NcChannels, rgb: NcRgb) {
let mut channel = channels_fchannel(*channels);
channel_set(&mut channel, rgb);
*channels = (channel as u64) << 32 | *channels & 0xffffffff_u64;
@ -244,7 +250,7 @@ pub fn channels_set_fg_rgb(channels: &mut Channels, 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 Channels, r: Color, g: Color, b: Color) {
pub fn channels_set_bg_rgb8(channels: &mut NcChannels, r: NcColor, g: NcColor, b: NcColor) {
let mut channel = channels_bchannel(*channels);
channel_set_rgb8(&mut channel, r, g, b);
channels_set_bchannel(channels, channel);
@ -252,7 +258,7 @@ pub fn channels_set_bg_rgb8(channels: &mut Channels, r: Color, g: Color, b: Colo
/// Same as channels_set_bg_rgb8 but set an assembled 24 bit channel at once.
#[inline]
pub fn channels_set_bg_rgb(channels: &mut Channels, rgb: Rgb) {
pub fn channels_set_bg_rgb(channels: &mut NcChannels, rgb: NcRgb) {
let mut channel = channels_bchannel(*channels);
channel_set(&mut channel, rgb);
channels_set_bchannel(channels, channel);
@ -260,19 +266,19 @@ pub fn channels_set_bg_rgb(channels: &mut Channels, rgb: Rgb) {
/// Set the 2-bit alpha component of the foreground channel.
#[inline]
pub fn channels_set_fg_alpha(channels: &mut Channels, alpha: AlphaBits) {
pub fn channels_set_fg_alpha(channels: &mut NcChannels, alpha: NcAlphaBits) {
let mut channel = channels_fchannel(*channels);
channel_set_alpha(&mut channel, alpha);
*channels = (channel as Channels) << 32 | *channels & 0xffffffff_u64;
*channels = (channel as NcChannels) << 32 | *channels & 0xffffffff_u64;
}
/// Set the 2-bit alpha component of the background channel.
#[inline]
pub fn channels_set_bg_alpha(channels: &mut Channels, alpha: AlphaBits) {
pub fn channels_set_bg_alpha(channels: &mut NcChannels, alpha: NcAlphaBits) {
let mut alpha_clean = alpha;
if alpha == CELL_ALPHA_HIGHCONTRAST {
if alpha == NCCELL_ALPHA_HIGHCONTRAST {
// forbidden for background alpha, so makes it opaque
alpha_clean = CELL_ALPHA_OPAQUE;
alpha_clean = NCCELL_ALPHA_OPAQUE;
}
let mut channel = channels_bchannel(*channels);
channel_set_alpha(&mut channel, alpha_clean);
@ -281,13 +287,13 @@ pub fn channels_set_bg_alpha(channels: &mut Channels, alpha: AlphaBits) {
/// Is the foreground using the "default foreground color"?
#[inline]
pub fn channels_fg_default_p(channels: Channels) -> bool {
pub fn channels_fg_default_p(channels: NcChannels) -> bool {
channel_default_p(channels_fchannel(channels))
}
/// Is the foreground using indexed palette color?
#[inline]
pub fn channels_fg_palindex_p(channels: Channels) -> bool {
pub fn channels_fg_palindex_p(channels: NcChannels) -> bool {
channel_palindex_p(channels_fchannel(channels))
}
@ -295,19 +301,19 @@ pub fn channels_fg_palindex_p(channels: Channels) -> bool {
/// background color" must generally be used to take advantage of
/// terminal-effected transparency.
#[inline]
pub fn channels_bg_default_p(channels: Channels) -> bool {
pub fn channels_bg_default_p(channels: NcChannels) -> bool {
channel_default_p(channels_bchannel(channels))
}
/// Is the background using indexed palette color?
#[inline]
pub fn channels_bg_palindex_p(channels: Channels) -> bool {
pub fn channels_bg_palindex_p(channels: NcChannels) -> 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 Channels) -> Channels {
pub fn channels_set_fg_default(channels: &mut NcChannels) -> NcChannels {
let mut channel = channels_fchannel(*channels);
channel_set_default(&mut channel);
*channels = (channel as u64) << 32 | *channels & 0xffffffff_u64;
@ -316,7 +322,7 @@ pub fn channels_set_fg_default(channels: &mut Channels) -> Channels {
/// Mark the background channel as using its default color.
#[inline]
pub fn channels_set_bg_default(channels: &mut Channels) -> Channels {
pub fn channels_set_bg_default(channels: &mut NcChannels) -> NcChannels {
let mut channel = channels_bchannel(*channels);
channel_set_default(&mut channel);
channels_set_bchannel(channels, channel);
@ -325,34 +331,35 @@ pub fn channels_set_bg_default(channels: &mut Channels) -> Channels {
#[cfg(test)]
mod test {
use super::{Channel, Channels};
use super::{NcChannel, NcChannels};
use crate::types::{
CELL_ALPHA_BLEND, CELL_ALPHA_HIGHCONTRAST, CELL_ALPHA_OPAQUE, CELL_ALPHA_TRANSPARENT,
NCCELL_ALPHA_BLEND, NCCELL_ALPHA_HIGHCONTRAST, NCCELL_ALPHA_OPAQUE,
NCCELL_ALPHA_TRANSPARENT,
};
use serial_test::serial;
#[test]
#[serial]
fn channel_r() {
let c: Channel = 0x112233;
let c: NcChannel = 0x112233;
assert_eq!(super::channel_r(c), 0x11);
}
#[test]
#[serial]
fn channel_g() {
let c: Channel = 0x112233;
let c: NcChannel = 0x112233;
assert_eq!(super::channel_g(c), 0x22);
}
#[test]
#[serial]
fn channel_b() {
let c: Channel = 0x112233;
let c: NcChannel = 0x112233;
assert_eq!(super::channel_b(c), 0x33);
}
#[test]
#[serial]
fn channel_rgb8() {
let c: Channel = 0x112233;
let c: NcChannel = 0x112233;
let mut r = 0;
let mut g = 0;
let mut b = 0;
@ -364,7 +371,7 @@ mod test {
#[test]
#[serial]
fn channel_set_rgb8() {
let mut c: Channel = 0x000000;
let mut c: NcChannel = 0x000000;
super::channel_set_rgb8(&mut c, 0x11, 0x22, 0x33);
assert_eq!(super::channel_r(c), 0x11);
assert_eq!(super::channel_g(c), 0x22);
@ -373,33 +380,33 @@ mod test {
#[test]
#[serial]
fn channel_alpha() {
let c: Channel = 0x112233 | CELL_ALPHA_TRANSPARENT;
assert_eq!(super::channel_alpha(c), CELL_ALPHA_TRANSPARENT);
let c: NcChannel = 0x112233 | NCCELL_ALPHA_TRANSPARENT;
assert_eq!(super::channel_alpha(c), NCCELL_ALPHA_TRANSPARENT);
}
#[test]
#[serial]
fn channel_set_alpha() {
let mut c: Channel = 0x112233;
super::channel_set_alpha(&mut c, CELL_ALPHA_HIGHCONTRAST);
assert_eq!(CELL_ALPHA_HIGHCONTRAST, super::channel_alpha(c));
let mut c: NcChannel = 0x112233;
super::channel_set_alpha(&mut c, NCCELL_ALPHA_HIGHCONTRAST);
assert_eq!(NCCELL_ALPHA_HIGHCONTRAST, 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, NCCELL_ALPHA_TRANSPARENT);
assert_eq!(NCCELL_ALPHA_TRANSPARENT, 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, NCCELL_ALPHA_BLEND);
assert_eq!(NCCELL_ALPHA_BLEND, super::channel_alpha(c));
super::channel_set_alpha(&mut c, CELL_ALPHA_OPAQUE);
assert_eq!(CELL_ALPHA_OPAQUE, super::channel_alpha(c));
// TODO: CHECK for CELL_BGDEFAULT_MASK
super::channel_set_alpha(&mut c, NCCELL_ALPHA_OPAQUE);
assert_eq!(NCCELL_ALPHA_OPAQUE, super::channel_alpha(c));
// TODO: CHECK for NCCELL_BGDEFAULT_MASK
}
#[test]
#[serial]
fn channel_set_default() {
const DEFAULT: Channel = 0x112233;
const DEFAULT: NcChannel = 0x112233;
let mut c: Channel = DEFAULT | CELL_ALPHA_TRANSPARENT;
let mut c: NcChannel = DEFAULT | NCCELL_ALPHA_TRANSPARENT;
assert!(c != DEFAULT);
super::channel_set_default(&mut c);
@ -409,22 +416,22 @@ mod test {
#[test]
#[serial]
fn channel_default_p() {
let mut c: Channel = 0x112233;
let mut c: NcChannel = 0x112233;
assert_eq!(true, super::channel_default_p(c));
// TODO FIXME: test for the false result
// let _ = super::channel_set_alpha(&mut c, CELL_ALPHA_TRANSPARENT);
// let _ = super::channel_set_alpha(&mut c, NCCELL_ALPHA_TRANSPARENT);
// assert_eq!(false, super::channel_default_p(c));
let _ = super::channel_set_alpha(&mut c, CELL_ALPHA_OPAQUE);
let _ = super::channel_set_alpha(&mut c, NCCELL_ALPHA_OPAQUE);
assert_eq!(true, super::channel_default_p(c));
}
#[test]
#[serial]
#[allow(non_snake_case)]
fn channels_set_fchannel__channels_fchannel() {
let fc: Channel = 0x112233;
let mut cp: Channels = 0;
let fc: NcChannel = 0x112233;
let mut cp: NcChannels = 0;
super::channels_set_fchannel(&mut cp, fc);
assert_eq!(super::channels_fchannel(cp), fc);
}
@ -432,18 +439,18 @@ mod test {
#[serial]
#[allow(non_snake_case)]
fn channels_set_bchannel__channels_bchannel() {
let bc: Channel = 0x112233;
let mut cp: Channels = 0;
let bc: NcChannel = 0x112233;
let mut cp: NcChannels = 0;
super::channels_set_bchannel(&mut cp, bc);
assert_eq!(super::channels_bchannel(cp), bc);
}
#[test]
#[serial]
fn channels_combine() {
let bc: Channel = 0x112233;
let fc: Channel = 0x445566;
let mut cp1: Channels = 0;
let mut _cp2: Channels = 0;
let bc: NcChannel = 0x112233;
let fc: NcChannel = 0x445566;
let mut cp1: NcChannels = 0;
let mut _cp2: NcChannels = 0;
super::channels_set_bchannel(&mut cp1, bc);
super::channels_set_fchannel(&mut cp1, fc);
_cp2 = super::channels_combine(fc, bc);

@ -1,16 +1,16 @@
#[allow(unused_imports)]
use crate::Cell;
use crate::{NcCell, NcChannels, NcChar, NcStyleMask};
// Cell ------------------------------------------------------------------------
// NcCell ------------------------------------------------------------------------
/// Initializes a cell providing an [`Egc`],
/// a [`StyleMask`] and [`Channels`]
/// Initializes a cell providing an [`NcChar`],
/// a [`NcStyleMask`] and [`NcChannels`]
#[macro_export]
macro_rules! cell_initializer {
( $c:expr, $s:expr, $chan:expr ) => {
Cell {
NcCell {
gcluster: $c as u32,
gcluster_backstop: 0 as EgcBackstop,
gcluster_backstop: 0 as NcCharBackstop,
reserved: 0,
stylemask: $s,
channels: $chan,
@ -18,7 +18,7 @@ macro_rules! cell_initializer {
};
}
/// Initializes a cell providing just an [`Egc`],
/// Initializes a cell providing just an [`NcChar`],
#[macro_export]
macro_rules! cell_char_initializer {
( $c:expr ) => {

@ -19,36 +19,36 @@
use crate::{
channel_rgb8, channel_set, channel_set_rgb8,
types::{Channel, Color, Palette, PaletteIndex, Rgb},
types::{NcChannel, NcColor, NcPalette, NcPaletteIndex, NcRgb},
};
/// Set the different color components of an entry inside a palette store.
#[inline]
pub fn palette256_set_rgb(
palette: &mut Palette,
idx: PaletteIndex,
red: Color,
green: Color,
blue: Color,
palette: &mut NcPalette,
idx: NcPaletteIndex,
red: NcColor,
green: NcColor,
blue: NcColor,
) {
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) {
pub fn palette256_set(palette: &mut NcPalette, idx: NcPaletteIndex, rgb: NcRgb) {
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.
#[inline]
pub fn palette256_get_rgb(
palette: &Palette,
idx: PaletteIndex,
red: &mut Color,
green: &mut Color,
blue: &mut Color,
) -> Channel {
palette: &NcPalette,
idx: NcPaletteIndex,
red: &mut NcColor,
green: &mut NcColor,
blue: &mut NcColor,
) -> NcChannel {
channel_rgb8(palette.chans[idx as usize], red, green, blue)
}

@ -27,7 +27,7 @@
//+ ncpixel_set_r
//+ ncpixel_set_rgb
use crate::types::{Color, NcPixel};
use crate::types::{NcColor, NcPixel};
// NcPixel Structure:
//
@ -37,52 +37,52 @@ use crate::types::{Color, NcPixel};
// 0x000000ff 8 bit Red
/// Get an RGB pixel from RGB values
pub fn ncpixel(r: Color, g: Color, b: Color) -> NcPixel {
pub fn ncpixel(r: NcColor, g: NcColor, b: NcColor) -> NcPixel {
0xff000000 as NcPixel | r as NcPixel | (b as NcPixel) << 8 | (g as NcPixel) << 16
}
/// Extract the 8-bit alpha component from a pixel
pub fn ncpixel_a(pixel: NcPixel) -> Color {
((pixel & 0xff000000) >> 24) as Color
pub fn ncpixel_a(pixel: NcPixel) -> NcColor {
((pixel & 0xff000000) >> 24) as NcColor
}
/// Extract the 8 bit green component from a pixel
pub fn ncpixel_g(pixel: NcPixel) -> Color {
((pixel & 0x00ff0000) >> 16) as Color
pub fn ncpixel_g(pixel: NcPixel) -> NcColor {
((pixel & 0x00ff0000) >> 16) as NcColor
}
/// Extract the 8 bit blue component from a pixel
pub fn ncpixel_b(pixel: NcPixel) -> Color {
((pixel & 0x0000ff00) >> 8) as Color
pub fn ncpixel_b(pixel: NcPixel) -> NcColor {
((pixel & 0x0000ff00) >> 8) as NcColor
}
/// Extract the 8 bit red component from a pixel
pub fn ncpixel_r(pixel: NcPixel) -> Color {
(pixel & 0x000000ff) as Color
pub fn ncpixel_r(pixel: NcPixel) -> NcColor {
(pixel & 0x000000ff) as NcColor
}
/// Set the 8-bit alpha component of a pixel
pub fn ncpixel_set_a(pixel: &mut NcPixel, alpha: Color) {
pub fn ncpixel_set_a(pixel: &mut NcPixel, alpha: NcColor) {
*pixel = (*pixel & 0x00ffffff) | ((alpha as NcPixel) << 24);
}
/// Set the 8-bit green component of a pixel
pub fn ncpixel_set_g(pixel: &mut NcPixel, green: Color) {
pub fn ncpixel_set_g(pixel: &mut NcPixel, green: NcColor) {
*pixel = (*pixel & 0xff00ffff) | ((green as NcPixel) << 16);
}
/// Set the 8-bit blue component of a pixel
pub fn ncpixel_set_b(pixel: &mut NcPixel, blue: Color) {
pub fn ncpixel_set_b(pixel: &mut NcPixel, blue: NcColor) {
*pixel = (*pixel & 0xffff00ff) | ((blue as NcPixel) << 8);
}
/// Set the 8-bit red component of a pixel
pub fn ncpixel_set_r(pixel: &mut NcPixel, red: Color) {
pub fn ncpixel_set_r(pixel: &mut NcPixel, red: NcColor) {
*pixel = (*pixel & 0xffffff00) | red as NcPixel;
}
/// set the RGB values of an RGB pixel
pub fn ncpixel_set_rgb(pixel: &mut NcPixel, red: Color, green: Color, blue: Color) {
pub fn ncpixel_set_rgb(pixel: &mut NcPixel, red: NcColor, green: NcColor, blue: NcColor) {
ncpixel_set_r(pixel, red);
ncpixel_set_g(pixel, green);
ncpixel_set_b(pixel, blue);

@ -166,8 +166,8 @@ use crate::{
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,
NcPlaneOptions, Notcurses, StyleMask, NCPLANE_OPTION_HORALIGNED,
NcAlign, NcAlphaBits, NcCell, NcChannel, NcChannels, NcCharBackstop, NcColor, NcPlane,
NcPlaneOptions, NcResult, NcStyleMask, Notcurses, NCPLANE_OPTION_HORALIGNED,
},
};
@ -230,12 +230,12 @@ pub fn ncplane_align(plane: &NcPlane, align: NcAlign, cols: i32) -> i32 {
/// 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 ncplane_at_cursor_cell(plane: &mut NcPlane, cell: &mut Cell) -> IntResult {
pub fn ncplane_at_cursor_cell(plane: &mut NcPlane, cell: &mut NcCell) -> NcResult {
let mut egc = unsafe { ncplane_at_cursor(plane, &mut cell.stylemask, &mut cell.channels) };
if egc.is_null() {
return -1;
}
let result: IntResult = unsafe { cell_load(plane, cell, egc) };
let result: NcResult = unsafe { cell_load(plane, cell, egc) };
if result < 0 {
unsafe {
free(&mut egc as *mut _ as *mut c_void);
@ -247,13 +247,13 @@ pub fn ncplane_at_cursor_cell(plane: &mut NcPlane, cell: &mut Cell) -> IntResult
/// Retrieve the current contents of the specified cell into 'cell'.
/// This cell is invalidated if the associated plane is destroyed.
#[inline]
pub fn ncplane_at_yx_cell(plane: &mut NcPlane, y: i32, x: i32, cell: &mut Cell) -> IntResult {
pub fn ncplane_at_yx_cell(plane: &mut NcPlane, y: i32, x: i32, cell: &mut NcCell) -> NcResult {
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 { cell_load(plane, cell, egc) };
let result: NcResult = unsafe { cell_load(plane, cell, egc) };
cell.channels = channels;
unsafe {
free(&mut egc as *mut _ as *mut c_void);
@ -267,16 +267,16 @@ pub fn ncplane_at_yx_cell(plane: &mut NcPlane, y: i32, x: i32, cell: &mut Cell)
#[inline]
pub fn ncplane_box_sized(
plane: &mut NcPlane,
ul: &Cell,
ur: &Cell,
ll: &Cell,
lr: &Cell,
hline: &Cell,
vline: &Cell,
ul: &NcCell,
ur: &NcCell,
ll: &NcCell,
lr: &NcCell,
hline: &NcCell,
vline: &NcCell,
ylen: i32,
xlen: i32,
ctlword: u32,
) -> IntResult {
) -> NcResult {
let (mut y, mut x) = (0, 0);
unsafe {
ncplane_cursor_yx(plane, &mut y, &mut x);
@ -319,12 +319,12 @@ pub fn ncplane_dim_y(plane: &NcPlane) -> i32 {
#[inline]
pub fn ncplane_double_box(
plane: &mut NcPlane,
stylemask: StyleMask,
channels: Channels,
stylemask: NcStyleMask,
channels: NcChannels,
ystop: i32,
xstop: i32,
ctlword: u32,
) -> IntResult {
) -> NcResult {
#[allow(unused_assignments)]
let mut ret = 0;
@ -365,12 +365,12 @@ pub fn ncplane_double_box(
#[inline]
pub fn ncplane_double_box_sized(
plane: &mut NcPlane,
stylemask: StyleMask,
channels: Channels,
stylemask: NcStyleMask,
channels: NcChannels,
ylen: i32,
xlen: i32,
ctlword: u32,
) -> IntResult {
) -> NcResult {
let (mut y, mut x) = (0, 0);
unsafe {
ncplane_cursor_yx(plane, &mut y, &mut x);
@ -387,7 +387,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 {
pub fn ncplane_hline(plane: &mut NcPlane, cell: &NcCell, len: i32) -> i32 {
unsafe { ncplane_hline_interp(plane, cell, len, cell.channels, cell.channels) }
}
@ -395,14 +395,14 @@ pub fn ncplane_hline(plane: &mut NcPlane, cell: &Cell, len: i32) -> i32 {
#[inline]
pub fn ncplane_perimeter(
plane: &mut NcPlane,
ul: &Cell,
ur: &Cell,
ll: &Cell,
lr: &Cell,
hline: &Cell,
vline: &Cell,
ul: &NcCell,
ur: &NcCell,
ll: &NcCell,
lr: &NcCell,
hline: &NcCell,
vline: &NcCell,
ctlword: u32,
) -> IntResult {
) -> NcResult {
unsafe {
ncplane_cursor_move_yx(plane, 0, 0);
let (mut dimy, mut dimx) = (0, 0);
@ -415,10 +415,10 @@ pub fn ncplane_perimeter(
#[inline]
pub fn ncplane_perimeter_double(
plane: &mut NcPlane,
stylemask: StyleMask,
channels: Channels,
stylemask: NcStyleMask,
channels: NcChannels,
ctlword: u32,
) -> IntResult {
) -> NcResult {
if unsafe { ncplane_cursor_move_yx(plane, 0, 0) } != 0 {
return -1;
}
@ -464,10 +464,10 @@ pub fn ncplane_perimeter_double(
#[inline]
pub fn ncplane_perimeter_rounded(
plane: &mut NcPlane,
stylemask: StyleMask,
channels: Channels,
stylemask: NcStyleMask,
channels: NcChannels,
ctlword: u32,
) -> IntResult {
) -> NcResult {
if unsafe { ncplane_cursor_move_yx(plane, 0, 0) } != 0 {
return -1;
}
@ -511,19 +511,19 @@ 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 {
pub fn ncplane_putc(plane: &mut NcPlane, cell: &NcCell) -> NcResult {
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 {
pub fn ncplane_putegc(plane: &mut NcPlane, gcluster: i8, sbytes: &mut i32) -> NcResult {
unsafe { ncplane_putegc_yx(plane, -1, -1, &gcluster, sbytes) }
}
///
#[inline]
pub fn ncplane_putstr(plane: &mut NcPlane, gclustarr: &[u8]) -> IntResult {
pub fn ncplane_putstr(plane: &mut NcPlane, gclustarr: &[u8]) -> NcResult {
unsafe {
ncplane_putstr_yx(
plane,
@ -536,7 +536,7 @@ pub fn ncplane_putstr(plane: &mut NcPlane, gclustarr: &[u8]) -> IntResult {
///
#[inline]
pub fn ncplane_putnstr(plane: &mut NcPlane, size: u64, gclustarr: &[u8]) -> IntResult {
pub fn ncplane_putnstr(plane: &mut NcPlane, size: u64, gclustarr: &[u8]) -> NcResult {
unsafe {
ncplane_putnstr_yx(
plane,
@ -551,7 +551,7 @@ pub fn ncplane_putnstr(plane: &mut NcPlane, size: u64, gclustarr: &[u8]) -> IntR
/// Resize the plane, retaining what data we can (everything, unless we're
/// shrinking in some dimension). Keep the origin where it is.
#[inline]
pub fn ncplane_resize_simple(plane: &mut NcPlane, ylen: i32, xlen: i32) -> IntResult {
pub fn ncplane_resize_simple(plane: &mut NcPlane, ylen: i32, xlen: i32) -> NcResult {
let (mut oldy, mut oldx) = (0, 0);
unsafe {
ncplane_dim_yx(plane, &mut oldy, &mut oldx);
@ -576,13 +576,13 @@ pub fn ncplane_resize_simple(plane: &mut NcPlane, ylen: i32, xlen: i32) -> IntRe
///
/// On error, return the negative number of cells drawn.
#[inline]
pub fn ncplane_vline(plane: &mut NcPlane, cell: &Cell, len: i32) -> i32 {
pub fn ncplane_vline(plane: &mut NcPlane, cell: &NcCell, len: i32) -> i32 {
unsafe { ncplane_vline_interp(plane, cell, len, cell.channels, cell.channels) }
}
///
#[inline]
pub fn ncplane_vprintf(plane: &mut NcPlane, format: &str, ap: &mut __va_list_tag) -> IntResult {
pub fn ncplane_vprintf(plane: &mut NcPlane, format: &str, ap: &mut __va_list_tag) -> NcResult {
unsafe {
ncplane_vprintf_yx(
plane,
@ -602,14 +602,14 @@ pub fn ncplane_vprintf(plane: &mut NcPlane, format: &str, ap: &mut __va_list_tag
pub fn ncplane_gradient_sized(
plane: &mut NcPlane,
egc: &[u8],
stylemask: StyleMask,
stylemask: NcStyleMask,
ul: u64,
ur: u64,
ll: u64,
lr: u64,
ylen: i32,
xlen: i32,
) -> IntResult {
) -> NcResult {
if ylen < 1 || xlen < 1 {
return -1;
}
@ -632,37 +632,37 @@ pub fn ncplane_gradient_sized(
/// Extract the 32-bit working foreground channel from an ncplane.
#[inline]
pub fn ncplane_fchannel(plane: &NcPlane) -> Channel {
pub fn ncplane_fchannel(plane: &NcPlane) -> NcChannel {
channels_fchannel(unsafe { ncplane_channels(plane) })
}
/// Extract the 32-bit working background channel from an ncplane.
#[inline]
pub fn ncplane_bchannel(plane: &NcPlane) -> Channel {
pub fn ncplane_bchannel(plane: &NcPlane) -> NcChannel {
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 {
pub fn ncplane_fg_rgb(plane: &NcPlane) -> NcChannel {
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 {
pub fn ncplane_bg_rgb(plane: &NcPlane) -> NcChannel {
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 {
pub fn ncplane_fg_alpha(plane: &NcPlane) -> NcAlphaBits {
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 {
pub fn ncplane_bg_alpha(plane: &NcPlane) -> NcAlphaBits {
channels_bg_alpha(unsafe { ncplane_channels(plane) })
}
@ -682,10 +682,10 @@ pub fn ncplane_bg_default_p(plane: &NcPlane) -> bool {
#[inline]
pub fn ncplane_fg_rgb8(
plane: &NcPlane,
red: &mut Color,
green: &mut Color,
blue: &mut Color,
) -> Channel {
red: &mut NcColor,
green: &mut NcColor,
blue: &mut NcColor,
) -> NcChannel {
channels_fg_rgb8(unsafe { ncplane_channels(plane) }, red, green, blue)
}
@ -693,10 +693,10 @@ pub fn ncplane_fg_rgb8(
#[inline]
pub fn ncplane_bg_rgb8(
plane: &NcPlane,
red: &mut Color,
green: &mut Color,
blue: &mut Color,
) -> Channel {
red: &mut NcColor,
green: &mut NcColor,
blue: &mut NcColor,
) -> NcChannel {
channels_bg_rgb8(unsafe { ncplane_channels(plane) }, red, green, blue)
}
@ -704,12 +704,12 @@ pub fn ncplane_bg_rgb8(
#[inline]
pub fn ncplane_rounded_box(
plane: &mut NcPlane,
stylemask: StyleMask,
channels: Channels,
stylemask: NcStyleMask,
channels: NcChannels,
ystop: i32,
xstop: i32,
ctlword: u32,
) -> IntResult {
) -> NcResult {
#[allow(unused_assignments)]
let mut ret = 0;
@ -750,12 +750,12 @@ pub fn ncplane_rounded_box(
#[inline]
pub fn ncplane_rounded_box_sized(
plane: &mut NcPlane,
stylemask: StyleMask,
channels: Channels,
stylemask: NcStyleMask,
channels: NcChannels,
ylen: i32,
xlen: i32,
ctlword: u32,
) -> IntResult {
) -> NcResult {
let (mut y, mut x) = (0, 0);
unsafe {
ncplane_cursor_yx(plane, &mut y, &mut x);

@ -1,17 +1,20 @@
// Cell
#[allow(unused_imports)] // for docblocks
use crate::NcPlane;
// NcCell
/// A coordinate on an [`NcPlane`] storing 128 bits of data
///
/// ```txt
/// Cell: 128 bits structure comprised of the following 5 elements:
/// NcCell: 128 bits structure comprised of the following 5 elements:
///
/// GCLUSTER GCLUSTER GCLUSTER GCLUSTER 1. Egc
/// 00000000 ~~~~~~~~ 11111111 11111111 2. EgcBackstop + 3. reserved + 4. StyleMask
/// ~~AA~~~~ RRRRRRRR GGGGGGGG BBBBBBBB 5. Channels
/// GCLUSTER GCLUSTER GCLUSTER GCLUSTER 1. NcChar
/// 00000000 ~~~~~~~~ 11111111 11111111 2. NcCharBackstop + 3. reserved + 4. NcStyleMask
/// ~~AA~~~~ RRRRRRRR GGGGGGGG BBBBBBBB 5. NcChannels
/// ~~AA~~~~ RRRRRRRR GGGGGGGG BBBBBBBB |
///
/// 1. (32b) Extended Grapheme Cluster, presented either as:
///
/// 1.1. An Egc of up to 4 bytes:
/// 1.1. An NcChar of up to 4 bytes:
/// UUUUUUUU UUUUUUUU UUUUUUUU UUUUUUUU
///
/// 1.2. A `0x01` in the first byte, plus 3 bytes with a 24b address to an egcpool:
@ -23,14 +26,14 @@
/// 3. (8b) reserved (ought to be zero)
/// ~~~~~~~~
///
/// 4. (16b) StyleMask
/// 4. (16b) NcStyleMask
/// 11111111 11111111
///
/// 5. (64b) Channels
/// 5. (64b) NcChannels
/// ~~AA~~~~ RRRRRRRR GGGGGGGG BBBBBBBB|~~AA~~~~ RRRRRRRR GGGGGGGG BBBBBBBB
/// ```
///
/// A Cell corresponds to a single character cell on some plane, which can be
/// An NcCell 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
@ -44,7 +47,7 @@
/// 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
/// wcwidth() is not reliable. It's just quoting whether or not the NcChar
/// contains a "Wide Asian" double-width character.
/// This is set for some things, like most emoji, and not set for
/// other things, like cuneiform.
@ -82,61 +85,61 @@
///
/// `type in C: cell (struct)`
///
pub type Cell = crate::cell;
pub type NcCell = crate::cell;
///
pub const CELL_ALPHA_BLEND: u32 = crate::bindings::CELL_ALPHA_BLEND;
pub const NCCELL_ALPHA_BLEND: u32 = crate::bindings::CELL_ALPHA_BLEND;
/// Background cannot be highcontrast, only foreground
pub const CELL_ALPHA_HIGHCONTRAST: u32 = crate::bindings::CELL_ALPHA_HIGHCONTRAST;
pub const NCCELL_ALPHA_HIGHCONTRAST: u32 = crate::bindings::CELL_ALPHA_HIGHCONTRAST;
///
pub const CELL_ALPHA_OPAQUE: u32 = crate::bindings::CELL_ALPHA_OPAQUE;
pub const NCCELL_ALPHA_OPAQUE: u32 = crate::bindings::CELL_ALPHA_OPAQUE;
///
pub const CELL_ALPHA_TRANSPARENT: u32 = crate::bindings::CELL_ALPHA_TRANSPARENT;
pub const NCCELL_ALPHA_TRANSPARENT: u32 = crate::bindings::CELL_ALPHA_TRANSPARENT;
/// If this bit is set, we are *not* using the default background color
pub const CELL_BGDEFAULT_MASK: u32 = crate::bindings::CELL_BGDEFAULT_MASK;
pub const NCCELL_BGDEFAULT_MASK: u32 = crate::bindings::CELL_BGDEFAULT_MASK;
/// Extract these bits to get the background alpha mask
pub const CELL_BG_ALPHA_MASK: u32 = crate::bindings::CELL_BG_ALPHA_MASK;
pub const NCCELL_BG_ALPHA_MASK: u32 = crate::bindings::CELL_BG_ALPHA_MASK;
/// If this bit *and* CELL_BGDEFAULT_MASK are set, we're using a
/// palette-indexed background color
pub const CELL_BG_PALETTE: u32 = crate::bindings::CELL_BG_PALETTE;
pub const NCCELL_BG_PALETTE: u32 = crate::bindings::CELL_BG_PALETTE;
/// Extract these bits to get the background RGB value
pub const CELL_BG_RGB_MASK: u32 = crate::bindings::CELL_BG_RGB_MASK;
pub const NCCELL_BG_RGB_MASK: u32 = crate::bindings::CELL_BG_RGB_MASK;
/// If this bit is set, we are *not* using the default foreground color
pub const CELL_FGDEFAULT_MASK: u64 = crate::bindings::CELL_FGDEFAULT_MASK;
pub const NCCELL_FGDEFAULT_MASK: u64 = crate::bindings::CELL_FGDEFAULT_MASK;
/// Extract these bits to get the foreground alpha mask
pub const CELL_FG_ALPHA_MASK: u64 = crate::bindings::CELL_FG_ALPHA_MASK;
pub const NCCELL_FG_ALPHA_MASK: u64 = crate::bindings::CELL_FG_ALPHA_MASK;
/// If this bit *and* CELL_BGDEFAULT_MASK are set, we're using a
/// palette-indexed background color
pub const CELL_FG_PALETTE: u64 = crate::bindings::CELL_FG_PALETTE;
pub const NCCELL_FG_PALETTE: u64 = crate::bindings::CELL_FG_PALETTE;
/// Extract these bits to get the foreground RGB value
pub const CELL_FG_RGB_MASK: u64 = crate::bindings::CELL_FG_RGB_MASK;
pub const NCCELL_FG_RGB_MASK: u64 = crate::bindings::CELL_FG_RGB_MASK;
///
pub const CELL_NOBACKGROUND_MASK: u64 = crate::bindings::CELL_NOBACKGROUND_MASK;
pub const NCCELL_NOBACKGROUND_MASK: u64 = crate::bindings::CELL_NOBACKGROUND_MASK;
/// If this bit is set, the cell is part of a multicolumn glyph.
///
/// Whether a cell is the left or right side of the glyph can be determined
/// by checking whether ->gcluster is zero.
pub const CELL_WIDEASIAN_MASK: u64 = crate::bindings::CELL_WIDEASIAN_MASK as u64;
pub const NCCELL_WIDEASIAN_MASK: u64 = crate::bindings::CELL_WIDEASIAN_MASK as u64;
// Egc
// NcChar
//
/// Extended Grapheme Cluster. A 32-bit `Char` type
///
/// This 32 bit char, together with the associated plane's associated egcpool,
/// completely define this cell's `Egc`. Unless the `Egc` requires more than
/// completely define this cell's `NcChar`. Unless the `NcChar` requires more than
/// four bytes to encode as UTF-8, it will be inlined here:
///
/// ```txt
@ -150,8 +153,8 @@ pub const CELL_WIDEASIAN_MASK: u64 = crate::bindings::CELL_WIDEASIAN_MASK as u64
/// 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
/// A spilled NcChar is indicated by the value `0x01iiiiii`. This cannot alias a
/// true supra-ASCII NcChar, 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):
///
@ -164,7 +167,7 @@ pub const CELL_WIDEASIAN_MASK: u64 = crate::bindings::CELL_WIDEASIAN_MASK as u64
/// 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 as
/// NOTE that even if the `NcChar` is <= 4 bytes and inlined, is still interpreted as
/// 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,
@ -172,10 +175,10 @@ pub const CELL_WIDEASIAN_MASK: u64 = crate::bindings::CELL_WIDEASIAN_MASK as u64
///
/// `type in C: uint32_t`
///
pub type Egc = char;
pub type NcChar = char;
// EgcBackStop
/// An `u8` always at zero, part of the [`Cell`] struct
// NcCharBackStop
/// An `u8` always at zero, part of the [`NcCell`] struct
///
/// ```txt
/// 00000000
@ -183,9 +186,9 @@ pub type Egc = char;
///
/// `type in C: uint_8t`
///
pub type EgcBackstop = u8;
pub type NcCharBackstop = u8;
// StyleMask
// NcStyleMask
///
/// An `u16` of `NCSTYLE_*` boolean styling attributes
///
@ -195,4 +198,4 @@ pub type EgcBackstop = u8;
///
/// `type in C: uint16_t`
///
pub type StyleMask = u16;
pub type NcStyleMask = u16;

@ -1,4 +1,7 @@
// Channel
#[allow(unused_imports)] // for docblocks
use crate::NcChar;
// NcChannel
//
/// 32 bits of context-dependent info
/// containing RGB + 2 bits of alpha + extra
@ -12,19 +15,19 @@
/// - plus 2 bits of alpha
/// - plus context-dependent info
///
/// The context details are documented in [`Channels`]
/// The context details are documented in [`NcChannels`]
///
/// `type in C: channel (uint32_t)`
///
pub type Channel = u32;
pub type NcChannel = u32;
/// Extract these bits to get a channel's alpha value
pub const CHANNEL_ALPHA_MASK: u32 = crate::bindings::CHANNEL_ALPHA_MASK;
pub const NCCHANNEL_ALPHA_MASK: u32 = crate::bindings::CHANNEL_ALPHA_MASK;
// AlphaBits
// NcAlphaBits
//
/// 2 bits of alpha (surrounded by context dependent bits).
/// It is part of a Channel.
/// It is part of an [`NcChannel`].
///
/// ```txt
/// ~~AA~~~~ -------- -------- --------
@ -32,11 +35,11 @@ pub const CHANNEL_ALPHA_MASK: u32 = crate::bindings::CHANNEL_ALPHA_MASK;
///
/// `type in C: no data type`
///
pub type AlphaBits = u32;
pub type NcAlphaBits = u32;
// Channels
// NcChannels
//
/// 64 bits containing a foreground and background [`Channel`]
/// 64 bits containing a foreground and background [`NcChannel`]
///
/// ```txt
/// ~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB|~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB
@ -44,7 +47,7 @@ pub type AlphaBits = u32;
/// ```
///
/// Detailed info (specially on the context-dependent bits on each
/// `Channel`'s 4th byte):
/// `NcChannel`'s 4th byte):
///
/// ```txt
/// ~foreground channel~
@ -97,9 +100,9 @@ pub type AlphaBits = u32;
///
/// `type in C: channels (uint64_t)`
///
pub type Channels = u64;
pub type NcChannels = u64;
// Rgb
// NcRgb
//
/// 24 bits broken into 3x 8bpp channels.
///
@ -109,9 +112,9 @@ pub type Channels = u64;
///
/// `type in C: no data type`
///
pub type Rgb = u32;
pub type NcRgb = u32;
// Color
// NcColor
//
/// 8 bits representing a R/G/B color or alpha channel
///
@ -121,7 +124,7 @@ pub type Rgb = u32;
///
/// `type in C: no data type`
///
pub type Color = u8;
pub type NcColor = u8;
// NcPixel (RGBA)
/// 32 bits broken into RGB + 8-bit alpha
@ -138,10 +141,10 @@ pub type Color = u8;
///
/// `type in C: ncpixel (uint32_t)`
///
// NOTE: the order of the colors is different than in Channel.
// NOTE: the order of the colors is different than in NcChannel.
pub type NcPixel = u32;
/// Palette structure consisting of an array of 256 [`Channel`]s
/// NcPalette structure consisting of an array of 256 [`NcChannel`]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
@ -150,16 +153,16 @@ pub type NcPixel = u32;
///
/// `type in C: ncpalette256 (struct)`
///
pub type Palette = crate::palette256;
pub type NcPalette = crate::palette256;
/// 8-bit value used for indexing into a [`Palette`]
/// 8-bit value used for indexing into a [`NcPalette`]
///
pub type PaletteIndex = u8;
pub type NcPaletteIndex = u8;
/// Context for a palette fade operation
pub type NcFadeCtx = crate::ncfadectx;
/// the [`Egc`]s which form the various levels
/// the [`NcChar`] which form the various levels
/// of a given geometry.
///
/// If the geometry is wide, things are arranged with the rightmost side
@ -170,4 +173,4 @@ pub type NcFadeCtx = crate::ncfadectx;
///
/// `type in C: blitset (struct)`
///
pub type BlitSet = crate::blitset;
pub type NcBlitSet = crate::blitset;

@ -7,16 +7,13 @@ use core::ptr::{null_mut, NonNull};
use std::io::{Error, ErrorKind, Read, Seek, SeekFrom};
pub use libc::{
c_long, c_void, fclose, feof, fread, fseek, ftell, SEEK_CUR, SEEK_END,
SEEK_SET,
};
pub use libc::{c_long, c_void, fclose, feof, fread, fseek, ftell, SEEK_CUR, SEEK_END, SEEK_SET};
/// notcurses functions expects this type of *FILE (struct)
pub type NC_FILE = crate::bindgen::_IO_FILE;
pub type FILE_NC = crate::bindgen::_IO_FILE;
/// the libc crate expects this type of *FILE (opaque enum)
pub type LIBC_FILE = libc::FILE;
pub type FILE_LIBC = libc::FILE;
/// Intended to be passed into the CFile::open method.
/// It will open the file in a way that will allow reading and writing,
@ -59,27 +56,27 @@ fn get_error<T>() -> Result<T, Error> {
/// A wrapper struct around libc::FILE
///
/// The notcurses FILE type `NC_FILE` is imported through bindgen as a struct,
/// while the equivalent Rust libc::FILE (`LIBC_FILE`) is an opaque enum.
/// The notcurses FILE type `FILE_NC` is imported through bindgen as a struct,
/// while the equivalent Rust libc::FILE (`FILE_LIBC`) is an opaque enum.
/// Several methods are provided to convert back and forth between both types,
/// to allow both rust libc operations and notcurses file operations on it.
#[derive(Debug)]
pub struct NcFile {
file_ptr: NonNull<LIBC_FILE>,
file_ptr: NonNull<FILE_LIBC>,
}
impl NcFile {
// constructors --
/// `NcFile` constructor from a file produced by notcurses
pub fn from_nc(file: *mut NC_FILE) -> Self {
pub fn from_nc(file: *mut FILE_NC) -> Self {
NcFile {
file_ptr: unsafe { NonNull::new_unchecked(NcFile::nc2libc(file)) },
}
}
/// `NcFile` constructor from a file produced by the libc crate
pub fn from_libc(file: *mut LIBC_FILE) -> Self {
pub fn from_libc(file: *mut FILE_LIBC) -> Self {
NcFile {
file_ptr: unsafe { NonNull::new_unchecked(file) },
}
@ -89,13 +86,13 @@ impl NcFile {
/// Returns the file pointer in the format expected by libc
#[inline]
pub fn as_libc_ptr(&self) -> *mut LIBC_FILE {
pub fn as_libc_ptr(&self) -> *mut FILE_LIBC {
self.file_ptr.as_ptr()
}
/// Returns the file pointer in the format expected by notcurses
#[inline]
pub fn as_nc_ptr(&self) -> *mut NC_FILE {
pub fn as_nc_ptr(&self) -> *mut FILE_NC {
Self::libc2nc(self.file_ptr.as_ptr())
}
@ -127,15 +124,15 @@ impl NcFile {
/// Converts a file pointer from the struct notcurses uses to the
/// opaque enum type libc expects
#[inline]
fn nc2libc(file: *mut NC_FILE) -> *mut LIBC_FILE {
file as *mut _ as *mut LIBC_FILE
fn nc2libc(file: *mut FILE_NC) -> *mut FILE_LIBC {
file as *mut _ as *mut FILE_LIBC
}
/// Converts a file pointer from the libc opaque enum format to the struct
/// expected by notcurses
#[inline]
fn libc2nc(file: *mut LIBC_FILE) -> *mut NC_FILE {
file as *mut _ as *mut NC_FILE
fn libc2nc(file: *mut FILE_LIBC) -> *mut FILE_NC {
file as *mut _ as *mut FILE_NC
}
/// A utility function to expand a vector without increasing its capacity
@ -316,7 +313,7 @@ impl Drop for NcFile {
if !(self.as_libc_ptr()).is_null() {
let res = fclose(self.as_libc_ptr());
if res == 0 {
self.file_ptr = NonNull::new_unchecked(null_mut::<LIBC_FILE>());
self.file_ptr = NonNull::new_unchecked(null_mut::<FILE_LIBC>());
Ok(())
} else {
get_error()

@ -4,7 +4,11 @@
// error handling --------------------------------------------------------------
/// `i32` value used to return errors, when value < 0, (usually -1)
pub type IntResult = i32;
pub type NcResult = i32;
// time -----------------------------------------------------------------------
pub type NcTime = crate::bindings::timespec;
// ncmetric --------------------------------------------------------------------

@ -22,18 +22,18 @@ mod terminal;
mod widgets;
pub use cell::{
Cell, Egc, EgcBackstop, StyleMask, CELL_ALPHA_BLEND, CELL_ALPHA_HIGHCONTRAST,
CELL_ALPHA_OPAQUE, CELL_ALPHA_TRANSPARENT, CELL_BGDEFAULT_MASK, CELL_BG_ALPHA_MASK,
CELL_BG_PALETTE, CELL_BG_RGB_MASK, CELL_FGDEFAULT_MASK, CELL_FG_ALPHA_MASK, CELL_FG_PALETTE,
CELL_FG_RGB_MASK, CELL_NOBACKGROUND_MASK, CELL_WIDEASIAN_MASK,
NcCell, NcChar, NcCharBackstop, NcStyleMask, NCCELL_ALPHA_BLEND, NCCELL_ALPHA_HIGHCONTRAST,
NCCELL_ALPHA_OPAQUE, NCCELL_ALPHA_TRANSPARENT, NCCELL_BGDEFAULT_MASK, NCCELL_BG_ALPHA_MASK,
NCCELL_BG_PALETTE, NCCELL_BG_RGB_MASK, NCCELL_FGDEFAULT_MASK, NCCELL_FG_ALPHA_MASK,
NCCELL_FG_PALETTE, NCCELL_FG_RGB_MASK, NCCELL_NOBACKGROUND_MASK, NCCELL_WIDEASIAN_MASK,
};
pub use channel::{
AlphaBits, BlitSet, Channel, Channels, Color, NcFadeCtx, NcPixel, Palette, PaletteIndex, Rgb,
CHANNEL_ALPHA_MASK,
NcAlphaBits, NcBlitSet, NcChannel, NcChannels, NcColor, NcFadeCtx, NcPalette, NcPaletteIndex,
NcPixel, NcRgb, NCCHANNEL_ALPHA_MASK,
};
pub use file::{NcFile, LIBC_FILE, NC_FILE};
pub use file::{NcFile, FILE_LIBC, FILE_NC};
pub use misc::{
IntResult, BPREFIXCOLUMNS, BPREFIXSTRLEN, IPREFIXCOLUMNS, IPREFIXSTRLEN, PREFIXCOLUMNS,
NcResult, BPREFIXCOLUMNS, BPREFIXSTRLEN, IPREFIXCOLUMNS, IPREFIXSTRLEN, PREFIXCOLUMNS,
PREFIXSTRLEN,
};
pub use plane::{

@ -1,3 +1,6 @@
#[allow(unused_imports)] // for docblocks
use crate::NCCELL_ALPHA_BLEND;
// NcPlane
/// Fundamental drawing surface.
///
@ -101,7 +104,7 @@ pub type NcVisual = crate::ncvisual;
/// Options struct for [`NcVisual`]
pub type NcVisualOptions = crate::ncvisual_options;
/// Use [`CELL_ALPHA_BLEND`] with visual
/// Use [`NCCELL_ALPHA_BLEND`] with visual
pub const NCVISUAL_OPTION_BLEND: u32 = crate::bindings::NCVISUAL_OPTION_BLEND;
/// Fail rather than degrade

@ -1,5 +1,8 @@
//! Types for notcurses widgets
#[allow(unused_imports)] // for docblocks
use crate::NcPlane;
// NcMenu ----------------------------------------------------------------------
/// menus on the top or bottom rows

@ -18,7 +18,7 @@ use std::ffi::CString;
use crate::{
ncmenu_create,
types::{Channels, NcInput, NcMenu, NcMenuItem, NcMenuOptions, NcMenuSection, NcPlane},
types::{NcChannels, NcInput, NcMenu, NcMenuItem, NcMenuOptions, NcMenuSection, NcPlane},
};
impl NcMenu {
@ -43,8 +43,8 @@ impl NcMenuOptions {
pub fn with_options(
sections: &mut [NcMenuSection],
count: u32,
headerc: Channels,
sectionc: Channels,
headerc: NcChannels,
sectionc: NcChannels,
flags: u64,
) -> Self {
Self {

Loading…
Cancel
Save