Safe Haskell | None |
---|---|
Language | Haskell2010 |
Functions and types for working with menus.
Synopsis
- data Menu a
- data Choice a
- type Matcher a = Menu a -> Map Text a -> Text -> Choice a
- menu :: [a] -> (a -> Stylized) -> Menu a
- banner :: Stylized -> Menu a -> Menu a
- prefix :: (Int -> Stylized) -> Menu a -> Menu a
- suffix :: Stylized -> Menu a -> Menu a
- matcher :: Matcher a -> Menu a -> Menu a
- askWithMenu :: MonadIO m => Menu a -> Stylized -> Byline m (Choice a)
- askWithMenuRepeatedly :: MonadIO m => Menu a -> Stylized -> Stylized -> Byline m (Choice a)
Documentation
A type representing the choice made by a user while working with a menu.
type Matcher a = Menu a -> Map Text a -> Text -> Choice a Source #
A function that is given the input from a user while working in a
menu and should translate that into a Choice
.
The Map
contains the menu item indexes/prefixes (numbers or
letters) and the items themselves.
The default matcher function allows the user to select a menu item by typing its index or part of its textual representation. As long as input from the user is a unique prefix of one of the menu items then that item will be returned.
menu :: [a] -> (a -> Stylized) -> Menu a Source #
Create a Menu
by giving a list of menu items and a function
that can convert those items into stylized text.
banner :: Stylized -> Menu a -> Menu a Source #
Change the banner of a menu. The banner is printed just before the menu items are displayed.
prefix :: (Int -> Stylized) -> Menu a -> Menu a Source #
Change the prefix function. The prefix function should generate unique, stylized text that the user can use to select a menu item. The default prefix function numbers the menu items starting with 1.
suffix :: Stylized -> Menu a -> Menu a Source #
Change the menu item suffix. It is displayed directly after the menu item prefix and just before the menu item itself.
Default: ") "
Ask the user to choose an item from a menu. The menu will only
be shown once and the user's choice will be returned in a Choice
value.
If you want to force the user to only choose from the displayed
menu items you should use askWithMenuRepeatedly
instead.
askWithMenuRepeatedly Source #
:: MonadIO m | |
=> Menu a | The |
-> Stylized | The prompt. |
-> Stylized | Error message. |
-> Byline m (Choice a) |
Like askWithMenu
except that arbitrary input is not allowed.
If the user doesn't correctly select a menu item then the menu will
be repeated and an error message will be displayed.