nccell

Struct nccell 

Source
#[repr(C)]
pub struct nccell { pub gcluster: u32, pub gcluster_backstop: u8, pub width: u8, pub stylemask: u16, pub channels: u64, }
Expand description

An nccell corresponds to a single character cell on some plane, which can be occupied by a single grapheme cluster (some root spacing glyph, along with possible combining characters, which might span multiple columns). At any cell, we can have a theoretically arbitrarily long UTF-8 EGC, a foreground color, a background color, and an attribute set. Valid grapheme cluster contents include:

  • A NUL terminator,
  • A single control character, followed by a NUL terminator,
  • At most one spacing character, followed by zero or more nonspacing characters, followed by a NUL terminator.

Multi-column characters can only have a single style/color throughout. Existence is suffering, and thus wcwidth() is not reliable. It’s just quoting whether or not the EGC contains a “Wide Asian” double-width character. This is set for some things, like most emoji, and not set for other things, like cuneiform. True display width is a function of the font and terminal. Among the longest Unicode codepoints is

U+FDFD ARABIC LIGATURE BISMILLAH AR-RAHMAN AR-RAHEEM ﷽

wcwidth() rather optimistically claims this most exalted glyph to occupy a single column. BiDi text is too complicated for me to even get into here. Be assured there are no easy answers; ours is indeed a disturbing Universe.

Each nccell occupies 16 static bytes (128 bits). The surface is thus ~1.6MB for a (pretty large) 500x200 terminal. At 80x43, it’s less than 64KB. Dynamic requirements (the egcpool) can add up to 16MB to an ncplane, but such large pools are unlikely in common use.

We implement some small alpha compositing. Foreground and background both have two bits of inverted alpha. The actual grapheme written to a cell is the topmost non-zero grapheme. If its alpha is 00, its foreground color is used unchanged. If its alpha is 10, its foreground color is derived entirely from cells underneath it. Otherwise, the result will be a composite. Likewise for the background. If the bottom of a coordinate’s zbuffer is reached with a cumulative alpha of zero, the default is used. In this way, a terminal configured with transparent background can be supported through multiple occluding ncplanes. A foreground alpha of 11 requests high-contrast text (relative to the computed background). A background alpha of 11 is currently forbidden.

Default color takes precedence over palette or RGB, and cannot be used with transparency. Indexed palette takes precedence over RGB. It cannot meaningfully set transparency, but it can be mixed into a cascading color. RGB is used if neither default terminal colors nor palette indexing are in play, and fully supports all transparency options.

This structure is exposed only so that most functions can be inlined. Do not directly modify or access the fields of this structure; use the API.

Fields§

§gcluster: u32

4B → 4B little endian EGC

§gcluster_backstop: u8

1B → 5B (8 bits of zero)

§width: u8

1B → 6B (8 bits of EGC column width)

§stylemask: u16

2B → 8B (16 bits of NCSTYLE_* attributes)

§channels: u64
  • 8B == 16B

Implementations§

Source§

impl nccell

§NcCell constructors

Source

pub fn from_char7b(ch: char) -> NcResult<Self>

New NcCell, expects a 7-bit char.

Source

pub fn from_char(plane: &mut NcPlane, ch: char) -> NcResult<Self>

New NcCell, from a char.

Expects a plane where to save the extra data if it’s greater than 4 bytes.

Source

pub fn from_str(plane: &mut NcPlane, string: &str) -> NcResult<Self>

New NcCell, from a &str.

Expects a plane where to save the extra data if it’s greater than 4 bytes.

Source

pub fn new() -> Self

New empty NcCell.

Source

pub fn load(plane: &mut NcPlane, cell: &mut NcCell, egc: &str) -> NcResult<u32>

Breaks the UTF-8 string in egc down, setting up this NcCell, and returns the number of bytes copied out of egc.

The styling of the cell is left untouched, but any resources are released. C style function: nccell_load().

