2020-12-24 18:56:12 +00:00
|
|
|
//! based on the proof of concept at ../../src/poc/direct.c
|
|
|
|
|
|
|
|
use libnotcurses_sys::*;
|
2021-06-18 13:52:20 +00:00
|
|
|
use core::convert::TryInto;
|
2020-12-24 18:56:12 +00:00
|
|
|
|
2020-12-25 04:16:34 +00:00
|
|
|
fn main() -> NcResult<()> {
|
2021-05-05 17:33:00 +00:00
|
|
|
let dm = NcDirect::new()?;
|
2020-12-24 18:56:12 +00:00
|
|
|
|
2021-06-18 13:52:20 +00:00
|
|
|
let dimy = dm.dim_y() as i32;
|
|
|
|
let dimx = dm.dim_x() as i32;
|
2020-12-24 18:56:12 +00:00
|
|
|
for _ in 0..dimy {
|
|
|
|
for _ in 0..dimx {
|
|
|
|
printf!("X");
|
|
|
|
}
|
|
|
|
}
|
2021-01-02 21:50:48 +00:00
|
|
|
dm.flush()?;
|
2020-12-24 18:56:12 +00:00
|
|
|
|
2021-01-02 21:50:48 +00:00
|
|
|
dm.set_fg_rgb(0xff8080)?;
|
2020-12-24 18:56:12 +00:00
|
|
|
printf!(" erp erp \n");
|
2021-01-02 21:50:48 +00:00
|
|
|
dm.set_fg_rgb(0x80ff80)?;
|
2020-12-24 18:56:12 +00:00
|
|
|
printf!(" erp erp \n");
|
2021-01-02 21:50:48 +00:00
|
|
|
dm.set_fg_rgb(0xff8080)?;
|
2020-12-24 18:56:12 +00:00
|
|
|
printf!(" erp erp \n");
|
2021-01-02 21:50:48 +00:00
|
|
|
dm.cursor_right(dimx / 2)?;
|
|
|
|
dm.cursor_up(dimy / 2)?;
|
2020-12-24 18:56:12 +00:00
|
|
|
printf!(" erperperp! \n");
|
|
|
|
|
|
|
|
let (mut y, x);
|
|
|
|
|
2021-01-02 21:50:48 +00:00
|
|
|
if let Ok((_y, _x)) = dm.cursor_yx() {
|
2020-12-24 18:56:12 +00:00
|
|
|
y = _y;
|
|
|
|
x = _x;
|
|
|
|
printf!("\n\tRead cursor position: y: %d x: %d\n", y, x);
|
2020-12-25 04:16:34 +00:00
|
|
|
|
2020-12-24 18:56:12 +00:00
|
|
|
y += 2;
|
|
|
|
while y > 3 {
|
|
|
|
let up = if y >= 3 { 3 } else { y };
|
2021-06-18 13:52:20 +00:00
|
|
|
dm.cursor_up(up.try_into().unwrap_or(0))?;
|
2021-01-02 21:50:48 +00:00
|
|
|
dm.flush()?;
|
2020-12-24 18:56:12 +00:00
|
|
|
y -= up;
|
|
|
|
|
|
|
|
let newy;
|
2021-01-02 21:50:48 +00:00
|
|
|
if let Ok((_y, _)) = dm.cursor_yx() {
|
2020-12-24 18:56:12 +00:00
|
|
|
newy = _y;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2020-12-25 04:16:34 +00:00
|
|
|
|
2020-12-24 18:56:12 +00:00
|
|
|
if newy != y {
|
|
|
|
eprintln!("Expected {}, got {}", y, newy);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf!("\n\tRead cursor position: y: %d x: %d\n", newy, x);
|
|
|
|
y += 2;
|
|
|
|
}
|
|
|
|
} else {
|
2020-12-25 16:40:37 +00:00
|
|
|
return Err(NcError::with_msg(-10, "Couldn't read cursor position."));
|
2020-12-24 18:56:12 +00:00
|
|
|
}
|
2020-12-24 23:53:03 +00:00
|
|
|
|
2021-06-18 13:52:20 +00:00
|
|
|
dm.stop()?;
|
2020-12-25 04:16:34 +00:00
|
|
|
Ok(())
|
2020-12-24 18:56:12 +00:00
|
|
|
}
|