You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
notcurses/rust/examples/poc-menu.rs

88 lines
2.5 KiB
Rust

//! based on the proof of concept at ../../src/poc/menu.c
use libnotcurses_sys::*;
fn main() -> NcResult<()> {
// DEBUG
let nc = Notcurses::with_debug(NCLOGLEVEL_DEBUG, NCOPTION_NO_ALTERNATE_SCREEN)?;
//let nc = Notcurses::new()?;
nc.mouse_enable()?;
//let demo_items = vec![
let mut demo_items = [
NcMenuItem::new("Restart", NcInput::with_ctrl('r')),
NcMenuItem::new("Disabled", NcInput::with_ctrl('d')),
];
let mut file_items = [
NcMenuItem::new("New", NcInput::with_ctrl('n')),
NcMenuItem::new("Open", NcInput::with_ctrl('o')),
NcMenuItem::new("Close", NcInput::with_ctrl('c')),
NcMenuItem::new_empty(),
NcMenuItem::new("Quit", NcInput::with_ctrl('q')),
];
let mut help_items = [NcMenuItem::new("About", NcInput::with_ctrl('a'))];
let mut sections = [
NcMenuSection::new("Schwarzgerät", &mut demo_items, NcInput::with_alt('ä')),
NcMenuSection::new("File", &mut file_items, NcInput::with_alt('f')),
//NcMenuSection::new_empty(),
NcMenuSection::new("Help", &mut help_items, NcInput::with_alt('h')),
];
let mut mopts = NcMenuOptions::new(&mut sections);
mopts.header_channels_mut().set_fg_rgb(0x00ff00);
mopts.header_channels_mut().set_bg_rgb(0x440000);
mopts.section_channels_mut().set_fg_rgb(0xb0d700);
mopts.section_channels_mut().set_bg_rgb(0x002000);
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)?;
let mut channels: NcChannelPair = 0;
channels.set_fg_rgb(0x88aa00);
channels.set_fg_rgb(0x000088);
plane.set_base('x', 0, channels)?;
// 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(())
}
// 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(())
// }