Source

pub fn prime( plane: &mut NcPlane, cell: &mut NcCell, gcluster: &str, style: impl Into<NcStyle>, channels: impl Into<NcChannels>, ) -> NcResult<u32>

Same as load, plus blasts the styling with style and channels.

  • Breaks the UTF-8 string in gcluster down, setting up this NcCell.
  • Returns the number of bytes copied out of gcluster.
  • Any resources are released.
  • Blasts the styling with style and channels.

C style function: nccell_prime().

Source

pub fn duplicate(&self, common_plane: &mut NcPlane) -> NcResult<NcCell>

Duplicate this NcCell into another one.

Both must be or will be bound to common_plane.

C style function: nccell_duplicate().

Source

pub fn init(&mut self)

Initializes (zeroes out) this NcCell.

C style function: nccell_init().

Source

pub fn release(&mut self, plane: &mut NcPlane)

Releases resources held by the current cell in the NcPlane plane.

C style function: nccell_release().

Source§

impl nccell

§NcCell methods: bg|fg NcChannels manipulation.
Source

pub fn bchannel(&self) -> NcChannel

Gets the background alpha and coloring bits from the cell NcChannels as an NcChannel.

C style function: nccell_bchannel().

Source

pub fn fchannel(&self) -> NcChannel

Gets the foreground alpha and coloring bits from the cell NcChannels as an NcChannel.

C style function: nccell_fchannel().

Source

pub fn channels(&self) -> NcChannels

Gets the alpha and coloring bits from the cell NcChannels.

C style function: nccell_channels().

Source

pub fn set_bchannel(&mut self, from: impl Into<NcChannel>) -> NcChannels

Sets the background alpha and coloring bits of the cell NcChannels, returning the new NcChannels_u64.

C style function: nccell_bchannel().

Source

pub fn set_fchannel(&mut self, from: impl Into<NcChannel>) -> NcChannels

Sets the foreground alpha and coloring bits from the cell NcChannels, returning the new NcChannels_u64.

C style function: nccell_set_fchannel().

Source

pub fn set_channels(&mut self, from: impl Into<NcChannels>) -> NcChannels

Sets the alpha and coloring bits of the cell NcChannels from another NcChannels, returning the new NcChannels.

C style function: nccell_set_channels().

Source

pub fn bg_alpha(&self) -> NcAlpha

Gets the background NcAlpha (shifted to LSBs).

C style function: nccell_bg_alpha().

Source

pub fn bg_default_p(&self) -> bool

Is the background NcChannel using the “default background color”?

C style function: nccell_bg_default_p().

Source

pub fn bg_palindex(&self) -> NcPaletteIndex

Gets the NcPaletteIndex of the background NcChannel.

C style function: nccell_bg_palindex().

Source

pub fn bg_palindex_p(&self) -> bool

Is the background NcChannel using an NcPaletteIndex indexed NcPalette color?

C style function: nccell_bg_palindex_p().

Source

pub fn bg_rgb(&self) -> NcRgb

Gets the background NcRgb (shifted to LSBs).

C style function: nccell_bg_rgb().

Source

pub fn fg_alpha(&self) -> NcAlpha

Gets the foreground NcAlpha (shifted to LSBs).

C style function: nccell_fg_alpha().

Source

pub fn fg_default_p(&self) -> bool

Is the foreground NcChannel using the “default foreground color”?

C style function: nccell_fg_default_p().

Source

pub fn fg_palindex(&self) -> NcPaletteIndex

Gets the NcPaletteIndex of the foreground NcChannel.

C style function: nccell_fg_palindex().

Source

pub fn fg_palindex_p(&self) -> bool

Is the foreground NcChannel using an NcPaletteIndex indexed NcPalette color?

C style function: nccell_fg_palindex_p().

Source

pub fn fg_rgb(&self) -> NcRgb

Gets the foreground NcRgb (shifted to LSBs).

