Skip to content
/ ask Public

User input convenience functions for console programs

License

Notifications You must be signed in to change notification settings

valderman/ask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sometimes when writing a quick and dirty console program, you may want to ask the user for a bit more structured input than just a plain getLine, but reaching for brick or ncurses is just overkill.

This package is a collection of convenience functions for such occasions.

Example usage:

import Data.Char (toUpper, toLower)
import System.Console.Ask

main = do
  name <- ask (Just "John Doe") "What is your name?"
  name_confirmed <- confirm False ("Is your name *really* " ++ name ++ "?")
  if not name_confirmed
    then putStrLn "OK, let's start over then." >> main
    else greet name

greet name = do
  preferred_name <- chooseOne "Which do you prefer?"
    [ ("Uppercase", map toUpper name)
    , ("Lowercase", map toLower name)
    , ("Neither", name)
    ]
  putStrLn $ "Hello " ++ preferred_name ++ ", nice to meet you!"

About

User input convenience functions for console programs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published