rust: rustfmt

pull/922/head
joseLuís 4 years ago
parent e324cd404c
commit 9c08411e27

@ -55,10 +55,10 @@
//+cell_wide_left_p //+cell_wide_left_p
//+cell_wide_right_p //+cell_wide_right_p
use cstr_core::CString;
use crate as ffi; use crate as ffi;
use ffi::types::{AlphaBits, Channel, ChannelPair, Color, GraphemeCluster, IntResult, PaletteIndex, StyleMask}; use ffi::types::{
AlphaBits, Channel, ChannelPair, Color, GraphemeCluster, PaletteIndex, StyleMask,
};
use ffi::{cell, ncplane}; use ffi::{cell, ncplane};
/* /*
@ -139,7 +139,6 @@ pub fn cells_load_box(
return -1; return -1;
*/ */
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn cell_init(cell: &mut cell) { pub fn cell_init(cell: &mut cell) {
@ -232,15 +231,18 @@ pub fn cell_wide_left_p(cell: &cell) -> bool {
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn cell_strdup(plane: &ncplane, cell: &cell) -> *mut i8 { pub fn cell_strdup(plane: &ncplane, cell: &cell) -> *mut i8 {
unsafe{ unsafe { libc::strdup(ffi::cell_extended_gcluster(plane, cell)) }
libc::strdup(ffi::cell_extended_gcluster(plane, cell))
}
} }
/// Extract the three elements of a cell. /// Extract the three elements of a cell.
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn cell_extract(plane: &ncplane, cell: &cell, stylemask: &mut StyleMask, channels: &mut ChannelPair) -> *mut i8 { pub fn cell_extract(
plane: &ncplane,
cell: &cell,
stylemask: &mut StyleMask,
channels: &mut ChannelPair,
) -> *mut i8 {
if *stylemask != 0 { if *stylemask != 0 {
*stylemask = cell.stylemask; *stylemask = cell.stylemask;
} }
@ -264,7 +266,10 @@ pub fn cellcmp(plane1: &ncplane, cell1: &cell, plane2: &ncplane, cell2: &cell) -
return true; return true;
} }
unsafe { unsafe {
libc::strcmp(ffi::cell_extended_gcluster(plane1, cell1), ffi::cell_extended_gcluster(plane2, cell2)) != 0 libc::strcmp(
ffi::cell_extended_gcluster(plane1, cell1),
ffi::cell_extended_gcluster(plane2, cell2),
) != 0
} }
} }
@ -272,7 +277,9 @@ pub fn cellcmp(plane1: &ncplane, cell1: &cell, plane2: &ncplane, cell2: &cell) -
// 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_load_simple(plane: &mut ncplane, cell: &mut cell, ch: char) -> i32 { pub fn cell_load_simple(plane: &mut ncplane, cell: &mut cell, ch: char) -> i32 {
unsafe { ffi::cell_release(plane, cell); } unsafe {
ffi::cell_release(plane, cell);
}
cell.channels &= !(ffi::CELL_WIDEASIAN_MASK as u64 | ffi::CELL_NOBACKGROUND_MASK); cell.channels &= !(ffi::CELL_WIDEASIAN_MASK as u64 | ffi::CELL_NOBACKGROUND_MASK);
cell.gcluster = ch as GraphemeCluster; cell.gcluster = ch as GraphemeCluster;
1 1
@ -407,7 +414,7 @@ pub fn cell_set_bg(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 cell, index: PaletteIndex) {
cell.channels |= ffi::CELL_BGDEFAULT_MASK as u64 ; cell.channels |= ffi::CELL_BGDEFAULT_MASK as u64;
cell.channels |= ffi::CELL_BG_PALETTE as u64; cell.channels |= ffi::CELL_BG_PALETTE as u64;
cell_set_bg_alpha(cell, ffi::CELL_ALPHA_OPAQUE); cell_set_bg_alpha(cell, ffi::CELL_ALPHA_OPAQUE);
cell.channels &= 0xffffffffff000000; cell.channels &= 0xffffffffff000000;

@ -2,7 +2,6 @@
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
#![allow(non_snake_case)] #![allow(non_snake_case)]
#![no_std] #![no_std]
#![allow(clippy::too_many_arguments)] #![allow(clippy::too_many_arguments)]
// see https://github.com/rust-lang/rust-bindgen/issues/1470 // see https://github.com/rust-lang/rust-bindgen/issues/1470

@ -59,7 +59,10 @@ pub fn notcurses_getc_nblock(nc: &mut notcurses, input: &mut ncinput) -> ffi::ch
unsafe { unsafe {
let mut sigmask = ffi::sigset_t { __val: [0; 16] }; let mut sigmask = ffi::sigset_t { __val: [0; 16] };
ffi::sigfillset(&mut sigmask); ffi::sigfillset(&mut sigmask);
let ts = ffi::timespec {tv_sec: 0, tv_nsec: 0}; let ts = ffi::timespec {
tv_sec: 0,
tv_nsec: 0,
};
ffi::notcurses_getc(nc, &ts, &mut sigmask, input) ffi::notcurses_getc(nc, &ts, &mut sigmask, input)
} }
} }

