prompt-hs: A user-friendly, dependently-typed library for asking your users questions

[ bsd3, cli, library ] [ Propose Tags ] [ Report a vulnerability ]

A library making use of the terminal package to prompt users for answers in a CLI context.

Supports freeform text as well as choices between sum type constructors.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
prod

Enable production defaults

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 1.0.0.0
Change log CHANGELOG.md
Dependencies base (>=4.14.3.0 && <5), microlens (>=0.4.0.1 && <0.5), terminal (>=0.2 && <0.3), text (>=1.2.4.1 && <2.2) [details]
Tested with ghc ==8.10.7, ghc ==9.0.2, ghc ==9.2.8, ghc ==9.4.8, ghc ==9.6.6, ghc ==9.8.4
License BSD-3-Clause
Author notquiteamonad
Maintainer notquiteamonad
Category CLI
Home page https://github.com/notquiteamonad/prompt-hs
Bug tracker https://github.com/notquiteamonad/prompt-hs/issues
Source repo head: git clone https://github.com/notquiteamonad/prompt-hs
Uploaded by notquiteamonad at 2025-03-28T14:16:31Z
Distributions Stackage:1.0.0.0
Downloads 4 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2025-03-28 [all 1 reports]

Readme for prompt-hs-1.0.0.0

[back to package description]

prompt-hs

A user-friendly, dependently-typed library for asking your users questions

Made with nix-bootstrap

Table of Contents

Demo

demo

Click to expand demo source
module Main (main) where

import Data.Proxy (Proxy (Proxy))
import Data.Text (pack, unpack)
import System.Prompt
  ( Chooseable (showChooseable),
    Confirmation (DontConfirm, RequireConfirmation),
    Requirement (Optional, Required),
    promptChoice,
    promptText,
  )

data Colour = Red | Green | Blue deriving (Bounded, Enum, Eq, Show)

instance Chooseable Colour where
  showChooseable = pack . show

main :: IO ()
main = do
  name <- promptText Required RequireConfirmation $ pack "What is your name?"
  favouriteColour <- promptChoice Optional DontConfirm (Proxy :: Proxy Colour) $ pack "And what is your favourite colour?"
  putStrLn $
    "Your name is " <> unpack name <> " and " <> case favouriteColour of
      Just c -> "your favourite colour is " <> show c
      Nothing -> "you didn't tell me your favourite colour."

Usage

  1. Produce an instance of Chooseable for any sum types you want to be able to choose from. For types with Bounded and Enum instances, all you need to provide is how to display the options.
  2. Choose a type of prompt: use promptText for freeform text or promptChoice (or promptChoiceFromSet for more flexible options) to get the user to choose one of many options.
  3. Requirement: is an answer needed, or can the user skip the question? Can be Required or Optional. 4: Confirmation: If RequireConfirmation, get the user to confirm their answers after selecting/typing. Otherwise, accept it immediately and move on.
  4. Give your prompt text.

Note: For Optional questions, the returned value is wrapped in Maybe. For freeform answers, a Just value returned from an Optional question will never be empty.

Development Environment

A development environment is provided:

  1. Install Nix
  2. Run nix develop

Building for Production

To produce a production build as defined in nix/build.nix, run nix build.

This will produce a result directory with built artefacts.