From 8b01f26730ea4203e6598856b507a8ee2ff7362e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Tue, 11 Aug 2020 11:30:46 +0200 Subject: [PATCH] rust: improve info headers for maximum consistency and implement 1 palette fuction --- rust/libnotcurses-sys/src/cells.rs | 18 +++++------- rust/libnotcurses-sys/src/channel.rs | 31 ++++++++++---------- rust/libnotcurses-sys/src/key.rs | 14 ++++------ rust/libnotcurses-sys/src/nc.rs | 18 +++++------- rust/libnotcurses-sys/src/palette.rs | 42 ++++++++++++++-------------- rust/libnotcurses-sys/src/pixel.rs | 18 +++++------- rust/libnotcurses-sys/src/plane.rs | 19 +++++-------- 7 files changed, 68 insertions(+), 92 deletions(-) diff --git a/rust/libnotcurses-sys/src/cells.rs b/rust/libnotcurses-sys/src/cells.rs index 0ce71c732..6fecb39b7 100644 --- a/rust/libnotcurses-sys/src/cells.rs +++ b/rust/libnotcurses-sys/src/cells.rs @@ -1,5 +1,5 @@ -// Already exported by bindgen: 6 -// +// functions already exported by bindgen : 6 +// ----------------------------------------- // - cell_duplicate // - cell_extended_gcluster // - cell_load @@ -7,15 +7,11 @@ // - cells_double_box // - cells_rounded_box // -// FUNCTIONS TO REIMPLEMENT: -// - from notcurses.h: 45 -// - done: ±2 -// - remaining: 43 -// -// --------------- -// + reimplemented -// # and unit test -// -------------- +// static inline functions to reimplement: 45 +// ------------------------------------------ +// - finished : ±2 +// - remaining: 43 +// --------------- (+) implemented (#) + unit test (x) wont implement // cell_bchannel // cell_bg // cell_bg_alpha diff --git a/rust/libnotcurses-sys/src/channel.rs b/rust/libnotcurses-sys/src/channel.rs index 09cf39640..802948d11 100644 --- a/rust/libnotcurses-sys/src/channel.rs +++ b/rust/libnotcurses-sys/src/channel.rs @@ -1,37 +1,34 @@ -// NOTE: There are several differences from the original functions in C: +// --------------------------------------------------------------------------------------- +// - NOTE: The channel components are u8 instead of u32. +// Because of type enforcing, some runtime checks are now unnecessary. // -// - The channel components are u8 instead of u32. Because of type enforcing by the -// compiler, some runtime checks are now unnecessary. -// -// - These functions now can't fail and doesn't have to return an error: +// - NOTE: These functions now can't fail and don't have to return an error: // - `channel_set_rgb()` // - `channels_set_fg_rgb()` // - `channels_set_bg_rgb()` // -// - These functions were therefore deemed unnecessary to implement: +// - NOTE: These functions were therefore deemed unnecessary to implement: // - `channel_set_rgb_clipped()` // - `channels_set_fg_rgb_clipped()` // - `channels_set_bg_rgb_clipped()` // -// - These functions return an integer error result: +// - These functions still return an integer error result: // - `channel_set_alpha()` // - `channel_set_rgb()` // - `channels_set_fg()` // - `channels_set_bg()` // - `channels_set_fg_alpha()` // - `channels_set_bg_alpha()` +// --------------------------------------------------------------------------------------- // +// functions already exported by bindgen : 0 +// ------------------------------------------ // -// FUNCTIONS TO REIMPLEMENT: -// - from notcurses.h: 38 -// - done: ±37 -// - remaining: 1 -// -// --------------- -// + reimplemented -// # and unit test -// x not needed -// -------------- +// static inline functions to reimplement: 38 +// ------------------------------------------ +// - finished : 37 +// - remaining: 1 +// --------------- (+) implemented (#) + unit test (x) wont implement //#channel_alpha //#channel_b //#channel_default_p // FIXME TEST diff --git a/rust/libnotcurses-sys/src/key.rs b/rust/libnotcurses-sys/src/key.rs index 5ad9bee18..358422214 100644 --- a/rust/libnotcurses-sys/src/key.rs +++ b/rust/libnotcurses-sys/src/key.rs @@ -1,13 +1,9 @@ -// Functions already exported by bindgen: 0 -// static inline functions to reimplement: 2 -// - done: 2 -// - remaining: 0 +// functions already exported by bindgen : 0 // -// Function list -// --------------- -// + reimplemented -// # and unit test -// -------------- +// static inline functions to reimplement: 2 +// - finished : 2 +// - remaining: 0 +// --------------- (+) implemented (#) + unit test (x) wont implement //+nckey_mouse_p //+nckey_supppuab_p diff --git a/rust/libnotcurses-sys/src/nc.rs b/rust/libnotcurses-sys/src/nc.rs index 518f893d1..d5fac9fd9 100644 --- a/rust/libnotcurses-sys/src/nc.rs +++ b/rust/libnotcurses-sys/src/nc.rs @@ -1,5 +1,5 @@ -// Already exported by bindgen: 35 -// +// functions already exported by bindgen : 35 +// ------------------------------------------ // notcurses_at_yx // notcurses_canchangecolor // notcurses_canfade @@ -36,15 +36,11 @@ // notcurses_version // notcurses_version_components // -// FUNCTIONS TO REIMPLEMENT: -// - from notcurses.h: 4 -// - done: 0 -// - remaining: 4 -// -// --------------- -// + reimplemented -// # and unit test -// -------------- +// static inline functions to reimplement: 4 +// ----------------------------------------- +// - finished : 0 +// - remaining: 4 +// --------------- (+) implemented (#) + unit test (x) wont implement // notcurses_getc_blocking // notcurses_getc_nblock // notcurses_stddim_yx diff --git a/rust/libnotcurses-sys/src/palette.rs b/rust/libnotcurses-sys/src/palette.rs index dca033477..1aea26be0 100644 --- a/rust/libnotcurses-sys/src/palette.rs +++ b/rust/libnotcurses-sys/src/palette.rs @@ -1,32 +1,32 @@ -// Already exported by bindgen: 3 +// --------------------------------------------------------------------------------------- +// NOTE: These functions now can't fail and dont't have to return an error: +// - `palette256_set_rgb()` +// --------------------------------------------------------------------------------------- // +// functions already exported by bindgen : 3 +// ----------------------------------------- // palette256_free // palette256_new // palette256_use // -// FUNCTIONS TO REIMPLEMENT: -// - from notcurses.h: 3 -// - done: 0 -// - remaining: 3 -// -// --------------- -// + reimplemented -// # and unit test -// -------------- -// palette256_get_rgb +// static inline functions to reimplement: 3 +// ----------------------------------------- +// - finished : 1 +// - remaining: 2 +// --------------- (+) implemented (#) + unit test (x) wont implement +//+palette256_get_rgb // palette256_set // palette256_set_rgb +use crate as ffi; +use crate::types::Color; -// // Manipulate entries in the palette store 'p'. These are *not* locked. -// static inline int -// palette256_set_rgb(palette256* p, int idx, int r, int g, int b){ -// if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){ -// return -1; -// } -// return channel_set_rgb(&p->chans[idx], r, g, b); -// } -// +/// Manipulate entries in the palette store 'p'. These are *not* locked. +pub fn palette256_set_rgb(palette: &mut ffi::palette256, idx: usize, r: Color, g: Color, b: Color) { + ffi::channel_set_rgb(&mut palette.chans[idx], r, g, b) +} + +// XXX: what is the return type? // static inline int // palette256_set(palette256* p, int idx, unsigned rgb){ // if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){ @@ -34,7 +34,7 @@ // } // return channel_set(&p->chans[idx], rgb); // } -// + // static inline int // palette256_get_rgb(const palette256* p, int idx, unsigned* RESTRICT r, unsigned* RESTRICT g, unsigned* RESTRICT b){ // if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){ diff --git a/rust/libnotcurses-sys/src/pixel.rs b/rust/libnotcurses-sys/src/pixel.rs index 86c6038fe..f2224bf97 100644 --- a/rust/libnotcurses-sys/src/pixel.rs +++ b/rust/libnotcurses-sys/src/pixel.rs @@ -1,15 +1,11 @@ -// Already exported by bindgen: 0 -// -// FUNCTIONS TO REIMPLEMENT: -// - from notcurses.h: 10 -// - done: 0 -// - remaining: 10 -// -// --------------- -// + reimplemented -// # and unit test -// -------------- +// functions already exported by bindgen : 0 +// ----------------------------------------- // +// static inline functions to reimplement: 3 +// ----------------------------------------- +// - finished : 0 +// - remaining: 10 +// --------------- (+) implemented (#) + unit test (x) wont implement // ncpixel // ncpixel_a // ncpixel_b diff --git a/rust/libnotcurses-sys/src/plane.rs b/rust/libnotcurses-sys/src/plane.rs index 6247cc96d..b56943b95 100644 --- a/rust/libnotcurses-sys/src/plane.rs +++ b/rust/libnotcurses-sys/src/plane.rs @@ -1,5 +1,5 @@ -// Already exported by bindgen: 86 -// +// functions already exported by bindgen : 86 +// ------------------------------------------ // ncplane_aligned // ncplane_at_cursor // ncplane_attr @@ -87,16 +87,11 @@ // ncplane_vprintf_yx // ncplane_yx // -// -// FUNCTIONS TO REIMPLEMENT: -// - from notcurses.h: 42 -// - done: ±4 -// - remaining: 38 -// -// --------------- -// + reimplemented -// # and unit test -// -------------- +// static inline functions to reimplement: 42 +// ------------------------------------------ +// - finished : ±4 +// - remaining: 38 +// --------------- (+) implemented (#) + unit test (x) wont implement // ncplane_align // ncplane_at_cursor_cell // ncplane_at_yx_cell