mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
rust: add poc-kittyzapper example
- fix ncdirect_[b|f]g_rgb8 functions. - fix NcDirect.bg_rgb8 method. - new printf![] macro.
This commit is contained in:
parent
3c8328c9cc
commit
a9413eafb2
22
rust/examples/poc-kittyzapper.rs
Normal file
22
rust/examples/poc-kittyzapper.rs
Normal file
@ -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();
|
||||
}
|
@ -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.
|
||||
|
@ -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) }
|
||||
}
|
||||
|
@ -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]) }
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user