diff --git a/rust/examples/poc-kittyzapper.rs b/rust/examples/poc-kittyzapper.rs new file mode 100644 index 000000000..94921e63b --- /dev/null +++ b/rust/examples/poc-kittyzapper.rs @@ -0,0 +1,22 @@ +//! based on the proof of concept at ../../src/poc/kittyzapper.c + +use libnotcurses_sys::*; + +fn main() { + let ncd = NcDirect::new(); + ncd.fg_rgb8(100, 100, 100); + ncd.bg_rgb8(0xff, 0xff, 0xff); + printf!("a"); + ncd.bg_rgb8(0, 0, 0); + printf!("b"); + printf!(" "); + printf!(" "); + ncd.bg_rgb8(0, 0, 1); + printf!("c"); + printf!(" "); + printf!(" "); + ncd.bg_rgb8(0xff, 0xff, 0xff); + printf!("d"); + printf!("\n"); + ncd.stop(); +} diff --git a/rust/src/direct/methods.rs b/rust/src/direct/methods.rs index 3052fc70d..151f1dbbd 100644 --- a/rust/src/direct/methods.rs +++ b/rust/src/direct/methods.rs @@ -137,7 +137,7 @@ impl NcDirect { /// /// *C style function: [ncdirect_bg_rgb()][crate::ncdirect_bg_rgb].* pub fn bg_rgb8(&mut self, red: NcColor, green: NcColor, blue: NcColor) -> NcResult { - crate::ncdirect_fg_rgb8(self, red, green, blue) + crate::ncdirect_bg_rgb8(self, red, green, blue) } /// Removes the specified styles. diff --git a/rust/src/direct/reimplemented.rs b/rust/src/direct/reimplemented.rs index c61c25ca4..48b1b2456 100644 --- a/rust/src/direct/reimplemented.rs +++ b/rust/src/direct/reimplemented.rs @@ -43,12 +43,8 @@ pub fn ncdirect_fg_rgb8( green: NcColor, blue: NcColor, ) -> NcResult { - unsafe { - crate::ncdirect_fg_rgb( - ncd, - (red as NcRgb) << 16 + (green as NcRgb) << 8 + blue as NcRgb, - ) - } + let rgb = (red as NcRgb) << 16 | (green as NcRgb) << 8 | blue as NcRgb; + unsafe { crate::ncdirect_fg_rgb(ncd, rgb) } } /// Sets the background [NcColor] components. @@ -61,10 +57,6 @@ pub fn ncdirect_bg_rgb8( green: NcColor, blue: NcColor, ) -> NcResult { - unsafe { - crate::ncdirect_bg_rgb( - ncd, - (red as NcRgb) << 16 + (green as NcRgb) << 8 + blue as NcRgb, - ) - } + let rgb = (red as NcRgb) << 16 | (green as NcRgb) << 8 | blue as NcRgb; + unsafe { crate::ncdirect_bg_rgb(ncd, rgb) } } diff --git a/rust/src/macros.rs b/rust/src/macros.rs index fb5502df5..64fe2d459 100644 --- a/rust/src/macros.rs +++ b/rust/src/macros.rs @@ -31,3 +31,11 @@ macro_rules! cstring { std::ffi::CString::new($s).unwrap().as_ptr(); }; } + +/// Simple wrapper around [libc::printf]. +#[macro_export] +macro_rules! printf { + ($s:expr) => { + unsafe { libc::printf(cstring![$s]) } + }; +}