mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
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.
This commit is contained in:
parent
e522429dfb
commit
8e5e60f588
@ -1,19 +1,18 @@
|
|||||||
use libnotcurses_sys::*;
|
use libnotcurses_sys::*;
|
||||||
|
|
||||||
fn main() -> NcResult<()> {
|
fn main() -> NcResult<()> {
|
||||||
unsafe {
|
let nc = Notcurses::new()?;
|
||||||
let nc = Notcurses::new()?;
|
let stdplane = nc.stdplane()?;
|
||||||
let stdplane = notcurses_stdplane(nc);
|
let p1 = NcPlane::new(nc, 0, 0, 20, 30);
|
||||||
|
|
||||||
for ch in "Initializing cells...".chars() {
|
for ch in "Initializing cells...".chars() {
|
||||||
let cell = NcCell::with_char7b(ch);
|
let cell = NcCell::with_char7b(ch);
|
||||||
sleep![60];
|
stdplane.putc(&cell)?;
|
||||||
ncplane_putc(&mut *stdplane, &cell);
|
sleep![0, 40];
|
||||||
let _ = notcurses_render(nc);
|
nc.render()?;
|
||||||
}
|
|
||||||
sleep![900];
|
|
||||||
|
|
||||||
notcurses_stop(nc);
|
|
||||||
}
|
}
|
||||||
|
sleep![0, 900];
|
||||||
|
|
||||||
|
nc.stop()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,10 @@
|
|||||||
use libnotcurses_sys::*;
|
use libnotcurses_sys::*;
|
||||||
|
|
||||||
fn main() -> NcResult<()> {
|
fn main() -> NcResult<()> {
|
||||||
|
// DEBUG
|
||||||
|
let nc = Notcurses::with_debug(NCLOGLEVEL_DEBUG, NCOPTION_NO_ALTERNATE_SCREEN)?;
|
||||||
//let nc = Notcurses::new()?;
|
//let nc = Notcurses::new()?;
|
||||||
let nc = Notcurses::new()?;
|
|
||||||
nc.mouse_enable()?;
|
nc.mouse_enable()?;
|
||||||
|
|
||||||
//let demo_items = vec![
|
//let demo_items = vec![
|
||||||
@ -20,9 +22,7 @@ fn main() -> NcResult<()> {
|
|||||||
NcMenuItem::new("Quit", NcInput::with_ctrl('q')),
|
NcMenuItem::new("Quit", NcInput::with_ctrl('q')),
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut help_items = [
|
let mut help_items = [NcMenuItem::new("About", NcInput::with_ctrl('a'))];
|
||||||
NcMenuItem::new("About", NcInput::with_ctrl('a')),
|
|
||||||
];
|
|
||||||
|
|
||||||
let mut sections = [
|
let mut sections = [
|
||||||
NcMenuSection::new("Schwarzgerät", &mut demo_items, NcInput::with_alt('ä')),
|
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_fg_rgb(0xb0d700);
|
||||||
mopts.section_channels_mut().set_bg_rgb(0x002000);
|
mopts.section_channels_mut().set_bg_rgb(0x002000);
|
||||||
|
|
||||||
let (mut dimy, mut dimx) = (0, 0);
|
let plane = nc.stdplane()?;
|
||||||
let plane = nc.stddim_yx(&mut dimy, &mut dimx)?;
|
let (dim_y, _dim_x) = plane.dim_yx();
|
||||||
let top = NcMenu::new(plane, mopts)?;
|
let top = NcMenu::new(plane, mopts)?;
|
||||||
top.item_set_status("Schwarzgerät", "Disabled", false)?;
|
top.item_set_status("Schwarzgerät", "Disabled", false)?;
|
||||||
top.item_set_status("Schwarzgerät", "Restart", false)?;
|
top.item_set_status("Schwarzgerät", "Restart", false)?;
|
||||||
@ -48,8 +48,19 @@ fn main() -> NcResult<()> {
|
|||||||
channels.set_fg_rgb(0x000088);
|
channels.set_fg_rgb(0x000088);
|
||||||
plane.set_base('x', 0, channels)?;
|
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()?;
|
nc.stop()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -57,5 +68,20 @@ fn main() -> NcResult<()> {
|
|||||||
// fn run_menu(nc: &mut Notcurses, menu: &mut NcMenu) -> NcResult<()> {
|
// fn run_menu(nc: &mut Notcurses, menu: &mut NcMenu) -> NcResult<()> {
|
||||||
// let nopts = NcPlaneOptions::new_aligned(10, NCALIGN_CENTER, 3, 40);
|
// let nopts = NcPlaneOptions::new_aligned(10, NCALIGN_CENTER, 3, 40);
|
||||||
// let selplane = NcPlane::with_options(nc, nopts)?;
|
// 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(())
|
// Ok(())
|
||||||
// }
|
// }
|
||||||
|
@ -433,7 +433,8 @@ impl NcCell {
|
|||||||
/// Loads up six cells with the [NcEgc]s necessary to draw a box.
|
/// 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
|
/// 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].*
|
/// *C style function: [cells_load_box()][crate::cells_load_box].*
|
||||||
pub fn load_box(
|
pub fn load_box(
|
||||||
@ -454,7 +455,7 @@ impl NcCell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// NcCell.[load_box()][NcCell#method.box] with the double box-drawing characters.
|
/// NcCell.[load_box()][NcCell#method.box] with the double box-drawing characters.
|
||||||
///
|
///
|
||||||
/// *C style function: [cells_double_box()][crate::cells_double_box].*
|
/// *C style function: [cells_double_box()][crate::cells_double_box].*
|
||||||
pub fn double_box(
|
pub fn double_box(
|
||||||
plane: &mut NcPlane,
|
plane: &mut NcPlane,
|
||||||
|
@ -88,8 +88,8 @@ pub use reimplemented::*;
|
|||||||
/// spacing glyph, along with possible combining characters, which might span
|
/// spacing glyph, along with possible combining characters, which might span
|
||||||
/// multiple columns).
|
/// multiple columns).
|
||||||
///
|
///
|
||||||
/// An NcCell is bounded to an NcPlane, but the cell doesn't know which plane it is.
|
/// An NcCell is bounded to an NcPlane, but the cell doesn't store anything
|
||||||
/// The extended grapheme information
|
/// about the plane.
|
||||||
///
|
///
|
||||||
/// At any `NcCell`, we can have a theoretically arbitrarily long UTF-8 string,
|
/// At any `NcCell`, we can have a theoretically arbitrarily long UTF-8 string,
|
||||||
/// a foreground color, a background color, and an [`NcStyleMask`] attribute set.
|
/// 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].*
|
/// *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)
|
crate::notcurses_getc_nblocking(self, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,31 +507,31 @@ impl Notcurses {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [notcurses_stdplane()][crate::notcurses_stdplane], plus free bonus
|
// /// [notcurses_stdplane()][crate::notcurses_stdplane], plus free bonus
|
||||||
/// dimensions written to non-NULL y/x!
|
// /// dimensions written to non-NULL y/x!
|
||||||
///
|
// ///
|
||||||
/// *C style function: [notcurses_stddim_yx()][crate::notcurses_stddim_yx].*
|
// /// *C style function: [notcurses_stddim_yx()][crate::notcurses_stddim_yx].*
|
||||||
#[inline]
|
// #[inline]
|
||||||
pub fn stddim_yx<'a>(
|
// pub fn stddim_yx<'a>(
|
||||||
&'a mut self,
|
// &'a mut self,
|
||||||
y: &mut NcDimension,
|
// y: &mut NcDimension,
|
||||||
x: &mut NcDimension,
|
// x: &mut NcDimension,
|
||||||
) -> NcResult<&'a mut NcPlane> {
|
// ) -> NcResult<&'a mut NcPlane> {
|
||||||
crate::notcurses_stddim_yx(self, y, x)
|
// crate::notcurses_stddim_yx(self, y, x)
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// [stdplane_const()][Notcurses#method.stdplane_const], plus free
|
// /// [stdplane_const()][Notcurses#method.stdplane_const], plus free
|
||||||
/// bonus dimensions written to non-NULL y/x!
|
// /// bonus dimensions written to non-NULL y/x!
|
||||||
///
|
// ///
|
||||||
/// *C style function: [notcurses_stddim_yx()][crate::notcurses_stddim_yx].*
|
// /// *C style function: [notcurses_stddim_yx()][crate::notcurses_stddim_yx].*
|
||||||
#[inline]
|
// #[inline]
|
||||||
pub fn stddim_yx_const<'a>(
|
// pub fn stddim_yx_const<'a>(
|
||||||
&'a self,
|
// &'a self,
|
||||||
y: &mut NcDimension,
|
// y: &mut NcDimension,
|
||||||
x: &mut NcDimension,
|
// x: &mut NcDimension,
|
||||||
) -> NcResult<&'a NcPlane> {
|
// ) -> NcResult<&'a NcPlane> {
|
||||||
crate::notcurses_stddim_yx_const(self, y, x)
|
// crate::notcurses_stddim_yx_const(self, y, x)
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// Returns a mutable reference to the standard [NcPlane] for this terminal.
|
/// Returns a mutable reference to the standard [NcPlane] for this terminal.
|
||||||
///
|
///
|
||||||
|
@ -51,14 +51,14 @@
|
|||||||
// functions manually reimplemented: 6
|
// functions manually reimplemented: 6
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
// (+) done: 6 / 0
|
// (+) done: 6 / 0
|
||||||
// (#) test: 0
|
// (#) test: 1
|
||||||
// (W) wrap: 4 / 0
|
// (W) wrap: 4 / 0
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
//W# notcurses_align
|
//W# notcurses_align
|
||||||
//W+ notcurses_getc_blocking
|
|
||||||
//W+ notcurses_getc_nblock
|
//W+ notcurses_getc_nblock
|
||||||
//W+ notcurses_stddim_yx
|
//W+ notcurses_getc_nblocking
|
||||||
//W+ notcurses_stddim_yx_const
|
//~+ notcurses_stddim_yx // multiple mutable references errors
|
||||||
|
//~+ notcurses_stddim_yx_const //
|
||||||
//W+ notcurses_term_dim_yx
|
//W+ notcurses_term_dim_yx
|
||||||
|
|
||||||
#[cfg(test)]
|
#[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.
|
/// Blocks until an event is processed or a signal is received.
|
||||||
///
|
///
|
||||||
/// *Method: Notcurses.[getc_nblocking()][Notcurses#method.getc_nblocking].*
|
/// *Method: Notcurses.[getc_nblocking()][Notcurses#method.getc_nblocking].*
|
||||||
|
// TODO: Option<input>
|
||||||
#[inline]
|
#[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 {
|
unsafe {
|
||||||
let mut sigmask = NcSignalSet::new();
|
let mut sigmask = NcSignalSet::new();
|
||||||
sigmask.emptyset();
|
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);
|
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
|
/// Writes a series of [NcEgc][crate::NcEgc]s to the current location, but
|
||||||
/// retain the styling.
|
/// retain the styling.
|
||||||
/// The current styling of the plane will not be changed.
|
/// 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].*
|
/// *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].*
|
/// *C style function: [ncplane_perimeter_rounded()][crate::ncplane_perimeter_rounded].*
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// (X) wont: 6
|
// (X) wont: 6
|
||||||
// (D) depr: 4
|
// (D) depr: 4
|
||||||
// (#) test: 13
|
// (#) test: 13
|
||||||
// (W) wrap: 77 of 98
|
// (W) wrap: 79 of 98
|
||||||
// -------------------------------------------
|
// -------------------------------------------
|
||||||
//W ncpile_bottom
|
//W ncpile_bottom
|
||||||
//W# ncpile_create
|
//W# ncpile_create
|
||||||
@ -63,9 +63,9 @@
|
|||||||
// X ncplane_putegc_yx // unneeded
|
// X ncplane_putegc_yx // unneeded
|
||||||
// ncplane_putnstr_aligned
|
// ncplane_putnstr_aligned
|
||||||
// ncplane_putnstr_yx
|
// ncplane_putnstr_yx
|
||||||
// ncplane_putstr_aligned
|
//W ncplane_putstr_aligned
|
||||||
// ncplane_putstr_stained
|
//W ncplane_putstr_stained
|
||||||
// ncplane_putstr_yx
|
//W ncplane_putstr_yx
|
||||||
// ncplane_puttext
|
// ncplane_puttext
|
||||||
// X ncplane_putwegc_stained // unneeded
|
// X ncplane_putwegc_stained // unneeded
|
||||||
// X ncplane_putwstr_stained // unneeded
|
// X ncplane_putwstr_stained // unneeded
|
||||||
|
Loading…
Reference in New Issue
Block a user