Copyright | This 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. |
---|---|
License | BSD-2-Clause |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data Menu a
- menu :: ToStylizedText a => NonEmpty a -> Menu a
- menuBanner :: ToStylizedText b => b -> Menu a -> Menu a
- menuPrefix :: (Int -> Stylized Text) -> Menu a -> Menu a
- menuSuffix :: Stylized Text -> Menu a -> Menu a
- type FromChoice a = Menu a -> Map Text a -> Text -> Choice a
- menuFromChoiceFunc :: FromChoice a -> Menu a -> Menu a
- askWithMenu :: (MonadByline m, ToStylizedText a, ToStylizedText b) => Menu a -> b -> m (Choice a)
- askWithMenuRepeatedly :: (MonadByline m, ToStylizedText a, ToStylizedText b, ToStylizedText e) => Menu a -> b -> e -> m a
- data Choice a
- module Byline
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
Opaque type representing a menu containing items of type a
.
Since: 1.0.0.0
Instances
Foldable Menu Source # | |
Defined in Byline.Menu 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 # elem :: Eq a => a -> Menu a -> Bool # maximum :: Ord 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
:: (MonadByline m, ToStylizedText a, ToStylizedText b) | |
=> Menu a | The |
-> b | The prompt. |
-> m (Choice a) | The |
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 #
:: (MonadByline m, ToStylizedText a, ToStylizedText b, ToStylizedText e) | |
=> Menu a | The |
-> b | The prompt. |
-> e | Error message when the user tried to select a non-menu item. |
-> m a | The |
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
A type representing the choice made by a user while working with a menu.
Since: 1.0.0.0
Instances
Functor Choice Source # | |
Foldable Choice Source # | |
Defined in Byline.Menu 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 # elem :: Eq a => a -> Choice a -> Bool # maximum :: Ord a => Choice a -> a # minimum :: Ord a => Choice a -> a # | |
Traversable Choice Source # | |
Eq a => Eq (Choice a) Source # | |
Show a => Show (Choice a) Source # | |
Re-exports
module Byline