rust: Continue with poc-menu example.

- add NcPlane.pustr_aligned() method.
- disable notcurses_stddim_yx* functions & methods for now.
- make input argument optional for notcurses_getc_nblocking().
- update full-basics example.
- fix comments.
pull/1270/head
joseLuís 4 years ago
parent e522429dfb
commit 8e5e60f588

@ -1,19 +1,18 @@
use libnotcurses_sys::*;
fn main() -> NcResult<()> {
unsafe {
let nc = Notcurses::new()?;
let stdplane = notcurses_stdplane(nc);
let stdplane = nc.stdplane()?;
let p1 = NcPlane::new(nc, 0, 0, 20, 30);
for ch in "Initializing cells...".chars() {
let cell = NcCell::with_char7b(ch);
sleep![60];
ncplane_putc(&mut *stdplane, &cell);
let _ = notcurses_render(nc);
stdplane.putc(&cell)?;
sleep![0, 40];
nc.render()?;
}
sleep![900];
sleep![0, 900];
notcurses_stop(nc);
}
nc.stop()?;
Ok(())
}

@ -3,8 +3,10 @@
use libnotcurses_sys::*;
fn main() -> NcResult<()> {
// DEBUG
let nc = Notcurses::with_debug(NCLOGLEVEL_DEBUG, NCOPTION_NO_ALTERNATE_SCREEN)?;
//let nc = Notcurses::new()?;
let nc = Notcurses::new()?;
nc.mouse_enable()?;
//let demo_items = vec![
@ -20,9 +22,7 @@ fn main() -> NcResult<()> {
NcMenuItem::new("Quit", NcInput::with_ctrl('q')),
];
let mut help_items = [
NcMenuItem::new("About", NcInput::with_ctrl('a')),
];
let mut help_items = [NcMenuItem::new("About", NcInput::with_ctrl('a'))];
let mut sections = [
NcMenuSection::new("Schwarzgerät", &mut demo_items, NcInput::with_alt('ä')),
@ -37,8 +37,8 @@ fn main() -> NcResult<()> {
mopts.section_channels_mut().set_fg_rgb(0xb0d700);
mopts.section_channels_mut().set_bg_rgb(0x002000);
let (mut dimy, mut dimx) = (0, 0);
let plane = nc.stddim_yx(&mut dimy, &mut dimx)?;
let plane = nc.stdplane()?;
let (dim_y, _dim_x) = plane.dim_yx();
let top = NcMenu::new(plane, mopts)?;
top.item_set_status("Schwarzgerät", "Disabled", false)?;
top.item_set_status("Schwarzgerät", "Restart", false)?;
@ -48,8 +48,19 @@ fn main() -> NcResult<()> {
channels.set_fg_rgb(0x000088);
plane.set_base('x', 0, channels)?;
//nc.render()?;
// FIXME sometimes fails and sometimes does not.
nc.render()?;
sleep![1]; // DEBUG
plane.set_fg_rgb(0x00dddd);
plane.putstr_aligned(
dim_y - 1,
NCALIGN_RIGHT,
" -=+ menu poc. press q to exit +=-",
)?;
top.destroy()?; // DEBUG
nc.stop()?;
Ok(())
}
@ -57,5 +68,20 @@ fn main() -> NcResult<()> {
// fn run_menu(nc: &mut Notcurses, menu: &mut NcMenu) -> NcResult<()> {
// let nopts = NcPlaneOptions::new_aligned(10, NCALIGN_CENTER, 3, 40);
// let selplane = NcPlane::with_options(nc, nopts)?;
//
// //...
//
// let mut ni = NcInput::new();
// let mut keypress = u32;
//
// loop {
// keypress = nc.getc_blocking(Some(&mut ni));
// if keypress as u32 == -1 { break; }
//
// if !ncm
// }
//
// //...
//
// Ok(())
// }

@ -433,7 +433,8 @@ impl NcCell {
/// Loads up six cells with the [NcEgc]s necessary to draw a box.
///
/// On error, any [NcCell]s this function might have loaded before the error
/// are [cell_release]d. There must be at least six [NcEgc]s in `gcluster`.
/// are [release][NcCell#method.release]d.
/// There must be at least six [NcEgc]s in `gcluster`.
///
/// *C style function: [cells_load_box()][crate::cells_load_box].*
pub fn load_box(

@ -88,8 +88,8 @@ pub use reimplemented::*;
/// spacing glyph, along with possible combining characters, which might span
/// multiple columns).
///
/// An NcCell is bounded to an NcPlane, but the cell doesn't know which plane it is.
/// The extended grapheme information
/// An NcCell is bounded to an NcPlane, but the cell doesn't store anything
/// about the plane.
///
/// At any `NcCell`, we can have a theoretically arbitrarily long UTF-8 string,
/// a foreground color, a background color, and an [`NcStyleMask`] attribute set.

@ -331,7 +331,7 @@ impl Notcurses {
///
/// *C style function: [notcurses_getc_nblocking()][crate::notcurses_getc_nblocking].*
pub fn getc_nblocking(&mut self, input: &mut NcInput) -> char {
pub fn getc_nblocking(&mut self, input: Option<&mut NcInput>) -> char {
crate::notcurses_getc_nblocking(self, input)
}
@ -507,31 +507,31 @@ impl Notcurses {
}
}
/// [notcurses_stdplane()][crate::notcurses_stdplane], plus free bonus
/// dimensions written to non-NULL y/x!
///
/// *C style function: [notcurses_stddim_yx()][crate::notcurses_stddim_yx].*
#[inline]
pub fn stddim_yx<'a>(
&'a mut self,
y: &mut NcDimension,
x: &mut NcDimension,
) -> NcResult<&'a mut NcPlane> {
crate::notcurses_stddim_yx(self, y, x)
}
/// [stdplane_const()][Notcurses#method.stdplane_const], plus free
/// bonus dimensions written to non-NULL y/x!
///
/// *C style function: [notcurses_stddim_yx()][crate::notcurses_stddim_yx].*
#[inline]
pub fn stddim_yx_const<'a>(
&'a self,
y: &mut NcDimension,
x: &mut NcDimension,
) -> NcResult<&'a NcPlane> {
crate::notcurses_stddim_yx_const(self, y, x)
}
// /// [notcurses_stdplane()][crate::notcurses_stdplane], plus free bonus
// /// dimensions written to non-NULL y/x!
// ///
// /// *C style function: [notcurses_stddim_yx()][crate::notcurses_stddim_yx].*
// #[inline]
// pub fn stddim_yx<'a>(
// &'a mut self,
// y: &mut NcDimension,
// x: &mut NcDimension,
// ) -> NcResult<&'a mut NcPlane> {
// crate::notcurses_stddim_yx(self, y, x)
// }
// /// [stdplane_const()][Notcurses#method.stdplane_const], plus free
// /// bonus dimensions written to non-NULL y/x!
// ///
// /// *C style function: [notcurses_stddim_yx()][crate::notcurses_stddim_yx].*
// #[inline]
// pub fn stddim_yx_const<'a>(
// &'a self,
// y: &mut NcDimension,
// x: &mut NcDimension,
// ) -> NcResult<&'a NcPlane> {
// crate::notcurses_stddim_yx_const(self, y, x)
// }
/// Returns a mutable reference to the standard [NcPlane] for this terminal.
///

@ -51,14 +51,14 @@
// functions manually reimplemented: 6
// -----------------------------------------
// (+) done: 6 / 0
// (#) test: 0
// (#) test: 1
// (W) wrap: 4 / 0
// -----------------------------------------
//W# notcurses_align
//W+ notcurses_getc_blocking
//W+ notcurses_getc_nblock
//W+ notcurses_stddim_yx
//W+ notcurses_stddim_yx_const
//W+ notcurses_getc_nblocking
//~+ notcurses_stddim_yx // multiple mutable references errors
//~+ notcurses_stddim_yx_const //
//W+ notcurses_term_dim_yx
#[cfg(test)]

@ -55,12 +55,19 @@ pub fn notcurses_getc_nblock(nc: &mut Notcurses, input: &mut NcInput) -> char {
/// Blocks until an event is processed or a signal is received.
///
/// *Method: Notcurses.[getc_nblocking()][Notcurses#method.getc_nblocking].*
// TODO: Option<input>
#[inline]
pub fn notcurses_getc_nblocking(nc: &mut Notcurses, input: &mut NcInput) -> char {
pub fn notcurses_getc_nblocking(nc: &mut Notcurses, input: Option<&mut NcInput>) -> char {
let input_ptr;
if let Some(i) = input {
input_ptr = i as *mut _;
} else {
input_ptr = null_mut();
}
unsafe {
let mut sigmask = NcSignalSet::new();
sigmask.emptyset();
core::char::from_u32_unchecked(crate::notcurses_getc(nc, null(), &mut sigmask, input))
core::char::from_u32_unchecked(crate::notcurses_getc(nc, null(), &mut sigmask, input_ptr))
}
}

@ -732,6 +732,19 @@ impl NcPlane {
return Ok(cols);
}
/// Same as [putstr_yx()][NcPlane#method.putstr_yx] but [NcAlign]ed on x.
///
/// *C style function: [ncplane_putstr_aligned()][crate::ncplane_putstr_aligned].*
pub fn putstr_aligned(
&mut self,
y: NcDimension,
align: NcAlign,
string: &str,
) -> NcResult<NcDimension> {
let res = unsafe { crate::ncplane_putstr_aligned(self, y as i32, align, cstring![string]) };
error![res, res as NcDimension]
}
/// Writes a series of [NcEgc][crate::NcEgc]s to the current location, but
/// retain the styling.
/// The current styling of the plane will not be changed.
@ -1466,7 +1479,7 @@ impl NcPlane {
)]
}
/// NcPlane.[perimeter()][NcDirect#method.perimeter] with the double box-drawing characters.
/// NcPlane.[perimeter()][NcPlane#method.perimeter] with the double box-drawing characters.
///
/// *C style function: [ncplane_perimeter_double()][crate::ncplane_perimeter_double].*
@ -1482,7 +1495,7 @@ impl NcPlane {
)]
}
/// NcPlane.[perimeter()][NcDirect#method.perimeter] with the rounded box-drawing characters.
/// NcPlane.[perimeter()][NcPlane#method.perimeter] with the rounded box-drawing characters.
///
///
/// *C style function: [ncplane_perimeter_rounded()][crate::ncplane_perimeter_rounded].*

@ -5,7 +5,7 @@
// (X) wont: 6
// (D) depr: 4
// (#) test: 13
// (W) wrap: 77 of 98
// (W) wrap: 79 of 98
// -------------------------------------------
//W ncpile_bottom
//W# ncpile_create
@ -63,9 +63,9 @@
// X ncplane_putegc_yx // unneeded
// ncplane_putnstr_aligned
// ncplane_putnstr_yx
// ncplane_putstr_aligned
// ncplane_putstr_stained
// ncplane_putstr_yx
//W ncplane_putstr_aligned
//W ncplane_putstr_stained
//W ncplane_putstr_yx
// ncplane_puttext
// X ncplane_putwegc_stained // unneeded
// X ncplane_putwstr_stained // unneeded

Loading…
Cancel
Save