rust: replace cell macros with constructors
- add NcCell constructors: new(), new_blank(), with_char() - remove cell initializer macros - update full-basics example - add more doc commentspull/1145/head
parent
58c3d66c15
commit
b64a257ecf
@ -1,61 +0,0 @@
|
|||||||
#[allow(unused_imports)]
|
|
||||||
use crate::{NcCell, NcChannels, NcChar, NcStyleMask};
|
|
||||||
|
|
||||||
// NcCell ------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/// Initializes a cell providing an [`NcChar`],
|
|
||||||
/// a [`NcStyleMask`] and [`NcChannels`]
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! cell_initializer {
|
|
||||||
( $c:expr, $s:expr, $chan:expr ) => {
|
|
||||||
NcCell {
|
|
||||||
gcluster: $c as u32,
|
|
||||||
gcluster_backstop: 0 as NcCharBackstop,
|
|
||||||
reserved: 0,
|
|
||||||
stylemask: $s,
|
|
||||||
channels: $chan,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Initializes a cell providing just an [`NcChar`],
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! cell_char_initializer {
|
|
||||||
( $c:expr ) => {
|
|
||||||
cell_initializer![$c, 0, 0]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Initializes an empty cell
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! cell_trivial_initializer {
|
|
||||||
( ) => {
|
|
||||||
cell_char_initializer![0]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// ncmetric --------------------------------------------------------------------
|
|
||||||
|
|
||||||
// /// Used as arguments to a variable field width (i.e. "%*s" -- these are the *).
|
|
||||||
// ///
|
|
||||||
// /// We need this convoluted grotesquery to properly handle 'µ'.
|
|
||||||
// //
|
|
||||||
// // TODO: TEST
|
|
||||||
// //
|
|
||||||
// // NCMETRICFWIDTH(x, cols) ((int)(strlen(x) - ncstrwidth(x) + (cols)))
|
|
||||||
// #[macro_export]
|
|
||||||
// macro_rules! NCMETRICFWIDTH {
|
|
||||||
// ( $x:expr, $cols:expr ) => {
|
|
||||||
// libc::strlen($x) as i32 - ncstrwidth($x) as i32 + $cols as i32
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Proof of concept as const fn (wont work because strlen call)
|
|
||||||
// pub const unsafe fn NCMETRICFWIDTH(x: i8, cols: usize) -> usize {
|
|
||||||
// libc::strlen(&x) - crate::ncstrwidth(&x) as usize + cols
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #define NCMETRICFWIDTH(x, cols) ((int)(strlen(x) - ncstrwidth(x) + (cols)))
|
|
||||||
// #define PREFIXFMT(x) NCMETRICFWIDTH((x), PREFIXCOLUMNS), (x)
|
|
||||||
// #define IPREFIXFMT(x) NCMETRIXFWIDTH((x), IPREFIXCOLUMNS), (x)
|
|
||||||
// #define BPREFIXFMT(x) NCMETRICFWIDTH((x), BPREFIXCOLUMNS), (x)
|
|
Loading…
Reference in New Issue