notcurses/rust/examples/direct-cursor.rs

47 lines
1.2 KiB
Rust
Raw Normal View History

2020-11-16 22:53:07 +00:00
//! Example 'direct-cursor'
//!
//! Explore cursor functions in direct mode
//!
use libnotcurses_sys::*;
fn main() {
unsafe {
2020-11-16 22:53:07 +00:00
let ncd = NcDirect::new();
2020-11-16 22:53:07 +00:00
let cols = ncdirect_dim_x(ncd);
let rows = ncdirect_dim_y(ncd);
2020-09-21 18:03:18 +00:00
println!("terminal size (rows, cols): {}, {}", rows, cols);
ncdirect_putstr(ncd, 0, cstring![format!("The current coordinates are")]);
2020-11-16 22:53:07 +00:00
ncdirect_flush(ncd);
for _n in 0..20 {
ncdirect_putstr(ncd, 0, cstring!("."));
ncdirect_flush(ncd);
sleep![50];
}
2020-09-21 18:03:18 +00:00
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"));
2020-11-16 22:53:07 +00:00
ncdirect_flush(ncd);
sleep![600];
2020-09-21 18:03:18 +00:00
ncdirect_clear(ncd);
sleep![1000];
2020-11-16 22:53:07 +00:00
ncdirect_stop(ncd);
}
}