rust: refactor NcCell constructors

pull/1253/head
joseLuís 4 years ago
parent 815507293d
commit b62c1ec74b

@ -3,12 +3,10 @@ use libnotcurses_sys::*;
fn main() {
unsafe {
let nc = Notcurses::new();
// use standard plane
let stdplane = notcurses_stdplane(nc);
for ch in "Initializing cells...".chars() {
let cell = NcCell::with_7bitchar(ch);
let cell = NcCell::with_char7b(ch);
sleep![60];
ncplane_putc(&mut *stdplane, &cell);
let _ = notcurses_render(nc);

@ -8,7 +8,7 @@ fn main() {
let plane = nc.stdplane();
plane.set_scrolling(true);
let mut wc = '\u{4e00}'; // '';
let mut wc = '\u{4e00}'; //
loop {
sleep![1];

@ -9,7 +9,7 @@ use crate::{
impl NcCell {
/// New NcCell, expects a 7-bit [char].
#[inline]
pub const fn with_7bitchar(ch: char) -> Self {
pub const fn with_char7b(ch: char) -> Self {
NcCell {
gcluster: (ch as u32).to_le(),
gcluster_backstop: 0 as NcEgcBackstop,
@ -21,7 +21,7 @@ impl NcCell {
/// New NcCell, expects an [NcPlane] and a [char].
#[inline]
pub fn with_char(plane: &mut NcPlane, ch: char) -> Self {
pub fn with_char(ch: char, plane: &mut NcPlane) -> Self {
let mut cell = Self::new();
let result = unsafe { cell_load(plane, &mut cell, cstring![ch.to_string()]) };
debug_assert_ne![NCRESULT_ERR, result];
@ -40,7 +40,7 @@ impl NcCell {
/// New empty NcCell.
#[inline]
pub const fn new() -> Self {
Self::with_7bitchar(0 as char)
Self::with_char7b(0 as char)
}
}

@ -118,6 +118,18 @@ impl Notcurses {
/// # `Notcurses` methods
impl Notcurses {
//
// /// Returns the offset into 'availcols' at which 'cols' ought be output given
// /// the requirements of `align`.
// ///
// /// Returns -NCRESULT_MAX if NCALIGN_UNALIGNED or invalid NcAlign.
//
// ///
// /// *C style function: [notcurses_at_yx()][crate::notcurses_at_yx].*
// pub fn canchangecolor(&self) -> bool {
// unsafe { crate::notcurses_canchangecolor(self) }
// }
/// Retrieves the current contents of the specified [NcCell][crate::NcCell]
/// as last rendered, returning the [NcEgc] (or None on error) and writing
/// out the [NcStyleMask] and the [NcChannelPair].

@ -53,7 +53,7 @@
// (#) test: 0
// (W) wrap: 2
// -----------------------------------------
// # notcurses_align
//W# notcurses_align
//W+ notcurses_getc_blocking
//W+ notcurses_getc_nblock
// + notcurses_stddim_yx

@ -128,7 +128,7 @@ pub fn ncplane_putc(plane: &mut NcPlane, cell: &NcCell) -> NcResult {
#[inline]
pub fn ncplane_putchar(plane: &mut NcPlane, ch: char) -> NcResult {
unsafe {
let cell = NcCell::with_char(plane, ch);
let cell = NcCell::with_char(ch, plane);
crate::ncplane_putc_yx(plane, -1, -1, &cell)
}
}
@ -145,7 +145,7 @@ pub fn ncplane_putchar_yx(
ch: char,
) -> NcResult {
unsafe {
let cell = NcCell::with_char(plane, ch);
let cell = NcCell::with_char(ch, plane);
crate::ncplane_putc_yx(plane, y as i32, x as i32, &cell)
}
}

Loading…
Cancel
Save