2020-11-16 22:53:07 +00:00
|
|
|
//! Example 'direct-cursor'
|
|
|
|
//!
|
|
|
|
//! Explore cursor functions in direct mode
|
|
|
|
//!
|
|
|
|
|
2021-01-01 20:47:41 +00:00
|
|
|
use rand::{thread_rng, Rng};
|
|
|
|
|
2020-11-16 22:53:07 +00:00
|
|
|
use libnotcurses_sys::*;
|
2020-08-20 16:02:00 +00:00
|
|
|
|
2020-12-25 04:16:34 +00:00
|
|
|
fn main() -> NcResult<()> {
|
2021-01-01 20:47:41 +00:00
|
|
|
let mut rng = thread_rng();
|
|
|
|
|
2021-05-05 17:33:00 +00:00
|
|
|
let mut dm = NcDirect::new()?;
|
2020-12-26 04:14:27 +00:00
|
|
|
|
2021-01-02 21:50:48 +00:00
|
|
|
let cols = dm.dim_x();
|
|
|
|
let rows = dm.dim_y();
|
2020-12-26 04:14:27 +00:00
|
|
|
println!("terminal size (rows, cols): {}, {}", rows, cols);
|
|
|
|
|
2021-01-02 18:45:15 +00:00
|
|
|
let mut channels =
|
|
|
|
NcChannelPair::combine(NcChannel::with_rgb(0xAA2244), NcChannel::with_rgb(0x112233));
|
2021-01-02 21:50:48 +00:00
|
|
|
dm.putstr(channels, "The current coordinates are")?;
|
2020-12-26 04:14:27 +00:00
|
|
|
|
|
|
|
for _n in 0..40 {
|
2021-01-02 21:50:48 +00:00
|
|
|
fsleep![&mut dm, 0, 30];
|
2021-01-01 20:47:41 +00:00
|
|
|
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),
|
|
|
|
);
|
2021-01-02 21:50:48 +00:00
|
|
|
dm.putstr(channels, ".")?;
|
2020-12-26 04:14:27 +00:00
|
|
|
}
|
|
|
|
|
2021-01-02 21:50:48 +00:00
|
|
|
let (cy, cx) = dm.cursor_yx()?;
|
|
|
|
dm.putstr(channels, &format!(" ({},{})\n", cy, cx))?;
|
2020-12-26 04:14:27 +00:00
|
|
|
sleep![1];
|
|
|
|
|
2021-01-02 18:45:15 +00:00
|
|
|
let sentence = vec![
|
|
|
|
"And", "now", "I", "will", "clear", "the", "screen", ".", ".", ".",
|
|
|
|
];
|
2020-12-26 04:14:27 +00:00
|
|
|
for word in sentence {
|
2021-01-01 20:47:41 +00:00
|
|
|
channels.set_fg_rgb(channels.fg_rgb().wrapping_sub(0x050505));
|
|
|
|
channels.set_bg_rgb(channels.bg_rgb().wrapping_add(0x090909));
|
2021-01-02 21:50:48 +00:00
|
|
|
dm.putstr(channels, &format!["{} ", word])?;
|
|
|
|
fsleep![&mut dm, 0, 150];
|
2020-08-20 16:02:00 +00:00
|
|
|
}
|
2020-12-26 04:14:27 +00:00
|
|
|
sleep![0, 300];
|
2021-01-01 20:47:41 +00:00
|
|
|
channels.set_fg_rgb(0xFFFFFF);
|
|
|
|
channels.set_bg_default();
|
2021-01-02 21:50:48 +00:00
|
|
|
dm.putstr(channels, "\nbye!\n\n")?;
|
|
|
|
fsleep![&mut dm, 0, 600];
|
|
|
|
dm.clear()?;
|
2020-12-25 04:16:34 +00:00
|
|
|
Ok(())
|
2020-08-20 16:02:00 +00:00
|
|
|
}
|