Browse Source

Changed menus so they default to the first item

tags/v0.2.2.0
Peter J. Jones 4 years ago
parent
commit
f972d360b3
2 changed files with 3 additions and 3 deletions
  1. 1
    1
      examples/menu.hs
  2. 2
    2
      src/System/Console/Byline/Menu.hs

+ 1
- 1
examples/menu.hs View File

@@ -38,7 +38,7 @@ items = [ Fruit "Watermelon"
main :: IO ()
main = do
let menuConfig = banner "Pick a snack: " $ menu items displayItem
prompt = "pick one> "
prompt = "Which snack? "
onError = "please pick a valid item!" <> fg red

answer <- runByline $ askWithMenuRepeatedly menuConfig prompt onError

+ 2
- 2
src/System/Console/Byline/Menu.hs View File

@@ -174,13 +174,13 @@ askWithMenu :: (MonadIO m)
-> Byline m (Choice a)
askWithMenu m prompt = do
currCompFunc <- Reader.asks compFunc >>= liftIO . readIORef
let firstItem = Text.strip $ renderText Plain (menuItemPrefix m 1)

-- Use the default completion function for menus, but not if another
-- completion function is already active.
withCompletionFunc (fromMaybe (defaultCompFunc m) currCompFunc) $ do
prefixes <- displayMenu
answer <- ask prompt Nothing
answer <- ask prompt (Just firstItem)
return (menuMatcher m m prefixes answer)

where

Loading…
Cancel
Save