From a7c56236ddce2f0809ce65dd6a05c4949656491f Mon Sep 17 00:00:00 2001 From: Eivind Alexander Bergem Date: Fri, 30 Aug 2024 09:00:34 +0200 Subject: [PATCH] Fixed sub-menu path in prompt --- src/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9dfa62e..326851e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -281,10 +281,15 @@ impl<'a, I, T> PromptIter<'a, I, T> { let state = if newline { PromptIterState::Newline } else { - PromptIterState::Menu(0) + Self::first_menu() }; Self { menu_mgr, state } } + + const fn first_menu() -> PromptIterState { + // Skip the first menu level which is root + PromptIterState::Menu(1) + } } impl<'a, I, T> Iterator for PromptIter<'a, I, T> { @@ -294,11 +299,11 @@ impl<'a, I, T> Iterator for PromptIter<'a, I, T> { loop { match self.state { PromptIterState::Newline => { - self.state = PromptIterState::Menu(0); + self.state = Self::first_menu(); break Some("\n"); } PromptIterState::Menu(i) => { - if i >= self.menu_mgr.depth() { + if i > self.menu_mgr.depth() { self.state = PromptIterState::Arrow; } else { let menu = self.menu_mgr.get_menu(Some(i));