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

CopyrightThis file is part of the package byline. It is subject to the
license terms in the LICENSE file found in the top-level
directory of this distribution and at:

https://github.com/pjones/byline

No part of this package including this file may be copied
modified propagated or distributed except according to the
terms contained in the LICENSE file.
LicenseBSD-2-Clause
Safe HaskellNone
LanguageHaskell2010

Byline.Menu

Contents

Description

 
Synopsis

Menus with Tab Completion

Menus are used to provide the user with a choice of acceptable values. Each choice is labeled to make it easier for a user to select it, or the user may enter text that does not correspond to any of the menus items.

For an example see the menu.hs file in the examples directory.

Building a Menu

data Menu a Source #

Opaque type representing a menu containing items of type a.

Since: 1.0.0.0

Instances
Foldable Menu Source # 
Instance details

Defined in Byline.Menu

Methods

fold :: Monoid m => Menu m -> m #

foldMap :: Monoid m => (a -> m) -> Menu a -> m #

foldr :: (a -> b -> b) -> b -> Menu a -> b #

foldr' :: (a -> b -> b) -> b -> Menu a -> b #

foldl :: (b -> a -> b) -> b -> Menu a -> b #

foldl' :: (b -> a -> b) -> b -> Menu a -> b #

foldr1 :: (a -> a -> a) -> Menu a -> a #

foldl1 :: (a -> a -> a) -> Menu a -> a #

toList :: Menu a -> [a] #

null :: Menu a -> Bool #

length :: Menu a -> Int #

elem :: Eq a => a -> Menu a -> Bool #

maximum :: Ord a => Menu a -> a #

minimum :: Ord a => Menu a -> a #

sum :: Num a => Menu a -> a #

product :: Num a => Menu a -> a #

menu :: ToStylizedText a => NonEmpty a -> Menu a Source #

Create a Menu by giving a list of menu items and a function that can convert those items into stylized text.

Since: 1.0.0.0

menuBanner :: ToStylizedText b => b -> Menu a -> Menu a Source #

Change the banner of a menu. The banner is printed just before the menu items are displayed.

Since: 1.0.0.0

menuPrefix :: (Int -> Stylized Text) -> 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.

Since: 1.0.0.0

menuSuffix :: Stylized Text -> 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: ") "

Since: 1.0.0.0

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

Since: 1.0.0.0

menuFromChoiceFunc :: FromChoice a -> Menu a -> Menu a Source #

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

Since: 1.0.0.0

Prompting with a Menu

askWithMenu Source #

Arguments

:: (MonadByline m, ToStylizedText a, ToStylizedText b) 
=> Menu a

The Menu to display.

-> b

The prompt.

-> m (Choice a)

The Choice the user selected.

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.

Since: 1.0.0.0

askWithMenuRepeatedly Source #

Arguments

:: (MonadByline m, ToStylizedText a, ToStylizedText b, ToStylizedText e) 
=> Menu a

The Menu to display.

-> b

The prompt.

-> e

Error message when the user tried to select a non-menu item.

-> m a

The Choice the user selected.

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.

Since: 1.0.0.0

data Choice a Source #

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

Since: 1.0.0.0

Constructors

Match a

User picked a menu item.

Other Text

User entered text that doesn't match an item.

Instances
Functor Choice Source # 
Instance details

Defined in Byline.Menu

Methods

fmap :: (a -> b) -> Choice a -> Choice b #

(<$) :: a -> Choice b -> Choice a #

Foldable Choice Source # 
Instance details

Defined in Byline.Menu

Methods

fold :: Monoid m => Choice m -> m #

foldMap :: Monoid m => (a -> m) -> Choice a -> m #

foldr :: (a -> b -> b) -> b -> Choice a -> b #

foldr' :: (a -> b -> b) -> b -> Choice a -> b #

foldl :: (b -> a -> b) -> b -> Choice a -> b #

foldl' :: (b -> a -> b) -> b -> Choice a -> b #

foldr1 :: (a -> a -> a) -> Choice a -> a #

foldl1 :: (a -> a -> a) -> Choice a -> a #

toList :: Choice a -> [a] #

null :: Choice a -> Bool #

length :: Choice a -> Int #

elem :: Eq a => a -> Choice a -> Bool #

maximum :: Ord a => Choice a -> a #

minimum :: Ord a => Choice a -> a #

sum :: Num a => Choice a -> a #

product :: Num a => Choice a -> a #

Traversable Choice Source # 
Instance details

Defined in Byline.Menu

Methods

traverse :: Applicative f => (a -> f b) -> Choice a -> f (Choice b) #

sequenceA :: Applicative f => Choice (f a) -> f (Choice a) #

mapM :: Monad m => (a -> m b) -> Choice a -> m (Choice b) #

sequence :: Monad m => Choice (m a) -> m (Choice a) #

Eq a => Eq (Choice a) Source # 
Instance details

Defined in Byline.Menu

Methods

(==) :: Choice a -> Choice a -> Bool #

(/=) :: Choice a -> Choice a -> Bool #

Show a => Show (Choice a) Source # 
Instance details

Defined in Byline.Menu

Methods

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

show :: Choice a -> String #

showList :: [Choice a] -> ShowS #

Re-exports

module Byline