notcurses/rust/examples/poc-direct.rs

69 lines
1.6 KiB
Rust
Raw Normal View History

//! based on the proof of concept at ../../src/poc/direct.c
use libnotcurses_sys::*;
fn main() {
let ncd = NcDirect::new();
let dimy = ncd.dim_y();
let dimx = ncd.dim_x();
for _ in 0..dimy {
for _ in 0..dimx {
printf!("X");
}
}
ncd.flush();
let mut ret = 0;
ret |= ncd.fg_rgb(0xff8080);
ret |= ncd.styles_on(NCSTYLE_STANDOUT);
printf!(" erp erp \n");
ret |= ncd.fg_rgb(0x80ff80);
printf!(" erp erp \n");
ret |= ncd.styles_off(NCSTYLE_STANDOUT);
printf!(" erp erp \n");
ret |= ncd.fg_rgb(0xff8080);
printf!(" erp erp \n");
ret |= ncd.cursor_right(dimx / 2);
ret |= ncd.cursor_up(dimy / 2);
printf!(" erperperp! \n");
let (mut y, x);
if let Some((_y, _x)) = ncd.cursor_yx() {
y = _y;
x = _x;
printf!("\n\tRead cursor position: y: %d x: %d\n", y, x);
y += 2;
while y > 3 {
ret = NCRESULT_ERR;
let up = if y >= 3 { 3 } else { y };
if ncd.cursor_up(up) == NCRESULT_ERR {
break;
}
ncd.flush();
y -= up;
let newy;
if let Some((_y, _)) = ncd.cursor_yx() {
newy = _y;
} else {
break;
}
if newy != y {
eprintln!("Expected {}, got {}", y, newy);
break;
}
printf!("\n\tRead cursor position: y: %d x: %d\n", newy, x);
y += 2;
ret = NCRESULT_OK;
}
} else {
ret = NCRESULT_ERR - 10;
}
// println!("ret={}", ret); // DEBUG
ncd.stop();
}