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-07-09 09:33:23 +00:00
|
|
|
let ncd = NcDirect::new()?;
|
2020-12-26 04:14:27 +00:00
|
|
|
|
2021-07-09 09:33:23 +00:00
|
|
|
let cols = ncd.dim_x();
|
|
|
|
let rows = ncd.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 =
|
2021-06-16 22:00:31 +00:00
|
|
|
NcChannels::combine(NcChannel::from_rgb(0xAA2244), NcChannel::from_rgb(0x112233));
|
2021-07-09 09:33:23 +00:00
|
|
|
ncd.putstr(channels, "The current coordinates are")?;
|
2020-12-26 04:14:27 +00:00
|
|
|
|
|
|
|
for _n in 0..40 {
|
2021-07-09 09:33:23 +00:00
|
|
|
ncd.flush()?;
|
|
|
|
sleep![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-07-09 09:33:23 +00:00
|
|
|
ncd.putstr(channels, ".")?;
|
2020-12-26 04:14:27 +00:00
|
|
|
}
|
|
|
|
|
2021-07-09 09:33:23 +00:00
|
|
|
let (cy, cx) = ncd.cursor_yx()?;
|
|
|
|
ncd.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-07-09 09:33:23 +00:00
|
|
|
ncd.putstr(channels, &format!["{} ", word])?;
|
|
|
|
ncd.flush()?;
|
|
|
|
sleep![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-07-09 09:33:23 +00:00
|
|
|
ncd.putstr(channels, "\nbye!\n\n")?;
|
|
|
|
ncd.flush()?;
|
|
|
|
sleep![0, 600];
|
|
|
|
ncd.clear()?;
|
2020-12-25 04:16:34 +00:00
|
|
|
Ok(())
|
2020-08-20 16:02:00 +00:00
|
|
|
}
|