diff --git a/rust/examples/full-input.rs b/rust/examples/full-input.rs index 76569069a..63cb5f08b 100644 --- a/rust/examples/full-input.rs +++ b/rust/examples/full-input.rs @@ -18,7 +18,7 @@ fn main() -> NcResult<()> { println!("Exit with F1\n"); - let mut input = NcInput::new(); + let mut input = NcInput::new_empty(); loop { let key = notcurses_getc_nblock(nc, &mut input); diff --git a/rust/examples/poc-menu.rs b/rust/examples/poc-menu.rs index 47b78064a..63236c9ee 100644 --- a/rust/examples/poc-menu.rs +++ b/rust/examples/poc-menu.rs @@ -79,7 +79,7 @@ fn run_menu(nc: &mut Notcurses, menu: &mut NcMenu) -> NcResult<()> { channels.set_bg_rgb(0x88aa00); selplane.set_base(' ', 0, channels)?; - let mut ni = NcInput::new(); + let mut ni = NcInput::new_empty(); let mut keypress: char; // FIXME: screen updates one keypress later. @@ -102,11 +102,15 @@ fn run_menu(nc: &mut Notcurses, menu: &mut NcMenu) -> NcResult<()> { } } } - selplane.erase(); - // let mut selni = NcInput::new(); - // BUG FIXME: - // let selitem = menu.selected(Some(&mut selni))?; - // selplane.putstr_aligned(1, NCALIGN_CENTER, &selitem)?; + + let mut selni = NcInput::new_empty(); + // if let Some(selitem) = menu.selected(Some(&mut selni)) { + // selplane.putstr_aligned(1, NCALIGN_CENTER, &selitem)?; + // } else { + // // DEBUG + // selplane.putstr_aligned(1, NCALIGN_CENTER, "nothing opened")?; + // } + nc.render()?; } } diff --git a/rust/src/input/mod.rs b/rust/src/input/mod.rs index c5df86836..8b81810d3 100644 --- a/rust/src/input/mod.rs +++ b/rust/src/input/mod.rs @@ -53,7 +53,7 @@ pub const fn ncinput_equal_p(n1: NcInput, n2: NcInput) -> bool { /// New NcInput. impl NcInput { /// New empty NcInput. - pub const fn new() -> NcInput { + pub const fn new_empty() -> NcInput { NcInput { id: 0, y: 0, @@ -65,6 +65,26 @@ impl NcInput { } } + /// New NcInput. + pub const fn new(id: char) -> NcInput { + Self::with_all_args(id, None, None, false, false, false, 0) + } + + /// New NcInput with alt key. + pub const fn with_alt(id: char) -> NcInput { + Self::with_all_args(id, None, None, true, false, false, 0) + } + + /// New NcInput with shift key. + pub const fn with_shift(id: char) -> NcInput { + Self::with_all_args(id, None, None, false, true, false, 0) + } + + /// New NcInput with ctrl key. + pub const fn with_ctrl(id: char) -> NcInput { + Self::with_all_args(id, None, None, false, false, true, 0) + } + /// New NcInput, expecting all the arguments. pub const fn with_all_args( id: char, @@ -97,21 +117,6 @@ impl NcInput { seqnum, } } - - /// New NcInput with alt key. - pub const fn with_alt(id: char) -> NcInput { - Self::with_all_args(id, None, None, true, false, false, 0) - } - - /// New NcInput with shift key. - pub const fn with_shift(id: char) -> NcInput { - Self::with_all_args(id, None, None, false, true, false, 0) - } - - /// New NcInput with ctrl key. - pub const fn with_ctrl(id: char) -> NcInput { - Self::with_all_args(id, None, None, false, false, true, 0) - } } /// Is this [char] a Supplementary Private Use Area-B codepoint? diff --git a/rust/src/widgets/menu/methods/mod.rs b/rust/src/widgets/menu/methods/mod.rs index 49d17d3e8..1db3108ea 100644 --- a/rust/src/widgets/menu/methods/mod.rs +++ b/rust/src/widgets/menu/methods/mod.rs @@ -27,7 +27,7 @@ impl NcMenuItem { pub fn new_empty() -> Self { Self { desc: null_mut(), - shortcut: NcInput::new(), + shortcut: NcInput::new_empty(), } } } @@ -60,7 +60,7 @@ impl NcMenuSection { name: null_mut(), items: null_mut(), itemcount: 0, - shortcut: NcInput::new(), + shortcut: NcInput::new_empty(), } } }