@ -10,7 +10,7 @@
// //
// static inline functions to reimplement: 3 // static inline functions to reimplement: 3
// ----------------------------------------- (done / (x) wont / remaining) // ----------------------------------------- (done / (x) wont / remaining)
// (+) implement : 1 / 0 / 2 // (+) implement : 3 / 0 / 0
// (#) unit tests: 0 / 0 / 3 // (#) unit tests: 0 / 0 / 3
// ----------------------------------------- // -----------------------------------------
//+palette256_get_rgb //+palette256_get_rgb

@ -139,7 +139,7 @@ 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}; use ffi::{cell, ncalign_e, ncplane};
/// Return the column at which 'cols' columns ought start in order to be aligned /// Return the column at which 'cols' columns ought start in order to be aligned
/// according to 'align' within ncplane 'n'. Returns INT_MAX on invalid 'align'. /// according to 'align' within ncplane 'n'. Returns INT_MAX on invalid 'align'.
@ -148,10 +148,14 @@ use ffi::{cell, ncplane, ncalign_e};
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_align(plane: &ncplane, align: ncalign_e, cols: i32) -> i32 { pub fn ncplane_align(plane: &ncplane, align: ncalign_e, cols: i32) -> i32 {
if align == ffi::ncalign_e_NCALIGN_LEFT { return 0; } if align == ffi::ncalign_e_NCALIGN_LEFT {
return 0;
}
let plane_cols = ncplane_dim_x(plane); let plane_cols = ncplane_dim_x(plane);
if cols > plane_cols { return 0; } if cols > plane_cols {
return 0;
}
if align == ffi::ncalign_e_NCALIGN_CENTER { if align == ffi::ncalign_e_NCALIGN_CENTER {
return plane_cols - cols / 2; return plane_cols - cols / 2;
@ -215,11 +219,33 @@ pub fn ncplane_align(plane: &ncplane, align: ncalign_e, cols: i32) -> i32 {
/// minimum box size is 2x2, and it cannot be drawn off-screen. /// minimum box size is 2x2, and it cannot be drawn off-screen.
// TODO: TEST // TODO: TEST
#[inline] #[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 { 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 { unsafe {
let (mut y, mut x) = (0,0); let (mut y, mut x) = (0, 0);
ffi::ncplane_cursor_yx(plane, &mut y, &mut x); 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) ffi::ncplane_box(
plane,
ul,
ur,
ll,
lr,
hline,
vline,
y + ylen - 1,
x + xlen - 1,
ctrlword,
)
} }
} }
@ -250,18 +276,25 @@ pub fn ncplane_dim_y(plane: &ncplane) -> i32 {
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_hline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 { pub fn ncplane_hline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 {
unsafe { unsafe { ffi::ncplane_hline_interp(plane, cell, len, cell.channels, cell.channels) }
ffi::ncplane_hline_interp(plane, cell, len, cell.channels, cell.channels)
}
} }
/// ///
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_perimeter(plane: &mut ncplane, ul: &cell, ur: &cell, ll: &cell, lr: &cell, hline: &cell, vline: &cell, ctlword: u32) -> IntResult { pub fn ncplane_perimeter(
plane: &mut ncplane,
ul: &cell,
ur: &cell,
ll: &cell,
lr: &cell,
hline: &cell,
vline: &cell,
ctlword: u32,
) -> IntResult {
unsafe { unsafe {
ffi::ncplane_cursor_move_yx(plane, 0, 0); ffi::ncplane_cursor_move_yx(plane, 0, 0);
let (mut dimy, mut dimx) = (0,0); let (mut dimy, mut dimx) = (0, 0);
ffi::ncplane_dim_yx(plane, &mut dimy, &mut dimx); ffi::ncplane_dim_yx(plane, &mut dimy, &mut dimx);
ncplane_box_sized(plane, ul, ur, ll, lr, hline, vline, dimy, dimx, ctlword) ncplane_box_sized(plane, ul, ur, ll, lr, hline, vline, dimy, dimx, ctlword)
} }
@ -291,7 +324,6 @@ pub fn ncplane_perimeter(plane: &mut ncplane, ul: &cell, ur: &cell, ll: &cell, l
// return r; // return r;
// } // }
// static inline int // static inline int
// ncplane_perimeter_rounded(struct ncplane* n, uint32_t attrword, // ncplane_perimeter_rounded(struct ncplane* n, uint32_t attrword,
// uint64_t channels, unsigned ctlword){ // uint64_t channels, unsigned ctlword){
@ -316,7 +348,6 @@ pub fn ncplane_perimeter(plane: &mut ncplane, ul: &cell, ur: &cell, ll: &cell, l
// return r; // 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){
@ -519,9 +550,7 @@ pub fn ncplane_putstr(plane: &mut ncplane, _str: &str) -> i32 {
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_vline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 { pub fn ncplane_vline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 {
unsafe { unsafe { ffi::ncplane_vline_interp(plane, cell, len, cell.channels, cell.channels) }
ffi::ncplane_vline_interp(plane, cell, len, cell.channels, cell.channels)
}
} }
// static inline int // static inline int
@ -529,7 +558,6 @@ pub fn ncplane_vline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 {
// return ncplane_vprintf_yx(n, -1, -1, format, ap); // return ncplane_vprintf_yx(n, -1, -1, format, ap);
// } // }
// // 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.
// static inline int // static inline int
@ -564,57 +592,56 @@ pub fn ncplane_vline(plane: &mut ncplane, cell: &cell, len: i32) -> i32 {
// TODO: TEST // TODO: TEST
#[inline] #[inline]
pub fn ncplane_fchannel(plane: &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: &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: &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) })
} }
/// 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: &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: &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: &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: &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: &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) })
} }
/// Extract 24 bits of foreground RGB from a plane, split into components. /// Extract 24 bits of foreground RGB from a plane, split into components.

@ -1,7 +1,6 @@
//! The notcurses types are defined and/or explained here //! The notcurses types are defined and/or explained here
//! //!
/// RGB: 24 bits broken into 3x 8bpp channels. /// RGB: 24 bits broken into 3x 8bpp channels.
/// ///
/// -------- RRRRRRRR GGGGGGGG BBBBBBBB /// -------- RRRRRRRR GGGGGGGG BBBBBBBB
@ -10,7 +9,6 @@
/// ///
pub type Rgb = u32; pub type Rgb = u32;
/// 8 bpp channel /// 8 bpp channel
/// ///
/// CCCCCCCC (1 Byte) /// CCCCCCCC (1 Byte)
@ -185,7 +183,6 @@ pub type GraphemeClusterBackStop = u8;
/// ///
pub type StyleMask = u16; pub type StyleMask = u16;
// Plane: fundamental drawing surface. unites a: // Plane: fundamental drawing surface. unites a:
// //
// - CellMatrix // - CellMatrix
@ -197,7 +194,6 @@ pub type StyleMask = u16;
// //
// type in C: egcpool (struct) // type in C: egcpool (struct)
// CellMatrix: rectilinear array of Cells // CellMatrix: rectilinear array of Cells
// one -- fb per plane, and transients show up ? // one -- fb per plane, and transients show up ?

Loading…
Cancel
Save