C style function: nccell_fg_rgb().

Source

pub fn set_bg_alpha(&mut self, alpha: impl Into<NcAlpha>)

Sets the background NcAlpha.

C style function: nccell_set_bg_alpha().

Source

pub fn set_bg_default(&mut self)

Indicates to use the “default color” for the background NcChannel.

C style function: nccell_set_bg_default().

Source

pub fn set_bg_palindex(&mut self, index: impl Into<NcPaletteIndex>)

Sets the background NcPaletteIndex.

Also sets NcChannels::BG_PALETTE_MASK and NcAlpha::OPAQUE, and clears out NcChannels::BG_DEFAULT_MASK.

C style function: nccell_set_bg_palindex().

Source

pub fn set_bg_rgb(&mut self, rgb: impl Into<NcRgb>)

Sets the background NcRgb and marks it as not using the default color.

C style function: nccell_set_bg_rgb().

Source

pub fn set_fg_alpha(&mut self, alpha: impl Into<NcAlpha>)

Sets the foreground NcAlpha.

C style function: nccell_set_fg_alpha().

Source

pub fn set_fg_default(&mut self)

Indicates to use the “default color” for the foreground NcChannel.

C style function: nccell_set_fg_default().

Source

pub fn set_fg_palindex(&mut self, index: impl Into<NcPaletteIndex>)

Sets the foreground NcPaletteIndex.

Also sets NcChannels::FG_PALETTE_MASK and NcAlpha::OPAQUE, and clears out NcChannels::FG_DEFAULT_MASK.

C style function: nccell_set_fg_palindex().

Source

pub fn set_fg_rgb(&mut self, rgb: impl Into<NcRgb>)

Sets the foreground NcRgb and marks it as not using the default color.

C style function: nccell_set_fg_rgb().

Source§

impl nccell

§NcCell methods: other components

Source

pub fn compare( plane1: &NcPlane, cell1: &NcCell, plane2: &NcPlane, cell2: &NcCell, ) -> bool

Available on crate feature libc only.

Returns true if the two cells have distinct EGCs, attributes, or NcChannels.

The actual egcpool index needn’t be the same–indeed, the planes needn’t even be the same. Only the expanded EGC must be bit-equal.

C style function: nccellcmp().

Source

pub fn extract( &self, plane: &mut NcPlane, styles: &mut NcStyle, channels: &mut NcChannels, ) -> String

Available on crate feature libc only.

Saves the NcStyle and the NcChannels, and returns the duplicatd EGC.

C style function: nccell_fg_alpha().

Source

pub fn styles(&self) -> NcStyle

Returns the NcStyle bits.

C style function: nccell_styles().

Source

pub fn styles_off(&mut self, stylebits: impl Into<NcStyle>)

Removes the specified NcStyle bits.

C style function: nccell_off_styles().

Source

pub fn styles_on(&mut self, stylebits: impl Into<NcStyle>)

Adds the specified NcStyle bits.

C style function: nccell_on_styles().

Source

pub fn styles_set(&mut self, stylebits: impl Into<NcStyle>)

Sets just the specified NcStyle bits.

C style function: nccell_set_styles().

Source§

impl nccell

§NcCell methods: text

Source

pub const fn cols(&self) -> u8

Returns the number of columns occupied by the cell.

See ncstrwidth for an equivalent for multiple EGCs.

C style function: nccell_cols().

Source

pub fn egc(&self, plane: &NcPlane) -> &str

Returns a pointer to the EGC of this NcCell in the plane.

This pointer can be invalidated by any further operation on the referred plane, so… watch out!

C style function: nccell_extended_gcluster().

Source

pub fn strdup(&self, plane: &NcPlane) -> String

Available on crate feature libc only.

Copies the UTF8-encoded EGC out of this NcCell, whether simple or complex.

The result is not tied to the NcPlane, and persists across erases and destruction.

C style function: nccell_strdup().

