diff --git a/rust/Cargo.toml b/rust/Cargo.toml index f3e42c104..d081bc2f7 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -20,8 +20,8 @@ categories = [ keywords = ["tui", "cli", "terminal", "ncurses", "ffi"] [dependencies] -libc = {version = "0.2.80", default-features = false} -cty = "0.2.1" +libc = {version = ">= 0.2.80", default-features = false} +cty = ">= 0.2.1" [build-dependencies] bindgen = ">= 0.55.1" @@ -30,3 +30,7 @@ pkg-config = ">= 0.3.18" [dev-dependencies] serial_test = ">= 0.5.0" serial_test_derive = ">= 0.5.0" + +# for the examples +rand = ">= 0.8" + diff --git a/rust/examples/direct-cursor.rs b/rust/examples/direct-cursor.rs index 2a7929438..17bc6f2e8 100644 --- a/rust/examples/direct-cursor.rs +++ b/rust/examples/direct-cursor.rs @@ -3,9 +3,13 @@ //! Explore cursor functions in direct mode //! +use rand::{thread_rng, Rng}; + use libnotcurses_sys::*; fn main() -> NcResult<()> { + let mut rng = thread_rng(); + let ncd = NcDirect::new()?; let cols = ncd.dim_x(); @@ -14,12 +18,22 @@ fn main() -> NcResult<()> { let mut channels = NcChannelPair::combine( NcChannel::with_rgb(0xAA2244), - NcChannel::with_rgb(0x114433), + NcChannel::with_rgb(0x112233), ); ncd.putstr(channels, "The current coordinates are")?; for _n in 0..40 { fsleep![ncd, 0, 30]; + channels.set_fg_rgb8( + rng.gen_range(0x66..=0xEE), + rng.gen_range(0x66..=0xEE), + rng.gen_range(0x66..=0xEE), + ); + channels.set_bg_rgb8( + rng.gen_range(0..=0x9), + rng.gen_range(0..=0x9), + rng.gen_range(0..=0x9), + ); ncd.putstr(channels, ".")?; } @@ -29,16 +43,18 @@ fn main() -> NcResult<()> { let sentence = vec!["And", "now", "I", "will", "clear", "the", "screen", ".", ".", "."]; for word in sentence { - ncd.putstr(0, &format!["{} ", word])?; + channels.set_fg_rgb(channels.fg_rgb().wrapping_sub(0x050505)); + channels.set_bg_rgb(channels.bg_rgb().wrapping_add(0x090909)); + ncd.putstr(channels, &format!["{} ", word])?; fsleep![ncd, 0, 150]; } sleep![0, 300]; - ncd.putstr(0, "\nbye!\n\n")?; + channels.set_fg_rgb(0xFFFFFF); + channels.set_bg_default(); + ncd.putstr(channels, "\nbye!\n\n")?; fsleep![ncd, 0, 600]; - ncd.clear()?; - sleep![1]; - + sleep![2]; ncd.stop()?; Ok(()) }