You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.5 KiB
Rust
61 lines
1.5 KiB
Rust
//! Example 'direct-cursor'
|
|
//!
|
|
//! Explore cursor functions in direct mode
|
|
//!
|
|
|
|
// utility macro: sleep for $ms milliseconds
|
|
macro_rules! sleep {
|
|
($ms:expr) => {
|
|
std::thread::sleep(std::time::Duration::from_millis($ms));
|
|
};
|
|
}
|
|
|
|
// utility macro: convert the String $s to *mut CString
|
|
macro_rules! cstring {
|
|
($s:expr) => {
|
|
std::ffi::CString::new($s).unwrap().as_ptr();
|
|
}
|
|
}
|
|
|
|
use libnotcurses_sys::*;
|
|
|
|
fn main() {
|
|
unsafe {
|
|
let ncd = NcDirect::new();
|
|
|
|
let cols = ncdirect_dim_x(ncd);
|
|
let rows = ncdirect_dim_y(ncd);
|
|
println!("terminal size (rows, cols): {}, {}", rows, cols);
|
|
|
|
ncdirect_putstr(ncd, 0, cstring![format!("The current coordinates are")]);
|
|
ncdirect_flush(ncd);
|
|
|
|
for _n in 0..20 {
|
|
ncdirect_putstr(ncd, 0, cstring!("."));
|
|
ncdirect_flush(ncd);
|
|
sleep![50];
|
|
}
|
|
|
|
let (mut cy, mut cx) = (0, 0);
|
|
ncdirect_cursor_yx(ncd, &mut cy, &mut cx);
|
|
ncdirect_putstr(ncd, 0, cstring![format!(" ({},{})\n", cy, cx)]);
|
|
sleep![1000];
|
|
|
|
let sentence = vec!["And", "now", "I", "will", "clear", "the", "screen", ".", ".", "."];
|
|
for word in sentence {
|
|
ncdirect_putstr(ncd, 0, cstring!(format!["{} ", word]));
|
|
ncdirect_flush(ncd);
|
|
sleep![200];
|
|
}
|
|
sleep![300];
|
|
ncdirect_putstr(ncd, 0, cstring!("\nbye!\n\n"));
|
|
ncdirect_flush(ncd);
|
|
sleep![600];
|
|
|
|
ncdirect_clear(ncd);
|
|
sleep![1000];
|
|
|
|
ncdirect_stop(ncd);
|
|
}
|
|
}
|