Source

pub fn double_wide_p(&self) -> bool

Does this NcCell contain a wide codepoint?

C style function: nccell_double_wide_p().

Source

pub fn wide_left_p(&self) -> bool

Is this the left half of a wide character?

C style function: nccell_wide_left_p().

Source

pub fn wide_right_p(&self) -> bool

Is this the right side of a wide character?

C style function: nccell_wide_right_p().

Source§

impl nccell

§NcCell methods: boxes

Source

pub fn load_box( plane: &mut NcPlane, style: impl Into<NcStyle>, channels: impl Into<NcChannels>, ul: &mut NcCell, ur: &mut NcCell, ll: &mut NcCell, lr: &mut NcCell, hl: &mut NcCell, vl: &mut NcCell, gcluster: &str, ) -> NcResult<()>

Loads up six cells with the EGCs necessary to draw a box.

On error, any NcCells this function might have loaded before the error are released. There must be at least six EGCs in gcluster.

C style function: nccells_load_box().

Source

pub fn double_box( plane: &mut NcPlane, style: impl Into<NcStyle>, channels: impl Into<NcChannels>, ul: &mut NcCell, ur: &mut NcCell, ll: &mut NcCell, lr: &mut NcCell, hl: &mut NcCell, vl: &mut NcCell, ) -> NcResult<()>

NcCell.load_box() with the double box-drawing characters.

C style function: nccells_double_box().

Source

pub fn rounded_box( plane: &mut NcPlane, style: impl Into<NcStyle>, channels: impl Into<NcChannels>, ul: &mut NcCell, ur: &mut NcCell, ll: &mut NcCell, lr: &mut NcCell, hl: &mut NcCell, vl: &mut NcCell, ) -> NcResult<()>

NcCell.load_box() with the rounded box-drawing characters.

C style function: nccells_rounded_box().

Source

pub fn ascii_box( plane: &mut NcPlane, style: impl Into<NcStyle>, channels: impl Into<NcChannels>, ul: &mut NcCell, ur: &mut NcCell, ll: &mut NcCell, lr: &mut NcCell, hl: &mut NcCell, vl: &mut NcCell, ) -> NcResult<()>

NcCell.load_box() with ASCII characters.

C style function: nccells_ascii_box().

Source

pub fn heavy_box( plane: &mut NcPlane, style: impl Into<NcStyle>, channels: impl Into<NcChannels>, ul: &mut NcCell, ur: &mut NcCell, ll: &mut NcCell, lr: &mut NcCell, hl: &mut NcCell, vl: &mut NcCell, ) -> NcResult<()>

NcCell.load_box() with the heavy line box-drawing characters.

C style function: nccells_heavy_box().

Source

pub fn light_box( plane: &mut NcPlane, style: impl Into<NcStyle>, channels: impl Into<NcChannels>, ul: &mut NcCell, ur: &mut NcCell, ll: &mut NcCell, lr: &mut NcCell, hl: &mut NcCell, vl: &mut NcCell, ) -> NcResult<()>

NcCell.load_box() with the light line box-drawing characters.

C style function: nccells_light_box().

Trait Implementations§

Source§

impl Clone for nccell

Source§

fn clone(&self) -> nccell

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for nccell

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for nccell

Source§

fn default() -> nccell

Returns the “default value” for a type. Read more
Source§

impl Hash for nccell

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for nccell

Source§

fn cmp(&self, other: &nccell) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for nccell

Source§

fn eq(&self, other: &nccell) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for nccell

Source§

fn partial_cmp(&self, other: &nccell) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for nccell

Source§

impl Eq for nccell

Source§

impl StructuralPartialEq for nccell

Auto Trait Implementations§

§

impl Freeze for nccell

§

impl RefUnwindSafe for nccell

§

impl Send for nccell

§

impl Sync for nccell

§

impl Unpin for nccell

§

impl UnwindSafe for nccell

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.