byline- Library for creating command-line interfaces (colors, menus, etc.)

Safe HaskellNone



Functions and types for working with menus.



data Menu a Source #

Opaque type representing a menu containing items of type a.

data Choice a Source #

A type representing the choice made by a user while working with a menu.



Menu has no items to choose from.

Match a

User picked a menu item.

Other Text

User entered text that doesn't match an item.


Show a => Show (Choice a) Source # 


showsPrec :: Int -> Choice a -> ShowS #

show :: Choice a -> String #

showList :: [Choice a] -> ShowS #

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: ") "

matcher :: Matcher a -> Menu a -> Menu a Source #

Change the Matcher function. The matcher function should compare the user's input to the menu items and their assigned prefix values and return a Choice.

askWithMenu Source #


:: MonadIO m 
=> Menu a

The Menu to display.

-> Stylized

The prompt.

-> Byline m (Choice a) 

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 Menu to display.

-> 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.