haskeline-class-0.6.2: Class interface for working with Haskeline

PortabilityFlexibleInstances, MultiPatamTypeClasses, UndecidableInstances, GeneralizedNewtypeDeriving
MaintainerAntoine Latter <aslatter@gmail.com>



Haskeline provides all of its functionality within the scope of a monad transformer. This module adds two pieces to this:

  • Introduced here is a type-class which defines the operations supported by the Haskeline monad transformer - MonadHaskeline
  • A newtype wrapper around Haskeline's InputT, called HaskelineT. Sadly, InputT defines ints own instance of the mtl MonadState, which is no good for folks wanting to use InputT in an existing monad transformer stack.

HaskelineT also has an instance of MonadState, but it merely lifts the functions further in the transformer stack.

Large portions of the Haskeline functionality are re-exported here for convinience.



runHaskelineT :: MonadException m => Settings m -> HaskelineT m a -> m aSource

Run a line-reading application, reading user Prefs from ~/.haskeline

data Settings m

Application-specific customizations to the user interface.




complete :: CompletionFunc m

Custom tab completion.

historyFile :: Maybe FilePath

Where to read/write the history at the start and end of each line input session.

autoAddHistory :: Bool

If True, each nonblank line returned by getInputLine will be automatically added to the history.


Monad m => CommandMonad (InputCmdT m) 
Monad m => MonadReader (Settings m) (InputT m) 

defaultSettings :: MonadIO m => Settings m

A useful default. In particular:

 defaultSettings = Settings {
           complete = completeFilename,
           historyFile = Nothing,
           autoAddHistory = True

setComplete :: CompletionFunc m -> Settings m -> Settings m

Because complete is the only field of Settings depending on m, the expression defaultSettings {completionFunc = f} leads to a type error from being too general. This function works around that issue, and may become unnecessary if another field depending on m is added.

data Prefs

Prefs allow the user to customize the terminal-style line-editing interface. They are read by default from ~/.haskeline; to override that behavior, use readPrefs and runInputTWithPrefs.

Each line of a .haskeline file defines one field of the Prefs datatype; field names are case-insensitive and unparseable lines are ignored. For example:

 editMode: Vi
 completionType: MenuCompletion
 maxhistorysize: Just 40


Show Prefs 
Monad m => MonadReader Prefs (InputT m) 
Monad m => CommandMonad (InputCmdT m) 

readPrefs :: FilePath -> IO Prefs

Read Prefs from a given file. If there is an error reading the file, the defaultPrefs will be returned.

defaultPrefs :: Prefs

The default preferences which may be overwritten in the .haskeline file.



:: MonadException m 
=> m a

Handler to run if Ctrl-C is pressed

-> m a

Computation to run

-> m a 

Catch and handle an exception of type Interrupt.