Merge branch 'master' of github.com:dankamongmen/notcurses into master

pull/907/head
nick black 4 years ago
commit 74537f0848
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -23,7 +23,7 @@ fn render_image(ncd: &mut nc::ncdirect, blit: nc::ncblitter_e) {
unsafe { unsafe {
if nc::ncdirect_render_image( if nc::ncdirect_render_image(
ncd, ncd,
CString::new("direct-image.png").unwrap().as_ptr(), CString::new("image-16x16.png").unwrap().as_ptr(),
nc::ncalign_e_NCALIGN_CENTER, nc::ncalign_e_NCALIGN_CENTER,
blit, blit,
nc::ncscale_e_NCSCALE_NONE, nc::ncscale_e_NCSCALE_NONE,

Before

Width:  |  Height:  |  Size: 435 B

After

Width:  |  Height:  |  Size: 435 B

@ -61,13 +61,14 @@
use cstr_core::CString; use cstr_core::CString;
use crate as ffi; use crate as ffi;
use crate::types::{ChannelPair, IntResult}; use ffi::types::{ChannelPair, IntResult};
use ffi::{cell, ncplane};
/// cell_load(), plus blast the styling with 'attr' and 'channels'. /// cell_load(), plus blast the styling with 'attr' and 'channels'.
// TODO: TEST // TODO: TEST
pub fn cell_prime( pub fn cell_prime(
plane: *mut ffi::ncplane, plane: &mut ffi::ncplane,
cell: *mut ffi::cell, cell: &mut ffi::cell,
gcluster: &str, gcluster: &str,
style: u16, style: u16,
channels: ChannelPair, channels: ChannelPair,
@ -94,15 +95,15 @@ pub fn cell_prime(
// TODO: TEST // TODO: TEST
// FIXME missing cell_prime()s // FIXME missing cell_prime()s
pub fn cells_load_box( pub fn cells_load_box(
plane: *mut ffi::ncplane, plane: &mut ncplane,
style: u16, style: u16,
channels: ChannelPair, channels: ChannelPair,
_ul: *mut ffi::cell, _ul: &mut cell,
_ur: *mut ffi::cell, _ur: &mut cell,
_ll: *mut ffi::cell, _ll: &mut cell,
_lr: *mut ffi::cell, _lr: &mut cell,
_hl: *mut ffi::cell, _hl: &mut cell,
_vl: *mut ffi::cell, _vl: &mut cell,
gcluster: &str, gcluster: &str,
) -> IntResult { ) -> IntResult {
cell_prime(plane, _ul, gcluster, style, channels) cell_prime(plane, _ul, gcluster, style, channels)
@ -138,17 +139,17 @@ pub fn cells_load_box(
// memset(c, 0, sizeof(*c)); // memset(c, 0, sizeof(*c));
// } // }
// //
// // Set the specified style bits for the cell 'c', whether they're actively // Set the specified style bits for the cell 'c', whether they're actively
// // supported or not. // supported or not. Only the lower 16 bits are meaningful.
// static inline void // static inline void
// cell_styles_set(cell* c, unsigned stylebits){ // cell_styles_set(cell* c, unsigned stylebits){
// c->stylemask = (c->stylemask & ~NCSTYLE_MASK) | ((stylebits & NCSTYLE_MASK)); // c->stylemask = stylebits & NCSTYLE_MASK;
// } // }
// //
// // Extract the style bits from the cell's stylemask. // // Extract the style bits from the cell.
// static inline unsigned // static inline unsigned
// cell_styles(const cell* c){ // cell_styles(const cell* c){
// return c->stylemask & NCSTYLE_MASK; // return c->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
@ -204,32 +205,17 @@ pub fn cells_load_box(
// return cell_double_wide_p(c) && c->gcluster; // return cell_double_wide_p(c) && c->gcluster;
// } // }
// //
// // Is the cell simple (a lone ASCII character, encoded as such)?
// static inline bool
// cell_simple_p(const cell* c){
// return c->gcluster < 0x80;
// }
//
// // copy the UTF8-encoded EGC out of the cell, whether simple or complex. the // // copy the UTF8-encoded EGC 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.
// static inline char* // static inline char*
// cell_strdup(const struct ncplane* n, const cell* c){ // cell_strdup(const struct ncplane* n, const cell* c){
// char* ret; // return strdup(cell_extended_gcluster(n, c));
// if(cell_simple_p(c)){
// if( (ret = (char*)malloc(2)) ){ // cast is here for C++ clients
// ret[0] = c->gcluster;
// ret[1] = '\0';
// }
// }else{
// ret = strdup(cell_extended_gcluster(n, c));
// }
// return ret;
// } // }
// //
// // Extract the three elements of a cell. // // Extract the three elements of a cell.
// static inline char* // static inline char*
// cell_extract(const struct ncplane* n, const cell* c, // cell_extract(const struct ncplane* n, const cell* c,
// uint32_t* stylemask, uint64_t* channels){ // uint16_t* stylemask, uint64_t* channels){
// if(stylemask){ // if(stylemask){
// *stylemask = c->stylemask; // *stylemask = c->stylemask;
// } // }
@ -252,24 +238,15 @@ pub fn cells_load_box(
// if(c1->channels != c2->channels){ // if(c1->channels != c2->channels){
// return true; // return true;
// } // }
// if(cell_simple_p(c1) && cell_simple_p(c2)){
// return c1->gcluster != c2->gcluster;
// }
// if(cell_simple_p(c1) || cell_simple_p(c2)){
// return true;
// }
// return strcmp(cell_extended_gcluster(n1, c1), cell_extended_gcluster(n2, c2)); // return strcmp(cell_extended_gcluster(n1, c1), cell_extended_gcluster(n2, c2));
// } // }
// //
// static inline int // static inline int
// cell_load_simple(struct ncplane* n, cell* c, char ch){ // cell_load_simple(struct ncplane* n, cell* c, char ch){
// cell_release(n, c); // cell_release(n, c);
// c->channels &= ~CELL_WIDEASIAN_MASK; // c->channels &= ~(CELL_WIDEASIAN_MASK | CELL_NOBACKGROUND_MASK);
// c->gcluster = ch; // c->gcluster = ch;
// if(cell_simple_p(c)){ // return 1;
// return 1;
// }
// return -1;
// } // }
// //
// // Extract the 32-bit background channel from a cell. // // Extract the 32-bit background channel from a cell.
@ -361,9 +338,7 @@ pub fn cells_load_box(
// cell_set_fg(cell* c, uint32_t channel){ // cell_set_fg(cell* c, uint32_t channel){
// return channels_set_fg(&c->channels, channel); // return channels_set_fg(&c->channels, channel);
// } // }
//
// // Set the cell's foreground palette index, set the foreground palette index
// // bit, set it foreground-opaque, and clear the foreground default color bit.
// static inline int // static inline int
// cell_set_fg_palindex(cell* cl, int idx){ // cell_set_fg_palindex(cell* cl, int idx){
// if(idx < 0 || idx >= NCPALETTESIZE){ // if(idx < 0 || idx >= NCPALETTESIZE){
@ -372,14 +347,14 @@ pub fn cells_load_box(
// cl->channels |= CELL_FGDEFAULT_MASK; // cl->channels |= CELL_FGDEFAULT_MASK;
// cl->channels |= CELL_FG_PALETTE; // cl->channels |= CELL_FG_PALETTE;
// cell_set_fg_alpha(cl, CELL_ALPHA_OPAQUE); // cell_set_fg_alpha(cl, CELL_ALPHA_OPAQUE);
// cl->stylemask &= 0xffff00ff; // cl->channels &= 0xff000000ffffffffull;
// cl->stylemask |= (idx << 8u); // cl->channels |= ((uint64_t)idx << 32u);
// return 0; // return 0;
// } // }
// //
// static inline unsigned // static inline unsigned
// cell_fg_palindex(const cell* cl){ // cell_fg_palindex(const cell* cl){
// return (cl->stylemask & 0x0000ff00) >> 8u; // return (cl->channels & 0xff00000000ull) >> 32u;
// } // }
// //
// // 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
@ -412,14 +387,14 @@ pub fn cells_load_box(
// cl->channels |= CELL_BGDEFAULT_MASK; // cl->channels |= CELL_BGDEFAULT_MASK;
// cl->channels |= CELL_BG_PALETTE; // cl->channels |= CELL_BG_PALETTE;
// cell_set_bg_alpha(cl, CELL_ALPHA_OPAQUE); // cell_set_bg_alpha(cl, CELL_ALPHA_OPAQUE);
// cl->stylemask &= 0xffffff00; // cl->channels &= 0xffffffffff000000;
// cl->stylemask |= idx; // cl->channels |= idx;
// return 0; // return 0;
// } // }
// //
// static inline unsigned // static inline unsigned
// cell_bg_palindex(const cell* cl){ // cell_bg_palindex(const cell* cl){
// return cl->stylemask & 0x000000ff; // return (cl->channels & 0xff);
// } // }
// //
// // Is the foreground using the "default foreground color"? // // Is the foreground using the "default foreground color"?

@ -3,6 +3,15 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
#![no_std] #![no_std]
#![allow(clippy::too_many_arguments)]
// see https://github.com/rust-lang/rust-bindgen/issues/1470
#[allow(clippy::all)]
mod bindings {
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}
pub use bindings::*;
mod cells; mod cells;
mod channel; mod channel;
mod key; mod key;
@ -22,8 +31,6 @@ pub use pixel::*;
pub use plane::*; pub use plane::*;
pub use types::*; pub use types::*;
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use core::ptr::{null, null_mut}; use core::ptr::{null, null_mut};

@ -88,10 +88,10 @@
// //
// static inline functions to reimplement: 42 // static inline functions to reimplement: 42
// ------------------------------------------ (done / (x) wont / remaining) // ------------------------------------------ (done / (x) wont / remaining)
// (+) implement : 10 / … / 32 // (+) implement: 18 / … / 24
// (#) unit tests: 0 / … / 42 // (#) unit test: 0 / … / 42
// ------------------------------------------ // ------------------------------------------
// ncplane_align //+ncplane_align
// ncplane_at_cursor_cell // ncplane_at_cursor_cell
// ncplane_at_yx_cell // ncplane_at_yx_cell
//+ncplane_bchannel //+ncplane_bchannel
@ -99,7 +99,7 @@
//+ncplane_bg_alpha //+ncplane_bg_alpha
//+ncplane_bg_default_p //+ncplane_bg_default_p
//+ncplane_bg_rgb //+ncplane_bg_rgb
// ncplane_box_sized //+ncplane_box_sized
//+ncplane_dim_x //+ncplane_dim_x
//+ncplane_dim_y //+ncplane_dim_y
// ncplane_double_box // ncplane_double_box
@ -111,7 +111,7 @@
//+ncplane_fg_rgb //+ncplane_fg_rgb
// ncplane_gradient_sized // ncplane_gradient_sized
// ncplane_highgradient_sized // ncplane_highgradient_sized
// ncplane_hline //+ncplane_hline
//+ncplane_perimeter //+ncplane_perimeter
// ncplane_perimeter_double // ncplane_perimeter_double
// ncplane_perimeter_rounded // ncplane_perimeter_rounded
@ -131,7 +131,7 @@
// ncplane_resize_simple // ncplane_resize_simple
// ncplane_rounded_box // ncplane_rounded_box
// ncplane_rounded_box_sized // ncplane_rounded_box_sized
// ncplane_vline //+ncplane_vline
// ncplane_vprintf // ncplane_vprintf
use core::ptr::null_mut; use core::ptr::null_mut;
@ -139,60 +139,47 @@ use cstr_core::CString;
use crate as ffi; use crate as ffi;
use ffi::types::{AlphaBits, Channel, Color, IntResult}; use ffi::types::{AlphaBits, Channel, Color, IntResult};
use ffi::{cell, ncplane, ncalign_e};
pub fn ncplane_putstr(plane: *mut ffi::ncplane, _str: &str) -> i32 { /// Return the column at which 'cols' columns ought start in order to be aligned
unsafe { /// according to 'align' within ncplane 'n'. Returns INT_MAX on invalid 'align'.
ffi::ncplane_putstr_yx( /// Undefined behavior on negative 'cols'.
plane, // XXX: change cols type to u32? https://github.com/dankamongmen/notcurses/issues/904
-1, // TODO: TEST
-1, #[inline]
CString::new(_str).expect("Bad string").as_ptr(), pub fn ncplane_align(plane: &ncplane, align: ncalign_e, cols: i32) -> i32 {
) if align == ffi::ncalign_e_NCALIGN_LEFT { return 0; }
}
}
pub fn ncplane_dim_y(plane: *const ffi::ncplane) -> i32 { let plane_cols = ncplane_dim_x(plane);
unsafe { if cols > plane_cols { return 0; }
let mut y = 0;
ffi::ncplane_dim_yx(plane, &mut y, null_mut());
return y;
}
}
pub fn ncplane_dim_x(plane: *const ffi::ncplane) -> i32 { if align == ffi::ncalign_e_NCALIGN_CENTER {
unsafe { return plane_cols - cols / 2;
let mut x = 0; } else if align == ffi::ncalign_e_NCALIGN_RIGHT {
ffi::ncplane_dim_yx(plane, null_mut(), &mut x); return plane_cols - cols;
return x;
} }
core::i32::MAX
} }
pub fn ncplane_perimeter(
plane: *mut ffi::ncplane,
_ul: *const ffi::cell,
_ur: *const ffi::cell,
_ll: *const ffi::cell,
_lr: *const ffi::cell,
_hl: *const ffi::cell,
_vl: *const ffi::cell,
_ctlword: u32,
) -> IntResult {
unsafe { ffi::ncplane_cursor_move_yx(plane, 0, 0) }
}
// // Resize the plane, retaining what data we can (everything, unless we're
// // shrinking in some dimension). Keep the origin where it is.
// static inline int // static inline int
// ncplane_resize_simple(struct ncplane* n, int ylen, int xlen){ // ncplane_align(const struct ncplane* n, ncalign_e align, int c){
// int oldy, oldx; // if(align == NCALIGN_LEFT){
// ncplane_dim_yx(n, &oldy, &oldx); // current dimensions of 'n' // return 0;
// int keepleny = oldy > ylen ? ylen : oldy; // }
// int keeplenx = oldx > xlen ? xlen : oldx; // int cols = ncplane_dim_x(n);
// return ncplane_resize(n, 0, 0, keepleny, keeplenx, 0, 0, ylen, xlen); // if(c > cols){
// return 0;
// }
// if(align == NCALIGN_CENTER){
// return (cols - c) / 2;
// }else if(align == NCALIGN_RIGHT){
// return cols - c;
// }
// return INT_MAX;
// } // }
// // Retrieve the current contents of the cell under the cursor into 'c'. This // Retrieve the current contents of the cell under the cursor into 'c'. This
// // cell is invalidated if the associated plane is destroyed. // cell is invalidated if the associated plane is destroyed.
// static inline int // static inline int
// ncplane_at_cursor_cell(struct ncplane* n, cell* c){ // ncplane_at_cursor_cell(struct ncplane* n, cell* c){
// char* egc = ncplane_at_cursor(n, &c->attrword, &c->channels); // char* egc = ncplane_at_cursor(n, &c->attrword, &c->channels);
@ -208,8 +195,8 @@ pub fn ncplane_perimeter(
// return r; // return r;
// } // }
// // Retrieve the current contents of the specified cell into 'c'. This cell is // Retrieve the current contents of the specified cell into 'c'. This cell is
// // invalidated if the associated plane is destroyed. // invalidated if the associated plane is destroyed.
// static inline int // static inline int
// ncplane_at_yx_cell(struct ncplane* n, int y, int x, cell* c){ // ncplane_at_yx_cell(struct ncplane* n, int y, int x, cell* c){
// char* egc = ncplane_at_yx(n, y, x, &c->attrword, &c->channels); // char* egc = ncplane_at_yx(n, y, x, &c->attrword, &c->channels);
@ -223,47 +210,119 @@ pub fn ncplane_perimeter(
// return r; // return r;
// } // }
// // Return the column at which 'c' cols ought start in order to be aligned /// Draw a box with its upper-left corner at the current cursor position, having
// // according to 'align' within ncplane 'n'. Returns INT_MAX on invalid 'align'. /// dimensions 'ylen'x'xlen'. See ncplane_box() for more information. The
// // Undefined behavior on negative 'c'. /// minimum box size is 2x2, and it cannot be drawn off-screen.
// TODO: TEST
#[inline]
pub fn ncplane_box_sized(plane: &mut ncplane, ul: &cell, ur: &cell, ll: &cell, lr: &cell, hline: &cell, vline: &cell, ylen: i32, xlen: i32, ctrlword: u32) -> IntResult {
unsafe {
let (mut y, mut x) = (0,0);
ffi::ncplane_cursor_yx(plane, &mut y, &mut x);
ffi::ncplane_box(plane, ul, ur, ll, lr, hline, vline, y + ylen -1, x + xlen -1, ctrlword)
}
}
///
// TODO: TEST
#[inline]
pub fn ncplane_dim_x(plane: &ncplane) -> i32 {
unsafe {
let mut x = 0;
ffi::ncplane_dim_yx(plane, null_mut(), &mut x);
x
}
}
///
// TODO: TEST
#[inline]
pub fn ncplane_dim_y(plane: &ncplane) -> i32 {
unsafe {
let mut y = 0;
ffi::ncplane_dim_yx(plane, &mut y, null_mut());
y
}
}
///
/// On error, return the negative number of cells drawn.
// TODO: TEST
#[inline]
pub fn ncplane_hline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 {
unsafe {
ffi::ncplane_hline_interp(plane, cell, len, cell.channels, cell.channels)
}
}
///
// TODO: TEST
#[inline]
pub fn ncplane_perimeter(plane: &mut ncplane, ul: &cell, ur: &cell, ll: &cell, lr: &cell, hline: &cell, vline: &cell, ctlword: u32) -> IntResult {
unsafe {
ffi::ncplane_cursor_move_yx(plane, 0, 0);
let (mut dimy, mut dimx) = (0,0);
ffi::ncplane_dim_yx(plane, &mut dimy, &mut dimx);
ncplane_box_sized(plane, ul, ur, ll, lr, hline, vline, dimy, dimx, ctlword)
}
}
// static inline int // static inline int
// ncplane_align(const struct ncplane* n, ncalign_e align, int c){ // ncplane_perimeter_double(struct ncplane* n, uint32_t attrword,
// if(align == NCALIGN_LEFT){ // uint64_t channels, unsigned ctlword){
// return 0; // if(ncplane_cursor_move_yx(n, 0, 0)){
// return -1;
// } // }
// int cols = ncplane_dim_x(n); // int dimy, dimx;
// if(c > cols){ // ncplane_dim_yx(n, &dimy, &dimx);
// return 0; // cell ul = CELL_TRIVIAL_INITIALIZER;
// cell ur = CELL_TRIVIAL_INITIALIZER;
// cell ll = CELL_TRIVIAL_INITIALIZER;
// cell lr = CELL_TRIVIAL_INITIALIZER;
// cell vl = CELL_TRIVIAL_INITIALIZER;
// cell hl = CELL_TRIVIAL_INITIALIZER;
// if(cells_double_box(n, attrword, channels, &ul, &ur, &ll, &lr, &hl, &vl)){
// return -1;
// } // }
// if(align == NCALIGN_CENTER){ // int r = ncplane_box_sized(n, &ul, &ur, &ll, &lr, &hl, &vl, dimy, dimx, ctlword);
// return (cols - c) / 2; // cell_release(n, &ul); cell_release(n, &ur);
// }else if(align == NCALIGN_RIGHT){ // cell_release(n, &ll); cell_release(n, &lr);
// return cols - c; // cell_release(n, &hl); cell_release(n, &vl);
// return r;
// }
// static inline int
// ncplane_perimeter_rounded(struct ncplane* n, uint32_t attrword,
// uint64_t channels, unsigned ctlword){
// if(ncplane_cursor_move_yx(n, 0, 0)){
// return -1;
// } // }
// return INT_MAX; // int dimy, dimx;
// ncplane_dim_yx(n, &dimy, &dimx);
// cell ul = CELL_TRIVIAL_INITIALIZER;
// cell ur = CELL_TRIVIAL_INITIALIZER;
// cell ll = CELL_TRIVIAL_INITIALIZER;
// cell lr = CELL_TRIVIAL_INITIALIZER;
// cell vl = CELL_TRIVIAL_INITIALIZER;
// cell hl = CELL_TRIVIAL_INITIALIZER;
// if(cells_rounded_box(n, attrword, channels, &ul, &ur, &ll, &lr, &hl, &vl)){
// return -1;
// }
// int r = ncplane_box_sized(n, &ul, &ur, &ll, &lr, &hl, &vl, dimy, dimx, ctlword);
// cell_release(n, &ul); cell_release(n, &ur);
// cell_release(n, &ll); cell_release(n, &lr);
// cell_release(n, &hl); cell_release(n, &vl);
// return r;
// } // }
// // Call ncplane_putc_yx() for the current cursor location. // // Call ncplane_putc_yx() for the current cursor location.
// static inline int // static inline int
// ncplane_putc(struct ncplane* n, const cell* c){ // ncplane_putc(struct ncplane* n, const cell* c){
// return ncplane_putc_yx(n, -1, -1, c); // return ncplane_putc_yx(n, -1, -1, c);
// } // }
// // Replace the EGC underneath us, but retain the styling. The current styling
// // of the plane will not be changed.
// //
// // Replace the cell at the specified coordinates with the provided 7-bit char
// // 'c'. Advance the cursor by 1. On success, returns 1. On failure, returns -1.
// // This works whether the underlying char is signed or unsigned.
// static inline int
// ncplane_putsimple_yx(struct ncplane* n, int y, int x, char c){
// cell ce = CELL_INITIALIZER((uint32_t)c, ncplane_attr(n), ncplane_channels(n));
// if(!cell_simple_p(&ce)){
// return -1;
// }
// return ncplane_putc_yx(n, y, x, &ce);
// }
// // Call ncplane_putsimple_yx() at the current cursor location. // // Call ncplane_putsimple_yx() at the current cursor location.
// static inline int // static inline int
// ncplane_putsimple(struct ncplane* n, char c){ // ncplane_putsimple(struct ncplane* n, char c){
@ -275,35 +334,35 @@ pub fn ncplane_perimeter(
// ncplane_putegc(struct ncplane* n, const char* gclust, int* sbytes){ // ncplane_putegc(struct ncplane* n, const char* gclust, int* sbytes){
// return ncplane_putegc_yx(n, -1, -1, gclust, sbytes); // return ncplane_putegc_yx(n, -1, -1, gclust, sbytes);
// } // }
// Replace the EGC underneath us, but retain the styling. The current styling
// of the plane will not be changed.
// //
// // ncplane_putegc(), but following a conversion from wchar_t to UTF-8 multibyte. // Replace the cell at the specified coordinates with the provided 7-bit char
// 'c'. Advance the cursor by 1. On success, returns 1. On failure, returns -1.
// This works whether the underlying char is signed or unsigned.
// static inline int // static inline int
// ncplane_putwegc(struct ncplane* n, const wchar_t* gclust, int* sbytes){ // ncplane_putsimple_yx(struct ncplane* n, int y, int x, char c){
// // maximum of six UTF8-encoded bytes per wchar_t // cell ce = CELL_INITIALIZER((uint32_t)c, ncplane_attr(n), ncplane_channels(n));
// const size_t mbytes = (wcslen(gclust) * WCHAR_MAX_UTF8BYTES) + 1; // if(!cell_simple_p(&ce)){
// char* mbstr = (char*)malloc(mbytes); // need cast for c++ callers
// if(mbstr == NULL){
// return -1;
// }
// size_t s = wcstombs(mbstr, gclust, mbytes);
// if(s == (size_t)-1){
// free(mbstr);
// return -1; // return -1;
// } // }
// int ret = ncplane_putegc(n, mbstr, sbytes); // return ncplane_putc_yx(n, y, x, &ce);
// free(mbstr);
// return ret;
// } // }
// // Call ncplane_putwegc() after successfully moving to y, x. ///
// static inline int // TODO: TEST
// ncplane_putwegc_yx(struct ncplane* n, int y, int x, const wchar_t* gclust, #[inline]
// int* sbytes){ pub fn ncplane_putstr(plane: &mut ncplane, _str: &str) -> i32 {
// if(ncplane_cursor_move_yx(n, y, x)){ unsafe {
// return -1; ffi::ncplane_putstr_yx(
// } plane,
// return ncplane_putwegc(n, gclust, sbytes); -1,
// } -1,
CString::new(_str).expect("Bad string").as_ptr(),
)
}
}
// static inline int // static inline int
// ncplane_putstr(struct ncplane* n, const char* gclustarr){ // ncplane_putstr(struct ncplane* n, const char* gclustarr){
@ -334,6 +393,35 @@ pub fn ncplane_perimeter(
// return ret; // return ret;
// } // }
// // ncplane_putegc(), but following a conversion from wchar_t to UTF-8 multibyte.
// static inline int
// ncplane_putwegc(struct ncplane* n, const wchar_t* gclust, int* sbytes){
// // maximum of six UTF8-encoded bytes per wchar_t
// const size_t mbytes = (wcslen(gclust) * WCHAR_MAX_UTF8BYTES) + 1;
// char* mbstr = (char*)malloc(mbytes); // need cast for c++ callers
// if(mbstr == NULL){
// return -1;
// }
// size_t s = wcstombs(mbstr, gclust, mbytes);
// if(s == (size_t)-1){
// free(mbstr);
// return -1;
// }
// int ret = ncplane_putegc(n, mbstr, sbytes);
// free(mbstr);
// return ret;
// }
// Call ncplane_putwegc() after successfully moving to y, x.
// static inline int
// ncplane_putwegc_yx(struct ncplane* n, int y, int x, const wchar_t* gclust,
// int* sbytes){
// if(ncplane_cursor_move_yx(n, y, x)){
// return -1;
// }
// return ncplane_putwegc(n, gclust, sbytes);
// }
// static inline int // static inline int
// ncplane_putwstr_aligned(struct ncplane* n, int y, ncalign_e align, // ncplane_putwstr_aligned(struct ncplane* n, int y, ncalign_e align,
// const wchar_t* gclustarr){ // const wchar_t* gclustarr){
@ -347,26 +435,21 @@ pub fn ncplane_perimeter(
// return ncplane_putwstr_yx(n, -1, -1, gclustarr); // return ncplane_putwstr_yx(n, -1, -1, gclustarr);
// } // }
// // Replace the cell at the specified coordinates with the provided wide char // Replace the cell at the specified coordinates with the provided wide char
// // 'w'. Advance the cursor by the character's width as reported by wcwidth(). // 'w'. Advance the cursor by the character's width as reported by wcwidth().
// // On success, returns 1. On failure, returns -1. // On success, returns 1. On failure, returns -1.
// static inline int // static inline int
// ncplane_putwc_yx(struct ncplane* n, int y, int x, wchar_t w){ // ncplane_putwc_yx(struct ncplane* n, int y, int x, wchar_t w){
// wchar_t warr[2] = { w, L'\0' }; // wchar_t warr[2] = { w, L'\0' };
// return ncplane_putwstr_yx(n, y, x, warr); // return ncplane_putwstr_yx(n, y, x, warr);
// } // }
// // Call ncplane_putwc() at the current cursor position. // Call ncplane_putwc() at the current cursor position.
// static inline int // static inline int
// ncplane_putwc(struct ncplane* n, wchar_t w){ // ncplane_putwc(struct ncplane* n, wchar_t w){
// return ncplane_putwc_yx(n, -1, -1, w); // return ncplane_putwc_yx(n, -1, -1, w);
// } // }
// static inline int
// ncplane_vprintf(struct ncplane* n, const char* format, va_list ap){
// return ncplane_vprintf_yx(n, -1, -1, format, ap);
// }
// static inline int // static inline int
// ncplane_printf(struct ncplane* n, const char* format, ...) // ncplane_printf(struct ncplane* n, const char* format, ...)
// __attribute__ ((format (printf, 2, 3))); // __attribute__ ((format (printf, 2, 3)));
@ -420,40 +503,32 @@ pub fn ncplane_perimeter(
// return ret; // return ret;
// } // }
// // Resize the plane, retaining what data we can (everything, unless we're
// // shrinking in some dimension). Keep the origin where it is.
// static inline int // static inline int
// ncplane_hline(struct ncplane* n, const cell* c, int len){ // ncplane_resize_simple(struct ncplane* n, int ylen, int xlen){
// return ncplane_hline_interp(n, c, len, c->channels, c->channels); // int oldy, oldx;
// ncplane_dim_yx(n, &oldy, &oldx); // current dimensions of 'n'
// int keepleny = oldy > ylen ? ylen : oldy;
// int keeplenx = oldx > xlen ? xlen : oldx;
// return ncplane_resize(n, 0, 0, keepleny, keeplenx, 0, 0, ylen, xlen);
// } // }
// static inline int ///
// ncplane_vline(struct ncplane* n, const cell* c, int len){ /// On error, return the negative number of cells drawn.
// return ncplane_vline_interp(n, c, len, c->channels, c->channels); // TODO: TEST
// } #[inline]
pub fn ncplane_vline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 {
unsafe {
ffi::ncplane_vline_interp(plane, cell, len, cell.channels, cell.channels)
}
}
// // Draw a box with its upper-left corner at the current cursor position, having
// // dimensions 'ylen'x'xlen'. See ncplane_box() for more information. The
// // minimum box size is 2x2, and it cannot be drawn off-screen.
// static inline int // static inline int
// ncplane_box_sized(struct ncplane* n, const cell* ul, const cell* ur, // ncplane_vprintf(struct ncplane* n, const char* format, va_list ap){
// const cell* ll, const cell* lr, const cell* hline, // return ncplane_vprintf_yx(n, -1, -1, format, ap);
// const cell* vline, int ylen, int xlen, unsigned ctlword){
// int y, x;
// ncplane_cursor_yx(n, &y, &x);
// return ncplane_box(n, ul, ur, ll, lr, hline, vline, y + ylen - 1,
// x + xlen - 1, ctlword);
// } // }
// static inline int
// ncplane_perimeter(struct ncplane* n, const cell* ul, const cell* ur,
// const cell* ll, const cell* lr, const cell* hline,
// const cell* vline, unsigned ctlword){
// if(ncplane_cursor_move_yx(n, 0, 0)){
// return -1;
// }
// int dimy, dimx;
// ncplane_dim_yx(n, &dimy, &dimx);
// return ncplane_box_sized(n, ul, ur, ll, lr, hline, vline, dimy, dimx, ctlword);
// }
// // Draw a gradient with its upper-left corner at the current cursor position, // // Draw a gradient with its upper-left corner at the current cursor position,
// // having dimensions 'ylen'x'xlen'. See ncplane_gradient for more information. // // having dimensions 'ylen'x'xlen'. See ncplane_gradient for more information.
@ -488,21 +563,21 @@ pub fn ncplane_perimeter(
/// Extract the 32-bit working foreground channel from an ncplane. /// Extract the 32-bit working foreground channel from an ncplane.
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_fchannel(plane: &ffi::ncplane) -> Channel { pub fn ncplane_fchannel(plane: &ncplane) -> Channel {
ffi::channels_fchannel(unsafe { ffi::ncplane_channels(plane)}) ffi::channels_fchannel(unsafe { ffi::ncplane_channels(plane)})
} }
/// Extract the 32-bit working background channel from an ncplane. /// Extract the 32-bit working background channel from an ncplane.
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_bchannel(plane: &ffi::ncplane) -> Channel { pub fn ncplane_bchannel(plane: &ncplane) -> Channel {
ffi::channels_bchannel(unsafe { ffi::ncplane_channels(plane)}) ffi::channels_bchannel(unsafe { ffi::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.
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_fg(plane: &ffi::ncplane) -> Channel { pub fn ncplane_fg(plane: &ncplane) -> Channel {
ffi::channels_fg(unsafe { ffi::ncplane_channels(plane)}) ffi::channels_fg(unsafe { ffi::ncplane_channels(plane)})
} }
@ -510,35 +585,35 @@ pub fn ncplane_fg(plane: &ffi::ncplane) -> Channel {
/// 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.
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_bg(plane: &ffi::ncplane) -> Channel { pub fn ncplane_bg(plane: &ncplane) -> Channel {
ffi::channels_bg(unsafe { ffi::ncplane_channels(plane)}) ffi::channels_bg(unsafe { ffi::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.
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_fg_alpha(plane: &ffi::ncplane) -> AlphaBits { pub fn ncplane_fg_alpha(plane: &ncplane) -> AlphaBits {
ffi::channels_fg_alpha(unsafe { ffi::ncplane_channels(plane)}) ffi::channels_fg_alpha(unsafe { ffi::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.
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_bg_alpha(plane: &ffi::ncplane) -> AlphaBits { pub fn ncplane_bg_alpha(plane: &ncplane) -> AlphaBits {
ffi::channels_bg_alpha(unsafe { ffi::ncplane_channels(plane)}) ffi::channels_bg_alpha(unsafe { ffi::ncplane_channels(plane)})
} }
/// Is the plane's foreground using the "default foreground color"? /// Is the plane's foreground using the "default foreground color"?
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_fg_default_p(plane: &ffi::ncplane) -> bool { pub fn ncplane_fg_default_p(plane: &ncplane) -> bool {
ffi::channels_fg_default_p(unsafe { ffi::ncplane_channels(plane)}) ffi::channels_fg_default_p(unsafe { ffi::ncplane_channels(plane)})
} }
/// Is the plane's background using the "default background color"? /// Is the plane's background using the "default background color"?
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_bg_default_p(plane: &ffi::ncplane) -> bool { pub fn ncplane_bg_default_p(plane: &ncplane) -> bool {
ffi::channels_bg_default_p(unsafe { ffi::ncplane_channels(plane)}) ffi::channels_bg_default_p(unsafe { ffi::ncplane_channels(plane)})
} }
@ -546,7 +621,7 @@ pub fn ncplane_bg_default_p(plane: &ffi::ncplane) -> bool {
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_fg_rgb( pub fn ncplane_fg_rgb(
plane: &ffi::ncplane, plane: &ncplane,
red: &mut Color, red: &mut Color,
green: &mut Color, green: &mut Color,
blue: &mut Color, blue: &mut Color,
@ -558,7 +633,7 @@ pub fn ncplane_fg_rgb(
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_bg_rgb( pub fn ncplane_bg_rgb(
plane: &ffi::ncplane, plane: &ncplane,
red: &mut Color, red: &mut Color,
green: &mut Color, green: &mut Color,
blue: &mut Color, blue: &mut Color,
@ -582,30 +657,6 @@ pub fn ncplane_bg_rgb(
// return ret; // return ret;
// } // }
// static inline int
// ncplane_perimeter_rounded(struct ncplane* n, uint32_t attrword,
// uint64_t channels, unsigned ctlword){
// if(ncplane_cursor_move_yx(n, 0, 0)){
// return -1;
// }
// int dimy, dimx;
// ncplane_dim_yx(n, &dimy, &dimx);
// cell ul = CELL_TRIVIAL_INITIALIZER;
// cell ur = CELL_TRIVIAL_INITIALIZER;
// cell ll = CELL_TRIVIAL_INITIALIZER;
// cell lr = CELL_TRIVIAL_INITIALIZER;
// cell vl = CELL_TRIVIAL_INITIALIZER;
// cell hl = CELL_TRIVIAL_INITIALIZER;
// if(cells_rounded_box(n, attrword, channels, &ul, &ur, &ll, &lr, &hl, &vl)){
// return -1;
// }
// int r = ncplane_box_sized(n, &ul, &ur, &ll, &lr, &hl, &vl, dimy, dimx, ctlword);
// cell_release(n, &ul); cell_release(n, &ur);
// cell_release(n, &ll); cell_release(n, &lr);
// cell_release(n, &hl); cell_release(n, &vl);
// return r;
// }
// static inline int // static inline int
// ncplane_rounded_box_sized(struct ncplane* n, uint32_t attr, uint64_t channels, // ncplane_rounded_box_sized(struct ncplane* n, uint32_t attr, uint64_t channels,
// int ylen, int xlen, unsigned ctlword){ // int ylen, int xlen, unsigned ctlword){
@ -631,30 +682,6 @@ pub fn ncplane_bg_rgb(
// return ret; // return ret;
// } // }
// static inline int
// ncplane_perimeter_double(struct ncplane* n, uint32_t attrword,
// uint64_t channels, unsigned ctlword){
// if(ncplane_cursor_move_yx(n, 0, 0)){
// return -1;
// }
// int dimy, dimx;
// ncplane_dim_yx(n, &dimy, &dimx);
// cell ul = CELL_TRIVIAL_INITIALIZER;
// cell ur = CELL_TRIVIAL_INITIALIZER;
// cell ll = CELL_TRIVIAL_INITIALIZER;
// cell lr = CELL_TRIVIAL_INITIALIZER;
// cell vl = CELL_TRIVIAL_INITIALIZER;
// cell hl = CELL_TRIVIAL_INITIALIZER;
// if(cells_double_box(n, attrword, channels, &ul, &ur, &ll, &lr, &hl, &vl)){
// return -1;
// }
// int r = ncplane_box_sized(n, &ul, &ur, &ll, &lr, &hl, &vl, dimy, dimx, ctlword);
// cell_release(n, &ul); cell_release(n, &ur);
// cell_release(n, &ll); cell_release(n, &lr);
// cell_release(n, &hl); cell_release(n, &vl);
// return r;
// }
// static inline int // static inline int
// ncplane_double_box_sized(struct ncplane* n, uint32_t attr, uint64_t channels, // ncplane_double_box_sized(struct ncplane* n, uint32_t attr, uint64_t channels,
// int ylen, int xlen, unsigned ctlword){ // int ylen, int xlen, unsigned ctlword){

Loading…
Cancel
Save