mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
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.
This commit is contained in:
parent
1dda2d7d58
commit
8b6495a894
@ -27,11 +27,15 @@ pub mod bindgen {
|
|||||||
|
|
||||||
// Miscellaneous ---------------------------------------------------------------
|
// Miscellaneous ---------------------------------------------------------------
|
||||||
|
|
||||||
|
pub(crate) use bindgen::{
|
||||||
|
// structs
|
||||||
|
timespec,
|
||||||
|
};
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use bindgen::{
|
pub use bindgen::{
|
||||||
// structs
|
// structs
|
||||||
__va_list_tag,
|
__va_list_tag,
|
||||||
timespec,
|
|
||||||
|
|
||||||
// functions
|
// functions
|
||||||
ncstrwidth,
|
ncstrwidth,
|
||||||
|
@ -66,9 +66,9 @@ use crate::{
|
|||||||
channels_set_bg_default, channels_set_bg_rgb, channels_set_bg_rgb8, channels_set_fchannel,
|
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,
|
channels_set_fg_alpha, channels_set_fg_default, channels_set_fg_rgb, channels_set_fg_rgb8,
|
||||||
types::{
|
types::{
|
||||||
AlphaBits, Cell, Channel, Channels, Color, Egc, IntResult, NcPlane, PaletteIndex,
|
NcAlphaBits, NcCell, NcChannel, NcChannels, NcChar, NcColor, NcPaletteIndex, NcPlane,
|
||||||
StyleMask, CELL_ALPHA_OPAQUE, CELL_BGDEFAULT_MASK, CELL_BG_PALETTE, CELL_FGDEFAULT_MASK,
|
NcResult, NcStyleMask, NCCELL_ALPHA_OPAQUE, NCCELL_BGDEFAULT_MASK, NCCELL_BG_PALETTE,
|
||||||
CELL_FG_PALETTE, CELL_NOBACKGROUND_MASK, CELL_WIDEASIAN_MASK,
|
NCCELL_FGDEFAULT_MASK, NCCELL_FG_PALETTE, NCCELL_NOBACKGROUND_MASK, NCCELL_WIDEASIAN_MASK,
|
||||||
},
|
},
|
||||||
NCSTYLE_MASK,
|
NCSTYLE_MASK,
|
||||||
};
|
};
|
||||||
@ -87,22 +87,22 @@ use crate::{
|
|||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
pub unsafe fn cell_prime(
|
pub unsafe fn cell_prime(
|
||||||
plane: &mut NcPlane,
|
plane: &mut NcPlane,
|
||||||
cell: &mut Cell,
|
cell: &mut NcCell,
|
||||||
gcluster: Egc,
|
gcluster: NcChar,
|
||||||
style: StyleMask,
|
style: NcStyleMask,
|
||||||
channels: Channels,
|
channels: NcChannels,
|
||||||
) -> IntResult {
|
) -> NcResult {
|
||||||
cell.stylemask = style;
|
cell.stylemask = style;
|
||||||
cell.channels = channels;
|
cell.channels = channels;
|
||||||
unsafe { cell_load(plane, cell, gcluster as u32 as *const i8) }
|
unsafe { cell_load(plane, cell, gcluster as u32 as *const i8) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// load up six cells with the [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.
|
/// returns 0 on success, -1 on error.
|
||||||
///
|
///
|
||||||
/// on error, any cells this function might have loaded before the 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
|
/// # Safety
|
||||||
///
|
///
|
||||||
@ -111,19 +111,19 @@ pub unsafe fn cell_prime(
|
|||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
pub unsafe fn cells_load_box(
|
pub unsafe fn cells_load_box(
|
||||||
plane: &mut NcPlane,
|
plane: &mut NcPlane,
|
||||||
style: StyleMask,
|
style: NcStyleMask,
|
||||||
channels: Channels,
|
channels: NcChannels,
|
||||||
ul: &mut Cell,
|
ul: &mut NcCell,
|
||||||
ur: &mut Cell,
|
ur: &mut NcCell,
|
||||||
ll: &mut Cell,
|
ll: &mut NcCell,
|
||||||
lr: &mut Cell,
|
lr: &mut NcCell,
|
||||||
hl: &mut Cell,
|
hl: &mut NcCell,
|
||||||
vl: &mut Cell,
|
vl: &mut NcCell,
|
||||||
gcluster: Egc,
|
gcluster: NcChar,
|
||||||
) -> IntResult {
|
) -> NcResult {
|
||||||
// mutable copy for pointer arithmetics:
|
// mutable copy for pointer arithmetics:
|
||||||
let mut gclu = gcluster as u32 as *const i8;
|
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) };
|
ulen = unsafe { cell_prime(plane, ul, gcluster, style, channels) };
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ pub unsafe fn cells_load_box(
|
|||||||
|
|
||||||
///
|
///
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_init(cell: &mut Cell) {
|
pub fn cell_init(cell: &mut NcCell) {
|
||||||
*cell = unsafe { core::mem::zeroed() }
|
*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.
|
/// supported or not. Only the lower 16 bits are meaningful.
|
||||||
/// static inline void
|
/// static inline void
|
||||||
#[inline]
|
#[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;
|
cell.stylemask = stylebits & NCSTYLE_MASK as u16;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the style bits from the cell.
|
/// Extract the style bits from the cell.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_styles(cell: &Cell) -> StyleMask {
|
pub fn cell_styles(cell: &NcCell) -> NcStyleMask {
|
||||||
cell.stylemask
|
cell.stylemask
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add the specified styles (in the LSBs) to the cell's existing spec, whether
|
/// Add the specified styles (in the LSBs) to the cell's existing spec, whether
|
||||||
/// they're actively supported or not.
|
/// they're actively supported or not.
|
||||||
#[inline]
|
#[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;
|
cell.stylemask |= stylebits & NCSTYLE_MASK as u16;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove the specified styles (in the LSBs) from the cell's existing spec.
|
/// Remove the specified styles (in the LSBs) from the cell's existing spec.
|
||||||
#[inline]
|
#[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);
|
cell.stylemask &= !(stylebits & NCSTYLE_MASK as u16);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use the default color for the foreground.
|
/// Use the default color for the foreground.
|
||||||
#[inline]
|
#[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);
|
channels_set_fg_default(&mut cell.channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use the default color for the background.
|
/// Use the default color for the background.
|
||||||
#[inline]
|
#[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);
|
channels_set_bg_default(&mut cell.channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the foreground alpha.
|
/// Set the foreground alpha.
|
||||||
#[inline]
|
#[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);
|
channels_set_fg_alpha(&mut cell.channels, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the background alpha.
|
/// Set the background alpha.
|
||||||
#[inline]
|
#[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);
|
channels_set_bg_alpha(&mut cell.channels, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Does the cell contain an East Asian Wide codepoint?
|
/// Does the cell contain an East Asian Wide codepoint?
|
||||||
// NOTE: remove casting when fixed: https://github.com/rust-lang/rust-bindgen/issues/1875
|
// NOTE: remove casting when fixed: https://github.com/rust-lang/rust-bindgen/issues/1875
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_double_wide_p(cell: &Cell) -> bool {
|
pub fn cell_double_wide_p(cell: &NcCell) -> bool {
|
||||||
(cell.channels & CELL_WIDEASIAN_MASK as Channels) != 0
|
(cell.channels & NCCELL_WIDEASIAN_MASK as NcChannels) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is this the right half of a wide character?
|
/// Is this the right half of a wide character?
|
||||||
#[inline]
|
#[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
|
cell_double_wide_p(cell) && cell.gcluster == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is this the left half of a wide character?
|
/// Is this the left half of a wide character?
|
||||||
#[inline]
|
#[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
|
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.
|
/// result is not tied to the ncplane, and persists across erases / destruction.
|
||||||
#[inline]
|
#[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)
|
core::char::from_u32(unsafe { libc::strdup(cell_extended_gcluster(plane, cell)) } as i32 as u32)
|
||||||
.expect("wrong char")
|
.expect("wrong char")
|
||||||
|
|
||||||
@ -267,10 +267,10 @@ pub fn cell_strdup(plane: &NcPlane, cell: &Cell) -> Egc {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_extract(
|
pub fn cell_extract(
|
||||||
plane: &NcPlane,
|
plane: &NcPlane,
|
||||||
cell: &Cell,
|
cell: &NcCell,
|
||||||
stylemask: &mut StyleMask,
|
stylemask: &mut NcStyleMask,
|
||||||
channels: &mut Channels,
|
channels: &mut NcChannels,
|
||||||
) -> Egc {
|
) -> NcChar {
|
||||||
if *stylemask != 0 {
|
if *stylemask != 0 {
|
||||||
*stylemask = cell.stylemask;
|
*stylemask = cell.stylemask;
|
||||||
}
|
}
|
||||||
@ -280,12 +280,12 @@ pub fn cell_extract(
|
|||||||
cell_strdup(plane, cell)
|
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
|
/// 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.
|
/// it would probably be better to test whether they're Unicode-equal FIXME.
|
||||||
#[inline]
|
#[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 {
|
if cell1.stylemask != cell2.stylemask {
|
||||||
return true;
|
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]
|
#[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 {
|
unsafe {
|
||||||
cell_release(plane, cell);
|
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;
|
cell.gcluster = ch as u32;
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the 32-bit background channel from a cell.
|
/// Extract the 32-bit background channel from a cell.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_bchannel(cell: &Cell) -> Channel {
|
pub fn cell_bchannel(cell: &NcCell) -> NcChannel {
|
||||||
channels_bchannel(cell.channels)
|
channels_bchannel(cell.channels)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the 32-bit foreground channel from a cell.
|
/// Extract the 32-bit foreground channel from a cell.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_fchannel(cell: &Cell) -> Channel {
|
pub fn cell_fchannel(cell: &NcCell) -> NcChannel {
|
||||||
channels_fchannel(cell.channels)
|
channels_fchannel(cell.channels)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the 32-bit background channel of a cell.
|
/// Set the 32-bit background channel of a cell.
|
||||||
#[inline]
|
#[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)
|
channels_set_bchannel(&mut cell.channels, channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the 32-bit foreground channel of a cell.
|
/// Set the 32-bit foreground channel of a cell.
|
||||||
#[inline]
|
#[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)
|
channels_set_fchannel(&mut cell.channels, channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 24 bits of foreground RGB from 'cell', shifted to LSBs.
|
/// Extract 24 bits of foreground RGB from 'cell', shifted to LSBs.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_fg_rgb(cell: &Cell) -> Channel {
|
pub fn cell_fg_rgb(cell: &NcCell) -> NcChannel {
|
||||||
channels_fg_rgb(cell.channels)
|
channels_fg_rgb(cell.channels)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 24 bits of background RGB from 'cell', shifted to LSBs.
|
/// Extract 24 bits of background RGB from 'cell', shifted to LSBs.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_bg_rgb(cell: &Cell) -> Channel {
|
pub fn cell_bg_rgb(cell: &NcCell) -> NcChannel {
|
||||||
channels_bg_rgb(cell.channels)
|
channels_bg_rgb(cell.channels)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 2 bits of foreground alpha from 'cell', shifted to LSBs.
|
/// Extract 2 bits of foreground alpha from 'cell', shifted to LSBs.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_fg_alpha(cell: &Cell) -> AlphaBits {
|
pub fn cell_fg_alpha(cell: &NcCell) -> NcAlphaBits {
|
||||||
channels_fg_alpha(cell.channels)
|
channels_fg_alpha(cell.channels)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 2 bits of background alpha from 'cell', shifted to LSBs.
|
/// Extract 2 bits of background alpha from 'cell', shifted to LSBs.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_bg_alpha(cell: &Cell) -> AlphaBits {
|
pub fn cell_bg_alpha(cell: &NcCell) -> NcAlphaBits {
|
||||||
channels_bg_alpha(cell.channels)
|
channels_bg_alpha(cell.channels)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 24 bits of foreground RGB from 'cell', split into components.
|
/// Extract 24 bits of foreground RGB from 'cell', split into components.
|
||||||
#[inline]
|
#[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)
|
channels_fg_rgb8(cell.channels, red, green, blue)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 24 bits of background RGB from 'cell', split into components.
|
/// Extract 24 bits of background RGB from 'cell', split into components.
|
||||||
#[inline]
|
#[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)
|
channels_bg_rgb8(cell.channels, red, green, blue)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the r, g, and b cell for the foreground component of this 64-bit
|
/// 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.
|
/// 'cell' variable, and mark it as not using the default color.
|
||||||
#[inline]
|
#[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);
|
channels_set_fg_rgb8(&mut cell.channels, red, green, blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as `cell_set_fg_rgb8()` but with an assembled 24-bit RGB value.
|
/// Same as `cell_set_fg_rgb8()` but with an assembled 24-bit RGB value.
|
||||||
#[inline]
|
#[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);
|
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
|
// NOTE: this function now can't fail
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_set_fg_palindex(cell: &mut Cell, index: PaletteIndex) {
|
pub fn cell_set_fg_palindex(cell: &mut NcCell, index: NcPaletteIndex) {
|
||||||
cell.channels |= CELL_FGDEFAULT_MASK;
|
cell.channels |= NCCELL_FGDEFAULT_MASK;
|
||||||
cell.channels |= CELL_FG_PALETTE;
|
cell.channels |= NCCELL_FG_PALETTE;
|
||||||
cell_set_fg_alpha(cell, CELL_ALPHA_OPAQUE);
|
cell_set_fg_alpha(cell, NCCELL_ALPHA_OPAQUE);
|
||||||
cell.channels &= 0xff000000ffffffff as Channels;
|
cell.channels &= 0xff000000ffffffff as NcChannels;
|
||||||
cell.channels |= (index as Channels) << 32;
|
cell.channels |= (index as NcChannels) << 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_fg_palindex(cell: &Cell) -> PaletteIndex {
|
pub fn cell_fg_palindex(cell: &NcCell) -> NcPaletteIndex {
|
||||||
((cell.channels & 0xff00000000 as Channels) >> 32) as PaletteIndex
|
((cell.channels & 0xff00000000 as NcChannels) >> 32) as NcPaletteIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the r, g, and b cell for the background component of this 64-bit
|
/// 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.
|
/// 'cell' variable, and mark it as not using the default color.
|
||||||
///
|
///
|
||||||
#[inline]
|
#[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);
|
channels_set_bg_rgb8(&mut cell.channels, red, green, blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as `cell_set_fg_rgb8()` but with an assembled 24-bit RGB value.
|
/// Same as `cell_set_fg_rgb8()` but with an assembled 24-bit RGB value.
|
||||||
///
|
///
|
||||||
#[inline]
|
#[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);
|
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
|
// NOTE: this function now can't fail
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_set_bg_palindex(cell: &mut Cell, index: PaletteIndex) {
|
pub fn cell_set_bg_palindex(cell: &mut NcCell, index: NcPaletteIndex) {
|
||||||
cell.channels |= CELL_BGDEFAULT_MASK as Channels;
|
cell.channels |= NCCELL_BGDEFAULT_MASK as NcChannels;
|
||||||
cell.channels |= CELL_BG_PALETTE as Channels;
|
cell.channels |= NCCELL_BG_PALETTE as NcChannels;
|
||||||
cell_set_bg_alpha(cell, CELL_ALPHA_OPAQUE);
|
cell_set_bg_alpha(cell, NCCELL_ALPHA_OPAQUE);
|
||||||
cell.channels &= 0xffffffffff000000;
|
cell.channels &= 0xffffffffff000000;
|
||||||
cell.channels |= index as Channels;
|
cell.channels |= index as NcChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell_bg_palindex(cell: &Cell) -> PaletteIndex {
|
pub fn cell_bg_palindex(cell: &NcCell) -> NcPaletteIndex {
|
||||||
(cell.channels & 0xff) as PaletteIndex
|
(cell.channels & 0xff) as NcPaletteIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is the foreground using the "default foreground color"?
|
/// Is the foreground using the "default foreground color"?
|
||||||
#[inline]
|
#[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)
|
channels_fg_default_p(cell.channels)
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
#[inline]
|
#[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)
|
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
|
/// background color" must generally be used to take advantage of
|
||||||
/// terminal-effected transparency.
|
/// terminal-effected transparency.
|
||||||
#[inline]
|
#[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)
|
channels_bg_default_p(cell.channels)
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
#[inline]
|
#[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)
|
channels_bg_palindex_p(cell.channels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,31 +61,37 @@
|
|||||||
//X channels_set_fg_rgb8_clipped
|
//X channels_set_fg_rgb8_clipped
|
||||||
|
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
AlphaBits, Channel, Channels, Color, Rgb, CELL_ALPHA_HIGHCONTRAST, CELL_ALPHA_OPAQUE,
|
NcAlphaBits, NcChannel, NcChannels, NcColor, NcRgb, NCCELL_ALPHA_HIGHCONTRAST,
|
||||||
CELL_BGDEFAULT_MASK, CELL_BG_PALETTE, CELL_BG_RGB_MASK, CHANNEL_ALPHA_MASK,
|
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.
|
/// Extract the 8-bit red component from a 32-bit channel.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channel_r(channel: Channel) -> Color {
|
pub fn channel_r(channel: NcChannel) -> NcColor {
|
||||||
((channel & 0xff0000) >> 16) as Color
|
((channel & 0xff0000) >> 16) as NcColor
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the 8-bit green component from a 32-bit channel.
|
/// Extract the 8-bit green component from a 32-bit channel.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channel_g(channel: Channel) -> Color {
|
pub fn channel_g(channel: NcChannel) -> NcColor {
|
||||||
((channel & 0x00ff00) >> 8) as Color
|
((channel & 0x00ff00) >> 8) as NcColor
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the 8-bit blue component from a 32-bit channel.
|
/// Extract the 8-bit blue component from a 32-bit channel.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channel_b(channel: Channel) -> Color {
|
pub fn channel_b(channel: NcChannel) -> NcColor {
|
||||||
(channel & 0x0000ff) as Color
|
(channel & 0x0000ff) as NcColor
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the three 8-bit R/G/B components from a 32-bit channel.
|
/// Extract the three 8-bit R/G/B components from a 32-bit channel.
|
||||||
#[inline]
|
#[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);
|
*r = channel_r(channel);
|
||||||
*g = channel_g(channel);
|
*g = channel_g(channel);
|
||||||
*b = channel_b(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
|
/// 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.
|
/// the default color. Retain the other bits unchanged.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channel_set_rgb8(channel: &mut Channel, r: Color, g: Color, b: Color) {
|
pub fn channel_set_rgb8(channel: &mut NcChannel, r: NcColor, g: NcColor, b: NcColor) {
|
||||||
let rgb: Rgb = (r as Channel) << 16 | (g as Channel) << 8 | (b as Channel);
|
let rgb: NcRgb = (r as NcChannel) << 16 | (g as NcChannel) << 8 | (b as NcChannel);
|
||||||
*channel = (*channel & !CELL_BG_RGB_MASK) | CELL_BGDEFAULT_MASK | rgb;
|
*channel = (*channel & !NCCELL_BG_RGB_MASK) | NCCELL_BGDEFAULT_MASK | rgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as channel_set_rgb8(), but provide an assembled, packed 24 bits of rgb.
|
/// Same as channel_set_rgb8(), but provide an assembled, packed 24 bits of rgb.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channel_set(channel: &mut Channel, rgb: Rgb) {
|
pub fn channel_set(channel: &mut NcChannel, rgb: NcRgb) {
|
||||||
*channel = (*channel & !CELL_BG_RGB_MASK) | CELL_BGDEFAULT_MASK | (rgb & 0x00ffffff);
|
*channel = (*channel & !NCCELL_BG_RGB_MASK) | NCCELL_BGDEFAULT_MASK | (rgb & 0x00ffffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the 2-bit alpha component from a 32-bit channel.
|
/// Extract the 2-bit alpha component from a 32-bit channel.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channel_alpha(channel: Channel) -> AlphaBits {
|
pub fn channel_alpha(channel: NcChannel) -> NcAlphaBits {
|
||||||
channel & CHANNEL_ALPHA_MASK
|
channel & NCCHANNEL_ALPHA_MASK
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the 2-bit alpha component of the 32-bit channel.
|
/// Set the 2-bit alpha component of the 32-bit channel.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channel_set_alpha(channel: &mut Channel, alpha: AlphaBits) {
|
pub fn channel_set_alpha(channel: &mut NcChannel, alpha: NcAlphaBits) {
|
||||||
let alpha_clean = alpha & CHANNEL_ALPHA_MASK;
|
let alpha_clean = alpha & NCCHANNEL_ALPHA_MASK;
|
||||||
*channel = alpha_clean | (*channel & !CHANNEL_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
|
// 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?
|
/// Is this channel using the "default color" rather than RGB/palette-indexed?
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channel_default_p(channel: Channel) -> bool {
|
pub fn channel_default_p(channel: NcChannel) -> bool {
|
||||||
(channel & CELL_BGDEFAULT_MASK) == 0
|
(channel & NCCELL_BGDEFAULT_MASK) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is this channel using palette-indexed color rather than RGB?
|
/// Is this channel using palette-indexed color rather than RGB?
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channel_palindex_p(channel: Channel) -> bool {
|
pub fn channel_palindex_p(channel: NcChannel) -> bool {
|
||||||
!channel_default_p(channel) && (channel & CELL_BG_PALETTE) == 0
|
!channel_default_p(channel) && (channel & NCCELL_BG_PALETTE) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark the channel as using its default color, which also marks it opaque.
|
/// Mark the channel as using its default color, which also marks it opaque.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channel_set_default(channel: &mut Channel) -> Channel {
|
pub fn channel_set_default(channel: &mut NcChannel) -> NcChannel {
|
||||||
*channel &= !(CELL_BGDEFAULT_MASK | CELL_ALPHA_HIGHCONTRAST); // < NOTE shouldn't be better CHANNEL_ALPHA_MASK?
|
*channel &= !(NCCELL_BGDEFAULT_MASK | NCCELL_ALPHA_HIGHCONTRAST); // < NOTE shouldn't be better NCCHANNEL_ALPHA_MASK?
|
||||||
*channel
|
*channel
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the 32-bit background channel from a channel pair.
|
/// Extract the 32-bit background channel from a channel pair.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channels_bchannel(channels: Channels) -> Channel {
|
pub fn channels_bchannel(channels: NcChannels) -> NcChannel {
|
||||||
(channels & 0xffffffff_u64) as Channel
|
(channels & 0xffffffff_u64) as NcChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the 32-bit foreground channel from a channel pair.
|
/// Extract the 32-bit foreground channel from a channel pair.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channels_fchannel(channels: Channels) -> Channel {
|
pub fn channels_fchannel(channels: NcChannels) -> NcChannel {
|
||||||
channels_bchannel(channels >> 32)
|
channels_bchannel(channels >> 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the 32-bit background channel of a channel pair.
|
/// Set the 32-bit background channel of a channel pair.
|
||||||
#[inline]
|
#[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 = (*channels & 0xffffffff00000000_u64) | bchannel as u64;
|
||||||
*channels
|
*channels
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the 32-bit foreground channel of a channel pair.
|
/// Set the 32-bit foreground channel of a channel pair.
|
||||||
#[inline]
|
#[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 = (*channels & 0xffffffff_u64) | (fchannel as u64) << 32;
|
||||||
*channels
|
*channels
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Combine two channels into a channel pair.
|
/// Combine two channels into a channel pair.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channels_combine(fchannel: Channel, bchannel: Channel) -> Channels {
|
pub fn channels_combine(fchannel: NcChannel, bchannel: NcChannel) -> NcChannels {
|
||||||
let mut channels: Channels = 0;
|
let mut channels: NcChannels = 0;
|
||||||
channels_set_fchannel(&mut channels, fchannel);
|
channels_set_fchannel(&mut channels, fchannel);
|
||||||
channels_set_bchannel(&mut channels, bchannel);
|
channels_set_bchannel(&mut channels, bchannel);
|
||||||
channels
|
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.
|
/// Extract 24 bits of foreground RGB from 'channels', shifted to LSBs.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channels_fg_rgb(channels: Channels) -> Channel {
|
pub fn channels_fg_rgb(channels: NcChannels) -> NcChannel {
|
||||||
channels_fchannel(channels) & CELL_BG_RGB_MASK
|
channels_fchannel(channels) & NCCELL_BG_RGB_MASK
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 24 bits of background RGB from 'channels', shifted to LSBs.
|
/// Extract 24 bits of background RGB from 'channels', shifted to LSBs.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channels_bg_rgb(channels: Channels) -> Channel {
|
pub fn channels_bg_rgb(channels: NcChannels) -> NcChannel {
|
||||||
channels_bchannel(channels) & CELL_BG_RGB_MASK
|
channels_bchannel(channels) & NCCELL_BG_RGB_MASK
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 2 bits of foreground alpha from 'channels', shifted to LSBs.
|
/// Extract 2 bits of foreground alpha from 'channels', shifted to LSBs.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channels_fg_alpha(channels: Channels) -> AlphaBits {
|
pub fn channels_fg_alpha(channels: NcChannels) -> NcAlphaBits {
|
||||||
channel_alpha(channels_fchannel(channels))
|
channel_alpha(channels_fchannel(channels))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 2 bits of background alpha from 'channels', shifted to LSBs.
|
/// Extract 2 bits of background alpha from 'channels', shifted to LSBs.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channels_bg_alpha(channels: Channels) -> AlphaBits {
|
pub fn channels_bg_alpha(channels: NcChannels) -> NcAlphaBits {
|
||||||
channel_alpha(channels_bchannel(channels))
|
channel_alpha(channels_bchannel(channels))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 24 bits of foreground RGB from 'channels', split into subchannels.
|
/// Extract 24 bits of foreground RGB from 'channels', split into subchannels.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channels_fg_rgb8(
|
pub fn channels_fg_rgb8(
|
||||||
channels: Channels,
|
channels: NcChannels,
|
||||||
r: &mut Color,
|
r: &mut NcColor,
|
||||||
g: &mut Color,
|
g: &mut NcColor,
|
||||||
b: &mut Color,
|
b: &mut NcColor,
|
||||||
) -> Channel {
|
) -> NcChannel {
|
||||||
channel_rgb8(channels_fchannel(channels), r, g, b)
|
channel_rgb8(channels_fchannel(channels), r, g, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 24 bits of background RGB from 'channels', split into subchannels.
|
/// Extract 24 bits of background RGB from 'channels', split into subchannels.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channels_bg_rgb8(
|
pub fn channels_bg_rgb8(
|
||||||
channels: Channels,
|
channels: NcChannels,
|
||||||
r: &mut Color,
|
r: &mut NcColor,
|
||||||
g: &mut Color,
|
g: &mut NcColor,
|
||||||
b: &mut Color,
|
b: &mut NcColor,
|
||||||
) -> Channel {
|
) -> NcChannel {
|
||||||
channel_rgb8(channels_bchannel(channels), r, g, b)
|
channel_rgb8(channels_bchannel(channels), r, g, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the r, g, and b channels for the foreground component of this 64-bit
|
/// 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.
|
/// 'channels' variable, and mark it as not using the default color.
|
||||||
#[inline]
|
#[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);
|
let mut channel = channels_fchannel(*channels);
|
||||||
channel_set_rgb8(&mut channel, r, g, b);
|
channel_set_rgb8(&mut channel, r, g, b);
|
||||||
*channels = (channel as u64) << 32 | *channels & 0xffffffff_u64;
|
*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.
|
/// Same as channels_set_fg_rgb8 but set an assembled 24 bit channel at once.
|
||||||
#[inline]
|
#[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);
|
let mut channel = channels_fchannel(*channels);
|
||||||
channel_set(&mut channel, rgb);
|
channel_set(&mut channel, rgb);
|
||||||
*channels = (channel as u64) << 32 | *channels & 0xffffffff_u64;
|
*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
|
/// 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.
|
/// 'channels' variable, and mark it as not using the default color.
|
||||||
#[inline]
|
#[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);
|
let mut channel = channels_bchannel(*channels);
|
||||||
channel_set_rgb8(&mut channel, r, g, b);
|
channel_set_rgb8(&mut channel, r, g, b);
|
||||||
channels_set_bchannel(channels, channel);
|
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.
|
/// Same as channels_set_bg_rgb8 but set an assembled 24 bit channel at once.
|
||||||
#[inline]
|
#[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);
|
let mut channel = channels_bchannel(*channels);
|
||||||
channel_set(&mut channel, rgb);
|
channel_set(&mut channel, rgb);
|
||||||
channels_set_bchannel(channels, channel);
|
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.
|
/// Set the 2-bit alpha component of the foreground channel.
|
||||||
#[inline]
|
#[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);
|
let mut channel = channels_fchannel(*channels);
|
||||||
channel_set_alpha(&mut channel, alpha);
|
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.
|
/// Set the 2-bit alpha component of the background channel.
|
||||||
#[inline]
|
#[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;
|
let mut alpha_clean = alpha;
|
||||||
if alpha == CELL_ALPHA_HIGHCONTRAST {
|
if alpha == NCCELL_ALPHA_HIGHCONTRAST {
|
||||||
// forbidden for background alpha, so makes it opaque
|
// forbidden for background alpha, so makes it opaque
|
||||||
alpha_clean = CELL_ALPHA_OPAQUE;
|
alpha_clean = NCCELL_ALPHA_OPAQUE;
|
||||||
}
|
}
|
||||||
let mut channel = channels_bchannel(*channels);
|
let mut channel = channels_bchannel(*channels);
|
||||||
channel_set_alpha(&mut channel, alpha_clean);
|
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"?
|
/// Is the foreground using the "default foreground color"?
|
||||||
#[inline]
|
#[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))
|
channel_default_p(channels_fchannel(channels))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is the foreground using indexed palette color?
|
/// Is the foreground using indexed palette color?
|
||||||
#[inline]
|
#[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))
|
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
|
/// background color" must generally be used to take advantage of
|
||||||
/// terminal-effected transparency.
|
/// terminal-effected transparency.
|
||||||
#[inline]
|
#[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))
|
channel_default_p(channels_bchannel(channels))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is the background using indexed palette color?
|
/// Is the background using indexed palette color?
|
||||||
#[inline]
|
#[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))
|
channel_palindex_p(channels_bchannel(channels))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark the foreground channel as using its default color.
|
/// Mark the foreground channel as using its default color.
|
||||||
#[inline]
|
#[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);
|
let mut channel = channels_fchannel(*channels);
|
||||||
channel_set_default(&mut channel);
|
channel_set_default(&mut channel);
|
||||||
*channels = (channel as u64) << 32 | *channels & 0xffffffff_u64;
|
*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.
|
/// Mark the background channel as using its default color.
|
||||||
#[inline]
|
#[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);
|
let mut channel = channels_bchannel(*channels);
|
||||||
channel_set_default(&mut channel);
|
channel_set_default(&mut channel);
|
||||||
channels_set_bchannel(channels, channel);
|
channels_set_bchannel(channels, channel);
|
||||||
@ -325,34 +331,35 @@ pub fn channels_set_bg_default(channels: &mut Channels) -> Channels {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::{Channel, Channels};
|
use super::{NcChannel, NcChannels};
|
||||||
use crate::types::{
|
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;
|
use serial_test::serial;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
fn channel_r() {
|
fn channel_r() {
|
||||||
let c: Channel = 0x112233;
|
let c: NcChannel = 0x112233;
|
||||||
assert_eq!(super::channel_r(c), 0x11);
|
assert_eq!(super::channel_r(c), 0x11);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
fn channel_g() {
|
fn channel_g() {
|
||||||
let c: Channel = 0x112233;
|
let c: NcChannel = 0x112233;
|
||||||
assert_eq!(super::channel_g(c), 0x22);
|
assert_eq!(super::channel_g(c), 0x22);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
fn channel_b() {
|
fn channel_b() {
|
||||||
let c: Channel = 0x112233;
|
let c: NcChannel = 0x112233;
|
||||||
assert_eq!(super::channel_b(c), 0x33);
|
assert_eq!(super::channel_b(c), 0x33);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
fn channel_rgb8() {
|
fn channel_rgb8() {
|
||||||
let c: Channel = 0x112233;
|
let c: NcChannel = 0x112233;
|
||||||
let mut r = 0;
|
let mut r = 0;
|
||||||
let mut g = 0;
|
let mut g = 0;
|
||||||
let mut b = 0;
|
let mut b = 0;
|
||||||
@ -364,7 +371,7 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
fn channel_set_rgb8() {
|
fn channel_set_rgb8() {
|
||||||
let mut c: Channel = 0x000000;
|
let mut c: NcChannel = 0x000000;
|
||||||
super::channel_set_rgb8(&mut c, 0x11, 0x22, 0x33);
|
super::channel_set_rgb8(&mut c, 0x11, 0x22, 0x33);
|
||||||
assert_eq!(super::channel_r(c), 0x11);
|
assert_eq!(super::channel_r(c), 0x11);
|
||||||
assert_eq!(super::channel_g(c), 0x22);
|
assert_eq!(super::channel_g(c), 0x22);
|
||||||
@ -373,33 +380,33 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
fn channel_alpha() {
|
fn channel_alpha() {
|
||||||
let c: Channel = 0x112233 | CELL_ALPHA_TRANSPARENT;
|
let c: NcChannel = 0x112233 | NCCELL_ALPHA_TRANSPARENT;
|
||||||
assert_eq!(super::channel_alpha(c), CELL_ALPHA_TRANSPARENT);
|
assert_eq!(super::channel_alpha(c), NCCELL_ALPHA_TRANSPARENT);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
fn channel_set_alpha() {
|
fn channel_set_alpha() {
|
||||||
let mut c: Channel = 0x112233;
|
let mut c: NcChannel = 0x112233;
|
||||||
super::channel_set_alpha(&mut c, CELL_ALPHA_HIGHCONTRAST);
|
super::channel_set_alpha(&mut c, NCCELL_ALPHA_HIGHCONTRAST);
|
||||||
assert_eq!(CELL_ALPHA_HIGHCONTRAST, super::channel_alpha(c));
|
assert_eq!(NCCELL_ALPHA_HIGHCONTRAST, super::channel_alpha(c));
|
||||||
|
|
||||||
super::channel_set_alpha(&mut c, CELL_ALPHA_TRANSPARENT);
|
super::channel_set_alpha(&mut c, NCCELL_ALPHA_TRANSPARENT);
|
||||||
assert_eq!(CELL_ALPHA_TRANSPARENT, super::channel_alpha(c));
|
assert_eq!(NCCELL_ALPHA_TRANSPARENT, super::channel_alpha(c));
|
||||||
|
|
||||||
super::channel_set_alpha(&mut c, CELL_ALPHA_BLEND);
|
super::channel_set_alpha(&mut c, NCCELL_ALPHA_BLEND);
|
||||||
assert_eq!(CELL_ALPHA_BLEND, super::channel_alpha(c));
|
assert_eq!(NCCELL_ALPHA_BLEND, super::channel_alpha(c));
|
||||||
|
|
||||||
super::channel_set_alpha(&mut c, CELL_ALPHA_OPAQUE);
|
super::channel_set_alpha(&mut c, NCCELL_ALPHA_OPAQUE);
|
||||||
assert_eq!(CELL_ALPHA_OPAQUE, super::channel_alpha(c));
|
assert_eq!(NCCELL_ALPHA_OPAQUE, super::channel_alpha(c));
|
||||||
// TODO: CHECK for CELL_BGDEFAULT_MASK
|
// TODO: CHECK for NCCELL_BGDEFAULT_MASK
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
fn channel_set_default() {
|
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);
|
assert!(c != DEFAULT);
|
||||||
|
|
||||||
super::channel_set_default(&mut c);
|
super::channel_set_default(&mut c);
|
||||||
@ -409,22 +416,22 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
fn channel_default_p() {
|
fn channel_default_p() {
|
||||||
let mut c: Channel = 0x112233;
|
let mut c: NcChannel = 0x112233;
|
||||||
assert_eq!(true, super::channel_default_p(c));
|
assert_eq!(true, super::channel_default_p(c));
|
||||||
|
|
||||||
// TODO FIXME: test for the false result
|
// 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));
|
// 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));
|
assert_eq!(true, super::channel_default_p(c));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn channels_set_fchannel__channels_fchannel() {
|
fn channels_set_fchannel__channels_fchannel() {
|
||||||
let fc: Channel = 0x112233;
|
let fc: NcChannel = 0x112233;
|
||||||
let mut cp: Channels = 0;
|
let mut cp: NcChannels = 0;
|
||||||
super::channels_set_fchannel(&mut cp, fc);
|
super::channels_set_fchannel(&mut cp, fc);
|
||||||
assert_eq!(super::channels_fchannel(cp), fc);
|
assert_eq!(super::channels_fchannel(cp), fc);
|
||||||
}
|
}
|
||||||
@ -432,18 +439,18 @@ mod test {
|
|||||||
#[serial]
|
#[serial]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn channels_set_bchannel__channels_bchannel() {
|
fn channels_set_bchannel__channels_bchannel() {
|
||||||
let bc: Channel = 0x112233;
|
let bc: NcChannel = 0x112233;
|
||||||
let mut cp: Channels = 0;
|
let mut cp: NcChannels = 0;
|
||||||
super::channels_set_bchannel(&mut cp, bc);
|
super::channels_set_bchannel(&mut cp, bc);
|
||||||
assert_eq!(super::channels_bchannel(cp), bc);
|
assert_eq!(super::channels_bchannel(cp), bc);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
fn channels_combine() {
|
fn channels_combine() {
|
||||||
let bc: Channel = 0x112233;
|
let bc: NcChannel = 0x112233;
|
||||||
let fc: Channel = 0x445566;
|
let fc: NcChannel = 0x445566;
|
||||||
let mut cp1: Channels = 0;
|
let mut cp1: NcChannels = 0;
|
||||||
let mut _cp2: Channels = 0;
|
let mut _cp2: NcChannels = 0;
|
||||||
super::channels_set_bchannel(&mut cp1, bc);
|
super::channels_set_bchannel(&mut cp1, bc);
|
||||||
super::channels_set_fchannel(&mut cp1, fc);
|
super::channels_set_fchannel(&mut cp1, fc);
|
||||||
_cp2 = super::channels_combine(fc, bc);
|
_cp2 = super::channels_combine(fc, bc);
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use crate::Cell;
|
use crate::{NcCell, NcChannels, NcChar, NcStyleMask};
|
||||||
|
|
||||||
// Cell ------------------------------------------------------------------------
|
// NcCell ------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Initializes a cell providing an [`Egc`],
|
/// Initializes a cell providing an [`NcChar`],
|
||||||
/// a [`StyleMask`] and [`Channels`]
|
/// a [`NcStyleMask`] and [`NcChannels`]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! cell_initializer {
|
macro_rules! cell_initializer {
|
||||||
( $c:expr, $s:expr, $chan:expr ) => {
|
( $c:expr, $s:expr, $chan:expr ) => {
|
||||||
Cell {
|
NcCell {
|
||||||
gcluster: $c as u32,
|
gcluster: $c as u32,
|
||||||
gcluster_backstop: 0 as EgcBackstop,
|
gcluster_backstop: 0 as NcCharBackstop,
|
||||||
reserved: 0,
|
reserved: 0,
|
||||||
stylemask: $s,
|
stylemask: $s,
|
||||||
channels: $chan,
|
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_export]
|
||||||
macro_rules! cell_char_initializer {
|
macro_rules! cell_char_initializer {
|
||||||
( $c:expr ) => {
|
( $c:expr ) => {
|
||||||
|
@ -19,36 +19,36 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
channel_rgb8, channel_set, channel_set_rgb8,
|
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.
|
/// Set the different color components of an entry inside a palette store.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn palette256_set_rgb(
|
pub fn palette256_set_rgb(
|
||||||
palette: &mut Palette,
|
palette: &mut NcPalette,
|
||||||
idx: PaletteIndex,
|
idx: NcPaletteIndex,
|
||||||
red: Color,
|
red: NcColor,
|
||||||
green: Color,
|
green: NcColor,
|
||||||
blue: Color,
|
blue: NcColor,
|
||||||
) {
|
) {
|
||||||
channel_set_rgb8(&mut palette.chans[idx as usize], red, green, blue)
|
channel_set_rgb8(&mut palette.chans[idx as usize], red, green, blue)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as `palette256_set_rgb()` but set an assembled 24 bit channel at once.
|
/// Same as `palette256_set_rgb()` but set an assembled 24 bit channel at once.
|
||||||
#[inline]
|
#[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);
|
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.
|
/// Extract the three 8-bit R/G/B components from an entry inside a palette store.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn palette256_get_rgb(
|
pub fn palette256_get_rgb(
|
||||||
palette: &Palette,
|
palette: &NcPalette,
|
||||||
idx: PaletteIndex,
|
idx: NcPaletteIndex,
|
||||||
red: &mut Color,
|
red: &mut NcColor,
|
||||||
green: &mut Color,
|
green: &mut NcColor,
|
||||||
blue: &mut Color,
|
blue: &mut NcColor,
|
||||||
) -> Channel {
|
) -> NcChannel {
|
||||||
channel_rgb8(palette.chans[idx as usize], red, green, blue)
|
channel_rgb8(palette.chans[idx as usize], red, green, blue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
//+ ncpixel_set_r
|
//+ ncpixel_set_r
|
||||||
//+ ncpixel_set_rgb
|
//+ ncpixel_set_rgb
|
||||||
|
|
||||||
use crate::types::{Color, NcPixel};
|
use crate::types::{NcColor, NcPixel};
|
||||||
|
|
||||||
// NcPixel Structure:
|
// NcPixel Structure:
|
||||||
//
|
//
|
||||||
@ -37,52 +37,52 @@ use crate::types::{Color, NcPixel};
|
|||||||
// 0x000000ff 8 bit Red
|
// 0x000000ff 8 bit Red
|
||||||
|
|
||||||
/// Get an RGB pixel from RGB values
|
/// 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
|
0xff000000 as NcPixel | r as NcPixel | (b as NcPixel) << 8 | (g as NcPixel) << 16
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the 8-bit alpha component from a pixel
|
/// Extract the 8-bit alpha component from a pixel
|
||||||
pub fn ncpixel_a(pixel: NcPixel) -> Color {
|
pub fn ncpixel_a(pixel: NcPixel) -> NcColor {
|
||||||
((pixel & 0xff000000) >> 24) as Color
|
((pixel & 0xff000000) >> 24) as NcColor
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the 8 bit green component from a pixel
|
/// Extract the 8 bit green component from a pixel
|
||||||
pub fn ncpixel_g(pixel: NcPixel) -> Color {
|
pub fn ncpixel_g(pixel: NcPixel) -> NcColor {
|
||||||
((pixel & 0x00ff0000) >> 16) as Color
|
((pixel & 0x00ff0000) >> 16) as NcColor
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the 8 bit blue component from a pixel
|
/// Extract the 8 bit blue component from a pixel
|
||||||
pub fn ncpixel_b(pixel: NcPixel) -> Color {
|
pub fn ncpixel_b(pixel: NcPixel) -> NcColor {
|
||||||
((pixel & 0x0000ff00) >> 8) as Color
|
((pixel & 0x0000ff00) >> 8) as NcColor
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the 8 bit red component from a pixel
|
/// Extract the 8 bit red component from a pixel
|
||||||
pub fn ncpixel_r(pixel: NcPixel) -> Color {
|
pub fn ncpixel_r(pixel: NcPixel) -> NcColor {
|
||||||
(pixel & 0x000000ff) as Color
|
(pixel & 0x000000ff) as NcColor
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the 8-bit alpha component of a pixel
|
/// 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);
|
*pixel = (*pixel & 0x00ffffff) | ((alpha as NcPixel) << 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the 8-bit green component of a pixel
|
/// 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);
|
*pixel = (*pixel & 0xff00ffff) | ((green as NcPixel) << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the 8-bit blue component of a pixel
|
/// 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);
|
*pixel = (*pixel & 0xffff00ff) | ((blue as NcPixel) << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the 8-bit red component of a pixel
|
/// 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;
|
*pixel = (*pixel & 0xffffff00) | red as NcPixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// set the RGB values of an RGB pixel
|
/// 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_r(pixel, red);
|
||||||
ncpixel_set_g(pixel, green);
|
ncpixel_set_g(pixel, green);
|
||||||
ncpixel_set_b(pixel, blue);
|
ncpixel_set_b(pixel, blue);
|
||||||
|
@ -166,8 +166,8 @@ use crate::{
|
|||||||
ncplane_hline_interp, ncplane_putc_yx, ncplane_putegc_yx, ncplane_putnstr_yx,
|
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,
|
ncplane_putstr_yx, ncplane_resize, ncplane_vline_interp, ncplane_vprintf_yx, notcurses_align,
|
||||||
types::{
|
types::{
|
||||||
AlphaBits, Cell, Channel, Channels, Color, EgcBackstop, IntResult, NcAlign, NcPlane,
|
NcAlign, NcAlphaBits, NcCell, NcChannel, NcChannels, NcCharBackstop, NcColor, NcPlane,
|
||||||
NcPlaneOptions, Notcurses, StyleMask, NCPLANE_OPTION_HORALIGNED,
|
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'.
|
/// Retrieve the current contents of the cell under the cursor into 'cell'.
|
||||||
/// This cell is invalidated if the associated plane is destroyed.
|
/// This cell is invalidated if the associated plane is destroyed.
|
||||||
#[inline]
|
#[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) };
|
let mut egc = unsafe { ncplane_at_cursor(plane, &mut cell.stylemask, &mut cell.channels) };
|
||||||
if egc.is_null() {
|
if egc.is_null() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
let result: IntResult = unsafe { cell_load(plane, cell, egc) };
|
let result: NcResult = unsafe { cell_load(plane, cell, egc) };
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
unsafe {
|
unsafe {
|
||||||
free(&mut egc as *mut _ as *mut c_void);
|
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'.
|
/// Retrieve the current contents of the specified cell into 'cell'.
|
||||||
/// This cell is invalidated if the associated plane is destroyed.
|
/// This cell is invalidated if the associated plane is destroyed.
|
||||||
#[inline]
|
#[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) };
|
let mut egc = unsafe { ncplane_at_yx(plane, y, x, &mut cell.stylemask, &mut cell.channels) };
|
||||||
if egc.is_null() {
|
if egc.is_null() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
let channels = cell.channels; // need to preserve wide flag
|
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;
|
cell.channels = channels;
|
||||||
unsafe {
|
unsafe {
|
||||||
free(&mut egc as *mut _ as *mut c_void);
|
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]
|
#[inline]
|
||||||
pub fn ncplane_box_sized(
|
pub fn ncplane_box_sized(
|
||||||
plane: &mut NcPlane,
|
plane: &mut NcPlane,
|
||||||
ul: &Cell,
|
ul: &NcCell,
|
||||||
ur: &Cell,
|
ur: &NcCell,
|
||||||
ll: &Cell,
|
ll: &NcCell,
|
||||||
lr: &Cell,
|
lr: &NcCell,
|
||||||
hline: &Cell,
|
hline: &NcCell,
|
||||||
vline: &Cell,
|
vline: &NcCell,
|
||||||
ylen: i32,
|
ylen: i32,
|
||||||
xlen: i32,
|
xlen: i32,
|
||||||
ctlword: u32,
|
ctlword: u32,
|
||||||
) -> IntResult {
|
) -> NcResult {
|
||||||
let (mut y, mut x) = (0, 0);
|
let (mut y, mut x) = (0, 0);
|
||||||
unsafe {
|
unsafe {
|
||||||
ncplane_cursor_yx(plane, &mut y, &mut x);
|
ncplane_cursor_yx(plane, &mut y, &mut x);
|
||||||
@ -319,12 +319,12 @@ pub fn ncplane_dim_y(plane: &NcPlane) -> i32 {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_double_box(
|
pub fn ncplane_double_box(
|
||||||
plane: &mut NcPlane,
|
plane: &mut NcPlane,
|
||||||
stylemask: StyleMask,
|
stylemask: NcStyleMask,
|
||||||
channels: Channels,
|
channels: NcChannels,
|
||||||
ystop: i32,
|
ystop: i32,
|
||||||
xstop: i32,
|
xstop: i32,
|
||||||
ctlword: u32,
|
ctlword: u32,
|
||||||
) -> IntResult {
|
) -> NcResult {
|
||||||
#[allow(unused_assignments)]
|
#[allow(unused_assignments)]
|
||||||
let mut ret = 0;
|
let mut ret = 0;
|
||||||
|
|
||||||
@ -365,12 +365,12 @@ pub fn ncplane_double_box(
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_double_box_sized(
|
pub fn ncplane_double_box_sized(
|
||||||
plane: &mut NcPlane,
|
plane: &mut NcPlane,
|
||||||
stylemask: StyleMask,
|
stylemask: NcStyleMask,
|
||||||
channels: Channels,
|
channels: NcChannels,
|
||||||
ylen: i32,
|
ylen: i32,
|
||||||
xlen: i32,
|
xlen: i32,
|
||||||
ctlword: u32,
|
ctlword: u32,
|
||||||
) -> IntResult {
|
) -> NcResult {
|
||||||
let (mut y, mut x) = (0, 0);
|
let (mut y, mut x) = (0, 0);
|
||||||
unsafe {
|
unsafe {
|
||||||
ncplane_cursor_yx(plane, &mut y, &mut x);
|
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.
|
/// On error, return the negative number of cells drawn.
|
||||||
#[inline]
|
#[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) }
|
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]
|
#[inline]
|
||||||
pub fn ncplane_perimeter(
|
pub fn ncplane_perimeter(
|
||||||
plane: &mut NcPlane,
|
plane: &mut NcPlane,
|
||||||
ul: &Cell,
|
ul: &NcCell,
|
||||||
ur: &Cell,
|
ur: &NcCell,
|
||||||
ll: &Cell,
|
ll: &NcCell,
|
||||||
lr: &Cell,
|
lr: &NcCell,
|
||||||
hline: &Cell,
|
hline: &NcCell,
|
||||||
vline: &Cell,
|
vline: &NcCell,
|
||||||
ctlword: u32,
|
ctlword: u32,
|
||||||
) -> IntResult {
|
) -> NcResult {
|
||||||
unsafe {
|
unsafe {
|
||||||
ncplane_cursor_move_yx(plane, 0, 0);
|
ncplane_cursor_move_yx(plane, 0, 0);
|
||||||
let (mut dimy, mut dimx) = (0, 0);
|
let (mut dimy, mut dimx) = (0, 0);
|
||||||
@ -415,10 +415,10 @@ pub fn ncplane_perimeter(
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_perimeter_double(
|
pub fn ncplane_perimeter_double(
|
||||||
plane: &mut NcPlane,
|
plane: &mut NcPlane,
|
||||||
stylemask: StyleMask,
|
stylemask: NcStyleMask,
|
||||||
channels: Channels,
|
channels: NcChannels,
|
||||||
ctlword: u32,
|
ctlword: u32,
|
||||||
) -> IntResult {
|
) -> NcResult {
|
||||||
if unsafe { ncplane_cursor_move_yx(plane, 0, 0) } != 0 {
|
if unsafe { ncplane_cursor_move_yx(plane, 0, 0) } != 0 {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -464,10 +464,10 @@ pub fn ncplane_perimeter_double(
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_perimeter_rounded(
|
pub fn ncplane_perimeter_rounded(
|
||||||
plane: &mut NcPlane,
|
plane: &mut NcPlane,
|
||||||
stylemask: StyleMask,
|
stylemask: NcStyleMask,
|
||||||
channels: Channels,
|
channels: NcChannels,
|
||||||
ctlword: u32,
|
ctlword: u32,
|
||||||
) -> IntResult {
|
) -> NcResult {
|
||||||
if unsafe { ncplane_cursor_move_yx(plane, 0, 0) } != 0 {
|
if unsafe { ncplane_cursor_move_yx(plane, 0, 0) } != 0 {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -511,19 +511,19 @@ pub fn ncplane_perimeter_rounded(
|
|||||||
|
|
||||||
/// Call ncplane_putc_yx() for the current cursor location.
|
/// Call ncplane_putc_yx() for the current cursor location.
|
||||||
#[inline]
|
#[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) }
|
unsafe { ncplane_putc_yx(plane, -1, -1, cell) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call ncplane_putegc() at the current cursor location.
|
/// Call ncplane_putegc() at the current cursor location.
|
||||||
#[inline]
|
#[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) }
|
unsafe { ncplane_putegc_yx(plane, -1, -1, &gcluster, sbytes) }
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_putstr(plane: &mut NcPlane, gclustarr: &[u8]) -> IntResult {
|
pub fn ncplane_putstr(plane: &mut NcPlane, gclustarr: &[u8]) -> NcResult {
|
||||||
unsafe {
|
unsafe {
|
||||||
ncplane_putstr_yx(
|
ncplane_putstr_yx(
|
||||||
plane,
|
plane,
|
||||||
@ -536,7 +536,7 @@ pub fn ncplane_putstr(plane: &mut NcPlane, gclustarr: &[u8]) -> IntResult {
|
|||||||
|
|
||||||
///
|
///
|
||||||
#[inline]
|
#[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 {
|
unsafe {
|
||||||
ncplane_putnstr_yx(
|
ncplane_putnstr_yx(
|
||||||
plane,
|
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
|
/// Resize the plane, retaining what data we can (everything, unless we're
|
||||||
/// shrinking in some dimension). Keep the origin where it is.
|
/// shrinking in some dimension). Keep the origin where it is.
|
||||||
#[inline]
|
#[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);
|
let (mut oldy, mut oldx) = (0, 0);
|
||||||
unsafe {
|
unsafe {
|
||||||
ncplane_dim_yx(plane, &mut oldy, &mut oldx);
|
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.
|
/// On error, return the negative number of cells drawn.
|
||||||
#[inline]
|
#[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) }
|
unsafe { ncplane_vline_interp(plane, cell, len, cell.channels, cell.channels) }
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
#[inline]
|
#[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 {
|
unsafe {
|
||||||
ncplane_vprintf_yx(
|
ncplane_vprintf_yx(
|
||||||
plane,
|
plane,
|
||||||
@ -602,14 +602,14 @@ pub fn ncplane_vprintf(plane: &mut NcPlane, format: &str, ap: &mut __va_list_tag
|
|||||||
pub fn ncplane_gradient_sized(
|
pub fn ncplane_gradient_sized(
|
||||||
plane: &mut NcPlane,
|
plane: &mut NcPlane,
|
||||||
egc: &[u8],
|
egc: &[u8],
|
||||||
stylemask: StyleMask,
|
stylemask: NcStyleMask,
|
||||||
ul: u64,
|
ul: u64,
|
||||||
ur: u64,
|
ur: u64,
|
||||||
ll: u64,
|
ll: u64,
|
||||||
lr: u64,
|
lr: u64,
|
||||||
ylen: i32,
|
ylen: i32,
|
||||||
xlen: i32,
|
xlen: i32,
|
||||||
) -> IntResult {
|
) -> NcResult {
|
||||||
if ylen < 1 || xlen < 1 {
|
if ylen < 1 || xlen < 1 {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -632,37 +632,37 @@ pub fn ncplane_gradient_sized(
|
|||||||
|
|
||||||
/// Extract the 32-bit working foreground channel from an ncplane.
|
/// Extract the 32-bit working foreground channel from an ncplane.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_fchannel(plane: &NcPlane) -> Channel {
|
pub fn ncplane_fchannel(plane: &NcPlane) -> NcChannel {
|
||||||
channels_fchannel(unsafe { ncplane_channels(plane) })
|
channels_fchannel(unsafe { ncplane_channels(plane) })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the 32-bit working background channel from an ncplane.
|
/// Extract the 32-bit working background channel from an ncplane.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_bchannel(plane: &NcPlane) -> Channel {
|
pub fn ncplane_bchannel(plane: &NcPlane) -> NcChannel {
|
||||||
channels_bchannel(unsafe { ncplane_channels(plane) })
|
channels_bchannel(unsafe { ncplane_channels(plane) })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 24 bits of working foreground RGB from an ncplane, shifted to LSBs.
|
/// Extract 24 bits of working foreground RGB from an ncplane, shifted to LSBs.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_fg_rgb(plane: &NcPlane) -> Channel {
|
pub fn ncplane_fg_rgb(plane: &NcPlane) -> NcChannel {
|
||||||
channels_fg_rgb(unsafe { ncplane_channels(plane) })
|
channels_fg_rgb(unsafe { ncplane_channels(plane) })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 24 bits of working background RGB from an ncplane, shifted to LSBs.
|
/// Extract 24 bits of working background RGB from an ncplane, shifted to LSBs.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_bg_rgb(plane: &NcPlane) -> Channel {
|
pub fn ncplane_bg_rgb(plane: &NcPlane) -> NcChannel {
|
||||||
channels_bg_rgb(unsafe { ncplane_channels(plane) })
|
channels_bg_rgb(unsafe { ncplane_channels(plane) })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 2 bits of foreground alpha from 'struct ncplane', shifted to LSBs.
|
/// Extract 2 bits of foreground alpha from 'struct ncplane', shifted to LSBs.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_fg_alpha(plane: &NcPlane) -> AlphaBits {
|
pub fn ncplane_fg_alpha(plane: &NcPlane) -> NcAlphaBits {
|
||||||
channels_fg_alpha(unsafe { ncplane_channels(plane) })
|
channels_fg_alpha(unsafe { ncplane_channels(plane) })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract 2 bits of background alpha from 'struct ncplane', shifted to LSBs.
|
/// Extract 2 bits of background alpha from 'struct ncplane', shifted to LSBs.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_bg_alpha(plane: &NcPlane) -> AlphaBits {
|
pub fn ncplane_bg_alpha(plane: &NcPlane) -> NcAlphaBits {
|
||||||
channels_bg_alpha(unsafe { ncplane_channels(plane) })
|
channels_bg_alpha(unsafe { ncplane_channels(plane) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,10 +682,10 @@ pub fn ncplane_bg_default_p(plane: &NcPlane) -> bool {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_fg_rgb8(
|
pub fn ncplane_fg_rgb8(
|
||||||
plane: &NcPlane,
|
plane: &NcPlane,
|
||||||
red: &mut Color,
|
red: &mut NcColor,
|
||||||
green: &mut Color,
|
green: &mut NcColor,
|
||||||
blue: &mut Color,
|
blue: &mut NcColor,
|
||||||
) -> Channel {
|
) -> NcChannel {
|
||||||
channels_fg_rgb8(unsafe { ncplane_channels(plane) }, red, green, blue)
|
channels_fg_rgb8(unsafe { ncplane_channels(plane) }, red, green, blue)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -693,10 +693,10 @@ pub fn ncplane_fg_rgb8(
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_bg_rgb8(
|
pub fn ncplane_bg_rgb8(
|
||||||
plane: &NcPlane,
|
plane: &NcPlane,
|
||||||
red: &mut Color,
|
red: &mut NcColor,
|
||||||
green: &mut Color,
|
green: &mut NcColor,
|
||||||
blue: &mut Color,
|
blue: &mut NcColor,
|
||||||
) -> Channel {
|
) -> NcChannel {
|
||||||
channels_bg_rgb8(unsafe { ncplane_channels(plane) }, red, green, blue)
|
channels_bg_rgb8(unsafe { ncplane_channels(plane) }, red, green, blue)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -704,12 +704,12 @@ pub fn ncplane_bg_rgb8(
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_rounded_box(
|
pub fn ncplane_rounded_box(
|
||||||
plane: &mut NcPlane,
|
plane: &mut NcPlane,
|
||||||
stylemask: StyleMask,
|
stylemask: NcStyleMask,
|
||||||
channels: Channels,
|
channels: NcChannels,
|
||||||
ystop: i32,
|
ystop: i32,
|
||||||
xstop: i32,
|
xstop: i32,
|
||||||
ctlword: u32,
|
ctlword: u32,
|
||||||
) -> IntResult {
|
) -> NcResult {
|
||||||
#[allow(unused_assignments)]
|
#[allow(unused_assignments)]
|
||||||
let mut ret = 0;
|
let mut ret = 0;
|
||||||
|
|
||||||
@ -750,12 +750,12 @@ pub fn ncplane_rounded_box(
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn ncplane_rounded_box_sized(
|
pub fn ncplane_rounded_box_sized(
|
||||||
plane: &mut NcPlane,
|
plane: &mut NcPlane,
|
||||||
stylemask: StyleMask,
|
stylemask: NcStyleMask,
|
||||||
channels: Channels,
|
channels: NcChannels,
|
||||||
ylen: i32,
|
ylen: i32,
|
||||||
xlen: i32,
|
xlen: i32,
|
||||||
ctlword: u32,
|
ctlword: u32,
|
||||||
) -> IntResult {
|
) -> NcResult {
|
||||||
let (mut y, mut x) = (0, 0);
|
let (mut y, mut x) = (0, 0);
|
||||||
unsafe {
|
unsafe {
|
||||||
ncplane_cursor_yx(plane, &mut y, &mut x);
|
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
|
/// A coordinate on an [`NcPlane`] storing 128 bits of data
|
||||||
///
|
///
|
||||||
/// ```txt
|
/// ```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
|
/// GCLUSTER GCLUSTER GCLUSTER GCLUSTER 1. NcChar
|
||||||
/// 00000000 ~~~~~~~~ 11111111 11111111 2. EgcBackstop + 3. reserved + 4. StyleMask
|
/// 00000000 ~~~~~~~~ 11111111 11111111 2. NcCharBackstop + 3. reserved + 4. NcStyleMask
|
||||||
/// ~~AA~~~~ RRRRRRRR GGGGGGGG BBBBBBBB 5. Channels
|
/// ~~AA~~~~ RRRRRRRR GGGGGGGG BBBBBBBB 5. NcChannels
|
||||||
/// ~~AA~~~~ RRRRRRRR GGGGGGGG BBBBBBBB |
|
/// ~~AA~~~~ RRRRRRRR GGGGGGGG BBBBBBBB |
|
||||||
///
|
///
|
||||||
/// 1. (32b) Extended Grapheme Cluster, presented either as:
|
/// 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
|
/// UUUUUUUU UUUUUUUU UUUUUUUU UUUUUUUU
|
||||||
///
|
///
|
||||||
/// 1.2. A `0x01` in the first byte, plus 3 bytes with a 24b address to an egcpool:
|
/// 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)
|
/// 3. (8b) reserved (ought to be zero)
|
||||||
/// ~~~~~~~~
|
/// ~~~~~~~~
|
||||||
///
|
///
|
||||||
/// 4. (16b) StyleMask
|
/// 4. (16b) NcStyleMask
|
||||||
/// 11111111 11111111
|
/// 11111111 11111111
|
||||||
///
|
///
|
||||||
/// 5. (64b) Channels
|
/// 5. (64b) NcChannels
|
||||||
/// ~~AA~~~~ RRRRRRRR GGGGGGGG BBBBBBBB|~~AA~~~~ RRRRRRRR GGGGGGGG BBBBBBBB
|
/// ~~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
|
/// occupied by a single grapheme cluster (some root spacing glyph, along with
|
||||||
/// possible combining characters, which might span multiple columns). At any
|
/// possible combining characters, which might span multiple columns). At any
|
||||||
/// cell, we can have a theoretically arbitrarily long UTF-8 string, a
|
/// cell, we can have a theoretically arbitrarily long UTF-8 string, a
|
||||||
@ -44,7 +47,7 @@
|
|||||||
/// characters, followed by a NUL terminator.
|
/// characters, followed by a NUL terminator.
|
||||||
///
|
///
|
||||||
/// Multi-column characters can only have a single style/color throughout.
|
/// 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.
|
/// contains a "Wide Asian" double-width character.
|
||||||
/// This is set for some things, like most emoji, and not set for
|
/// This is set for some things, like most emoji, and not set for
|
||||||
/// other things, like cuneiform.
|
/// other things, like cuneiform.
|
||||||
@ -82,61 +85,61 @@
|
|||||||
///
|
///
|
||||||
/// `type in C: cell (struct)`
|
/// `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
|
/// 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
|
/// 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
|
/// 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
|
/// If this bit *and* CELL_BGDEFAULT_MASK are set, we're using a
|
||||||
/// palette-indexed background color
|
/// 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
|
/// 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
|
/// 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
|
/// 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
|
/// If this bit *and* CELL_BGDEFAULT_MASK are set, we're using a
|
||||||
/// palette-indexed background color
|
/// 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
|
/// 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.
|
/// 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
|
/// Whether a cell is the left or right side of the glyph can be determined
|
||||||
/// by checking whether ->gcluster is zero.
|
/// 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
|
/// Extended Grapheme Cluster. A 32-bit `Char` type
|
||||||
///
|
///
|
||||||
/// This 32 bit char, together with the associated plane's associated egcpool,
|
/// 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:
|
/// four bytes to encode as UTF-8, it will be inlined here:
|
||||||
///
|
///
|
||||||
/// ```txt
|
/// ```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
|
/// byte of this struct (the GClusterBackStop field, see below) is
|
||||||
/// guaranteed to be zero, as are any unused bytes in gcluster.
|
/// guaranteed to be zero, as are any unused bytes in gcluster.
|
||||||
///
|
///
|
||||||
/// A spilled Egc is indicated by the value `0x01iiiiii`. This cannot alias a
|
/// A spilled NcChar is indicated by the value `0x01iiiiii`. This cannot alias a
|
||||||
/// true supra-ASCII Egc, because UTF-8 only encodes bytes <= 0x80 when they
|
/// 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
|
/// 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):
|
/// 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.
|
/// 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*).
|
/// 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,
|
/// 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,
|
/// 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`
|
/// `type in C: uint32_t`
|
||||||
///
|
///
|
||||||
pub type Egc = char;
|
pub type NcChar = char;
|
||||||
|
|
||||||
// EgcBackStop
|
// NcCharBackStop
|
||||||
/// An `u8` always at zero, part of the [`Cell`] struct
|
/// An `u8` always at zero, part of the [`NcCell`] struct
|
||||||
///
|
///
|
||||||
/// ```txt
|
/// ```txt
|
||||||
/// 00000000
|
/// 00000000
|
||||||
@ -183,9 +186,9 @@ pub type Egc = char;
|
|||||||
///
|
///
|
||||||
/// `type in C: uint_8t`
|
/// `type in C: uint_8t`
|
||||||
///
|
///
|
||||||
pub type EgcBackstop = u8;
|
pub type NcCharBackstop = u8;
|
||||||
|
|
||||||
// StyleMask
|
// NcStyleMask
|
||||||
///
|
///
|
||||||
/// An `u16` of `NCSTYLE_*` boolean styling attributes
|
/// An `u16` of `NCSTYLE_*` boolean styling attributes
|
||||||
///
|
///
|
||||||
@ -195,4 +198,4 @@ pub type EgcBackstop = u8;
|
|||||||
///
|
///
|
||||||
/// `type in C: uint16_t`
|
/// `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
|
/// 32 bits of context-dependent info
|
||||||
/// containing RGB + 2 bits of alpha + extra
|
/// containing RGB + 2 bits of alpha + extra
|
||||||
@ -12,19 +15,19 @@
|
|||||||
/// - plus 2 bits of alpha
|
/// - plus 2 bits of alpha
|
||||||
/// - plus context-dependent info
|
/// - plus context-dependent info
|
||||||
///
|
///
|
||||||
/// The context details are documented in [`Channels`]
|
/// The context details are documented in [`NcChannels`]
|
||||||
///
|
///
|
||||||
/// `type in C: channel (uint32_t)`
|
/// `type in C: channel (uint32_t)`
|
||||||
///
|
///
|
||||||
pub type Channel = u32;
|
pub type NcChannel = u32;
|
||||||
|
|
||||||
/// Extract these bits to get a channel's alpha value
|
/// 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).
|
/// 2 bits of alpha (surrounded by context dependent bits).
|
||||||
/// It is part of a Channel.
|
/// It is part of an [`NcChannel`].
|
||||||
///
|
///
|
||||||
/// ```txt
|
/// ```txt
|
||||||
/// ~~AA~~~~ -------- -------- --------
|
/// ~~AA~~~~ -------- -------- --------
|
||||||
@ -32,11 +35,11 @@ pub const CHANNEL_ALPHA_MASK: u32 = crate::bindings::CHANNEL_ALPHA_MASK;
|
|||||||
///
|
///
|
||||||
/// `type in C: no data type`
|
/// `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
|
/// ```txt
|
||||||
/// ~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB|~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB
|
/// ~~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
|
/// Detailed info (specially on the context-dependent bits on each
|
||||||
/// `Channel`'s 4th byte):
|
/// `NcChannel`'s 4th byte):
|
||||||
///
|
///
|
||||||
/// ```txt
|
/// ```txt
|
||||||
/// ~foreground channel~
|
/// ~foreground channel~
|
||||||
@ -97,9 +100,9 @@ pub type AlphaBits = u32;
|
|||||||
///
|
///
|
||||||
/// `type in C: channels (uint64_t)`
|
/// `type in C: channels (uint64_t)`
|
||||||
///
|
///
|
||||||
pub type Channels = u64;
|
pub type NcChannels = u64;
|
||||||
|
|
||||||
// Rgb
|
// NcRgb
|
||||||
//
|
//
|
||||||
/// 24 bits broken into 3x 8bpp channels.
|
/// 24 bits broken into 3x 8bpp channels.
|
||||||
///
|
///
|
||||||
@ -109,9 +112,9 @@ pub type Channels = u64;
|
|||||||
///
|
///
|
||||||
/// `type in C: no data type`
|
/// `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
|
/// 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`
|
/// `type in C: no data type`
|
||||||
///
|
///
|
||||||
pub type Color = u8;
|
pub type NcColor = u8;
|
||||||
|
|
||||||
// NcPixel (RGBA)
|
// NcPixel (RGBA)
|
||||||
/// 32 bits broken into RGB + 8-bit alpha
|
/// 32 bits broken into RGB + 8-bit alpha
|
||||||
@ -138,10 +141,10 @@ pub type Color = u8;
|
|||||||
///
|
///
|
||||||
/// `type in C: ncpixel (uint32_t)`
|
/// `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;
|
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
|
/// Some terminals only support 256 colors, but allow the full
|
||||||
/// palette to be specified with arbitrary RGB colors. In all cases, it's more
|
/// 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)`
|
/// `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
|
/// Context for a palette fade operation
|
||||||
pub type NcFadeCtx = crate::ncfadectx;
|
pub type NcFadeCtx = crate::ncfadectx;
|
||||||
|
|
||||||
/// the [`Egc`]s which form the various levels
|
/// the [`NcChar`] which form the various levels
|
||||||
/// of a given geometry.
|
/// of a given geometry.
|
||||||
///
|
///
|
||||||
/// If the geometry is wide, things are arranged with the rightmost side
|
/// 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)`
|
/// `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};
|
use std::io::{Error, ErrorKind, Read, Seek, SeekFrom};
|
||||||
|
|
||||||
pub use libc::{
|
pub use libc::{c_long, c_void, fclose, feof, fread, fseek, ftell, SEEK_CUR, SEEK_END, SEEK_SET};
|
||||||
c_long, c_void, fclose, feof, fread, fseek, ftell, SEEK_CUR, SEEK_END,
|
|
||||||
SEEK_SET,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// notcurses functions expects this type of *FILE (struct)
|
/// 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)
|
/// 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.
|
/// Intended to be passed into the CFile::open method.
|
||||||
/// It will open the file in a way that will allow reading and writing,
|
/// 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
|
/// A wrapper struct around libc::FILE
|
||||||
///
|
///
|
||||||
/// The notcurses FILE type `NC_FILE` is imported through bindgen as a struct,
|
/// The notcurses FILE type `FILE_NC` is imported through bindgen as a struct,
|
||||||
/// while the equivalent Rust libc::FILE (`LIBC_FILE`) is an opaque enum.
|
/// while the equivalent Rust libc::FILE (`FILE_LIBC`) is an opaque enum.
|
||||||
/// Several methods are provided to convert back and forth between both types,
|
/// Several methods are provided to convert back and forth between both types,
|
||||||
/// to allow both rust libc operations and notcurses file operations on it.
|
/// to allow both rust libc operations and notcurses file operations on it.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct NcFile {
|
pub struct NcFile {
|
||||||
file_ptr: NonNull<LIBC_FILE>,
|
file_ptr: NonNull<FILE_LIBC>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NcFile {
|
impl NcFile {
|
||||||
// constructors --
|
// constructors --
|
||||||
|
|
||||||
/// `NcFile` constructor from a file produced by notcurses
|
/// `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 {
|
NcFile {
|
||||||
file_ptr: unsafe { NonNull::new_unchecked(NcFile::nc2libc(file)) },
|
file_ptr: unsafe { NonNull::new_unchecked(NcFile::nc2libc(file)) },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `NcFile` constructor from a file produced by the libc crate
|
/// `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 {
|
NcFile {
|
||||||
file_ptr: unsafe { NonNull::new_unchecked(file) },
|
file_ptr: unsafe { NonNull::new_unchecked(file) },
|
||||||
}
|
}
|
||||||
@ -89,13 +86,13 @@ impl NcFile {
|
|||||||
|
|
||||||
/// Returns the file pointer in the format expected by libc
|
/// Returns the file pointer in the format expected by libc
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_libc_ptr(&self) -> *mut LIBC_FILE {
|
pub fn as_libc_ptr(&self) -> *mut FILE_LIBC {
|
||||||
self.file_ptr.as_ptr()
|
self.file_ptr.as_ptr()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the file pointer in the format expected by notcurses
|
/// Returns the file pointer in the format expected by notcurses
|
||||||
#[inline]
|
#[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())
|
Self::libc2nc(self.file_ptr.as_ptr())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,15 +124,15 @@ impl NcFile {
|
|||||||
/// Converts a file pointer from the struct notcurses uses to the
|
/// Converts a file pointer from the struct notcurses uses to the
|
||||||
/// opaque enum type libc expects
|
/// opaque enum type libc expects
|
||||||
#[inline]
|
#[inline]
|
||||||
fn nc2libc(file: *mut NC_FILE) -> *mut LIBC_FILE {
|
fn nc2libc(file: *mut FILE_NC) -> *mut FILE_LIBC {
|
||||||
file as *mut _ as *mut LIBC_FILE
|
file as *mut _ as *mut FILE_LIBC
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a file pointer from the libc opaque enum format to the struct
|
/// Converts a file pointer from the libc opaque enum format to the struct
|
||||||
/// expected by notcurses
|
/// expected by notcurses
|
||||||
#[inline]
|
#[inline]
|
||||||
fn libc2nc(file: *mut LIBC_FILE) -> *mut NC_FILE {
|
fn libc2nc(file: *mut FILE_LIBC) -> *mut FILE_NC {
|
||||||
file as *mut _ as *mut NC_FILE
|
file as *mut _ as *mut FILE_NC
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A utility function to expand a vector without increasing its capacity
|
/// 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() {
|
if !(self.as_libc_ptr()).is_null() {
|
||||||
let res = fclose(self.as_libc_ptr());
|
let res = fclose(self.as_libc_ptr());
|
||||||
if res == 0 {
|
if res == 0 {
|
||||||
self.file_ptr = NonNull::new_unchecked(null_mut::<LIBC_FILE>());
|
self.file_ptr = NonNull::new_unchecked(null_mut::<FILE_LIBC>());
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
get_error()
|
get_error()
|
||||||
|
@ -4,7 +4,11 @@
|
|||||||
// error handling --------------------------------------------------------------
|
// error handling --------------------------------------------------------------
|
||||||
|
|
||||||
/// `i32` value used to return errors, when value < 0, (usually -1)
|
/// `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 --------------------------------------------------------------------
|
// ncmetric --------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -22,18 +22,18 @@ mod terminal;
|
|||||||
mod widgets;
|
mod widgets;
|
||||||
|
|
||||||
pub use cell::{
|
pub use cell::{
|
||||||
Cell, Egc, EgcBackstop, StyleMask, CELL_ALPHA_BLEND, CELL_ALPHA_HIGHCONTRAST,
|
NcCell, NcChar, NcCharBackstop, NcStyleMask, NCCELL_ALPHA_BLEND, NCCELL_ALPHA_HIGHCONTRAST,
|
||||||
CELL_ALPHA_OPAQUE, CELL_ALPHA_TRANSPARENT, CELL_BGDEFAULT_MASK, CELL_BG_ALPHA_MASK,
|
NCCELL_ALPHA_OPAQUE, NCCELL_ALPHA_TRANSPARENT, NCCELL_BGDEFAULT_MASK, NCCELL_BG_ALPHA_MASK,
|
||||||
CELL_BG_PALETTE, CELL_BG_RGB_MASK, CELL_FGDEFAULT_MASK, CELL_FG_ALPHA_MASK, CELL_FG_PALETTE,
|
NCCELL_BG_PALETTE, NCCELL_BG_RGB_MASK, NCCELL_FGDEFAULT_MASK, NCCELL_FG_ALPHA_MASK,
|
||||||
CELL_FG_RGB_MASK, CELL_NOBACKGROUND_MASK, CELL_WIDEASIAN_MASK,
|
NCCELL_FG_PALETTE, NCCELL_FG_RGB_MASK, NCCELL_NOBACKGROUND_MASK, NCCELL_WIDEASIAN_MASK,
|
||||||
};
|
};
|
||||||
pub use channel::{
|
pub use channel::{
|
||||||
AlphaBits, BlitSet, Channel, Channels, Color, NcFadeCtx, NcPixel, Palette, PaletteIndex, Rgb,
|
NcAlphaBits, NcBlitSet, NcChannel, NcChannels, NcColor, NcFadeCtx, NcPalette, NcPaletteIndex,
|
||||||
CHANNEL_ALPHA_MASK,
|
NcPixel, NcRgb, NCCHANNEL_ALPHA_MASK,
|
||||||
};
|
};
|
||||||
pub use file::{NcFile, LIBC_FILE, NC_FILE};
|
pub use file::{NcFile, FILE_LIBC, FILE_NC};
|
||||||
pub use misc::{
|
pub use misc::{
|
||||||
IntResult, BPREFIXCOLUMNS, BPREFIXSTRLEN, IPREFIXCOLUMNS, IPREFIXSTRLEN, PREFIXCOLUMNS,
|
NcResult, BPREFIXCOLUMNS, BPREFIXSTRLEN, IPREFIXCOLUMNS, IPREFIXSTRLEN, PREFIXCOLUMNS,
|
||||||
PREFIXSTRLEN,
|
PREFIXSTRLEN,
|
||||||
};
|
};
|
||||||
pub use plane::{
|
pub use plane::{
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
#[allow(unused_imports)] // for docblocks
|
||||||
|
use crate::NCCELL_ALPHA_BLEND;
|
||||||
|
|
||||||
// NcPlane
|
// NcPlane
|
||||||
/// Fundamental drawing surface.
|
/// Fundamental drawing surface.
|
||||||
///
|
///
|
||||||
@ -101,7 +104,7 @@ pub type NcVisual = crate::ncvisual;
|
|||||||
/// Options struct for [`NcVisual`]
|
/// Options struct for [`NcVisual`]
|
||||||
pub type NcVisualOptions = crate::ncvisual_options;
|
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;
|
pub const NCVISUAL_OPTION_BLEND: u32 = crate::bindings::NCVISUAL_OPTION_BLEND;
|
||||||
|
|
||||||
/// Fail rather than degrade
|
/// Fail rather than degrade
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
//! Types for notcurses widgets
|
//! Types for notcurses widgets
|
||||||
|
|
||||||
|
#[allow(unused_imports)] // for docblocks
|
||||||
|
use crate::NcPlane;
|
||||||
|
|
||||||
// NcMenu ----------------------------------------------------------------------
|
// NcMenu ----------------------------------------------------------------------
|
||||||
|
|
||||||
/// menus on the top or bottom rows
|
/// menus on the top or bottom rows
|
||||||
|
@ -18,7 +18,7 @@ use std::ffi::CString;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ncmenu_create,
|
ncmenu_create,
|
||||||
types::{Channels, NcInput, NcMenu, NcMenuItem, NcMenuOptions, NcMenuSection, NcPlane},
|
types::{NcChannels, NcInput, NcMenu, NcMenuItem, NcMenuOptions, NcMenuSection, NcPlane},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl NcMenu {
|
impl NcMenu {
|
||||||
@ -43,8 +43,8 @@ impl NcMenuOptions {
|
|||||||
pub fn with_options(
|
pub fn with_options(
|
||||||
sections: &mut [NcMenuSection],
|
sections: &mut [NcMenuSection],
|
||||||
count: u32,
|
count: u32,
|
||||||
headerc: Channels,
|
headerc: NcChannels,
|
||||||
sectionc: Channels,
|
sectionc: NcChannels,
|
||||||
flags: u64,
|
flags: u64,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
Loading…
Reference in New Issue
Block a user