-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A command-line interface for user input, written in Haskell.
--   
--   Haskeline provides a user interface for line input in command-line
--   programs. This library is similar in purpose to readline, but since it
--   is written in Haskell it is (hopefully) more easily used in other
--   Haskell programs.
--   
--   Haskeline runs both on POSIX-compatible systems and on Windows.
@package haskeline
@version 0.7.2.1


-- | This module provides a low-level API to the line history stored in the
--   <tt>InputT</tt> monad transformer.
--   
--   For most application, it should suffice to instead use the following
--   <tt>Settings</tt> flags:
--   
--   <ul>
--   <li><tt>autoAddHistory</tt>: add nonblank lines to the command history
--   (<a>True</a> by default).</li>
--   <li><tt>historyFile</tt>: read/write the history to a file before and
--   after the line input session.</li>
--   </ul>
--   
--   If you do want custom history behavior, you may need to disable the
--   above default setting(s).
module System.Console.Haskeline.History
data History
emptyHistory :: History
addHistory :: String -> History -> History

-- | Add a line to the history unless it matches the previously recorded
--   line.
addHistoryUnlessConsecutiveDupe :: String -> History -> History

-- | Add a line to the history, and remove all previous entries which are
--   the same as it.
addHistoryRemovingAllDupes :: String -> History -> History

-- | The input lines stored in the history (newest first)
historyLines :: History -> [String]

-- | Reads the line input history from the given file. Returns
--   <a>emptyHistory</a> if the file does not exist or could not be read.
readHistory :: FilePath -> IO History

-- | Writes the line history to the given file. If there is an error when
--   writing the file, it will be ignored.
writeHistory :: FilePath -> History -> IO ()

-- | Limit the number of lines stored in the history.
stifleHistory :: Maybe Int -> History -> History

-- | The maximum number of lines stored in the history. If <a>Nothing</a>,
--   the history storage is unlimited.
stifleAmount :: History -> Maybe Int
instance GHC.Show.Show System.Console.Haskeline.History.History


-- | This module redefines some of the functions in
--   <a>Control.Exception</a> to work for more general monads built on top
--   of <a>IO</a>.
module System.Console.Haskeline.MonadException

-- | An instance of <a>MonadException</a> is generally made up of monad
--   transformers layered on top of the IO monad.
--   
--   The <a>controlIO</a> method enables us to "lift" a function that
--   manages IO actions (such as <a>bracket</a> or <a>catch</a>) into a
--   function that wraps arbitrary monadic actions.
class MonadIO m => MonadException m
controlIO :: MonadException m => (RunIO m -> IO (m a)) -> m a
catch :: (MonadException m, Exception e) => m a -> (e -> m a) -> m a
handle :: (MonadException m, Exception e) => (e -> m a) -> m a -> m a
catches :: (MonadException m) => m a -> [Handler m a] -> m a
data Handler m a
Handler :: (e -> m a) -> Handler m a
finally :: MonadException m => m a -> m b -> m a
throwIO :: (MonadIO m, Exception e) => e -> m a
throwTo :: (MonadIO m, Exception e) => ThreadId -> e -> m ()
bracket :: MonadException m => m a -> (a -> m b) -> (a -> m c) -> m c

-- | Lift a IO operation
--   
--   <pre>
--   wrap :: (a -&gt; IO b) -&gt; IO b
--   </pre>
--   
--   to a more general monadic operation
--   
--   <pre>
--   liftIOOp wrap :: MonadException m =&gt; (a -&gt; m b) -&gt; m b
--   </pre>
--   
--   For example:
--   
--   <pre>
--   <a>liftIOOp</a> (<a>withFile</a> f m) :: MonadException m =&gt; (Handle -&gt; m r) -&gt; m r
--   <a>liftIOOp</a> <a>alloca</a> :: (MonadException m, Storable a) =&gt; (Ptr a -&gt; m b) -&gt; m b
--   <a>liftIOOp</a> (<a>withForeignPtr</a> fp) :: MonadException m =&gt; (Ptr a -&gt; m b) -&gt; m b
--   </pre>
liftIOOp :: MonadException m => ((a -> IO (m b)) -> IO (m c)) -> (a -> m b) -> m c

-- | Lift an IO operation
--   
--   <pre>
--   wrap :: IO a -&gt; IO a
--   </pre>
--   
--   to a more general monadic operation
--   
--   <pre>
--   liftIOOp_ wrap :: MonadException m =&gt; m a -&gt; m a
--   </pre>
liftIOOp_ :: MonadException m => (IO (m a) -> IO (m a)) -> m a -> m a

-- | A <a>RunIO</a> function takes a monadic action <tt>m</tt> as input,
--   and outputs an IO action which performs the underlying impure part of
--   <tt>m</tt> and returns the '<tt>pure'</tt> part of <tt>m</tt>.
--   
--   Note that <tt>(RunIO return)</tt> is an incorrect implementation,
--   since it does not separate the pure and impure parts of the monadic
--   action. This module defines implementations for several common monad
--   transformers.
newtype RunIO m
RunIO :: (forall b. m b -> IO (m b)) -> RunIO m

-- | Any type that you wish to throw or catch as an exception must be an
--   instance of the <tt>Exception</tt> class. The simplest case is a new
--   exception type directly below the root:
--   
--   <pre>
--   data MyException = ThisException | ThatException
--       deriving (Show, Typeable)
--   
--   instance Exception MyException
--   </pre>
--   
--   The default method definitions in the <tt>Exception</tt> class do what
--   we need in this case. You can now throw and catch
--   <tt>ThisException</tt> and <tt>ThatException</tt> as exceptions:
--   
--   <pre>
--   *Main&gt; throw ThisException `catch` \e -&gt; putStrLn ("Caught " ++ show (e :: MyException))
--   Caught ThisException
--   </pre>
--   
--   In more complicated examples, you may wish to define a whole hierarchy
--   of exceptions:
--   
--   <pre>
--   ---------------------------------------------------------------------
--   -- Make the root exception type for all the exceptions in a compiler
--   
--   data SomeCompilerException = forall e . Exception e =&gt; SomeCompilerException e
--       deriving Typeable
--   
--   instance Show SomeCompilerException where
--       show (SomeCompilerException e) = show e
--   
--   instance Exception SomeCompilerException
--   
--   compilerExceptionToException :: Exception e =&gt; e -&gt; SomeException
--   compilerExceptionToException = toException . SomeCompilerException
--   
--   compilerExceptionFromException :: Exception e =&gt; SomeException -&gt; Maybe e
--   compilerExceptionFromException x = do
--       SomeCompilerException a &lt;- fromException x
--       cast a
--   
--   ---------------------------------------------------------------------
--   -- Make a subhierarchy for exceptions in the frontend of the compiler
--   
--   data SomeFrontendException = forall e . Exception e =&gt; SomeFrontendException e
--       deriving Typeable
--   
--   instance Show SomeFrontendException where
--       show (SomeFrontendException e) = show e
--   
--   instance Exception SomeFrontendException where
--       toException = compilerExceptionToException
--       fromException = compilerExceptionFromException
--   
--   frontendExceptionToException :: Exception e =&gt; e -&gt; SomeException
--   frontendExceptionToException = toException . SomeFrontendException
--   
--   frontendExceptionFromException :: Exception e =&gt; SomeException -&gt; Maybe e
--   frontendExceptionFromException x = do
--       SomeFrontendException a &lt;- fromException x
--       cast a
--   
--   ---------------------------------------------------------------------
--   -- Make an exception type for a particular frontend compiler exception
--   
--   data MismatchedParentheses = MismatchedParentheses
--       deriving (Typeable, Show)
--   
--   instance Exception MismatchedParentheses where
--       toException   = frontendExceptionToException
--       fromException = frontendExceptionFromException
--   </pre>
--   
--   We can now catch a <tt>MismatchedParentheses</tt> exception as
--   <tt>MismatchedParentheses</tt>, <tt>SomeFrontendException</tt> or
--   <tt>SomeCompilerException</tt>, but not other types, e.g.
--   <tt>IOException</tt>:
--   
--   <pre>
--   *Main&gt; throw MismatchedParentheses <tt>catch</tt> e -&gt; putStrLn ("Caught " ++ show (e :: MismatchedParentheses))
--   Caught MismatchedParentheses
--   *Main&gt; throw MismatchedParentheses <tt>catch</tt> e -&gt; putStrLn ("Caught " ++ show (e :: SomeFrontendException))
--   Caught MismatchedParentheses
--   *Main&gt; throw MismatchedParentheses <tt>catch</tt> e -&gt; putStrLn ("Caught " ++ show (e :: SomeCompilerException))
--   Caught MismatchedParentheses
--   *Main&gt; throw MismatchedParentheses <tt>catch</tt> e -&gt; putStrLn ("Caught " ++ show (e :: IOException))
--   *** Exception: MismatchedParentheses
--   </pre>
class (Typeable * e, Show e) => Exception e

-- | The <tt>SomeException</tt> type is the root of the exception type
--   hierarchy. When an exception of type <tt>e</tt> is thrown, behind the
--   scenes it is encapsulated in a <tt>SomeException</tt>.
data SomeException :: *
SomeException :: e -> SomeException

-- | Exceptions that occur in the <tt>IO</tt> monad. An
--   <tt>IOException</tt> records a more specific error type, a descriptive
--   string and maybe the handle that was used when the error was flagged.
data IOException :: *
instance System.Console.Haskeline.MonadException.MonadException GHC.Types.IO
instance System.Console.Haskeline.MonadException.MonadException m => System.Console.Haskeline.MonadException.MonadException (Control.Monad.Trans.Reader.ReaderT r m)
instance System.Console.Haskeline.MonadException.MonadException m => System.Console.Haskeline.MonadException.MonadException (Control.Monad.Trans.State.Strict.StateT s m)
instance System.Console.Haskeline.MonadException.MonadException m => System.Console.Haskeline.MonadException.MonadException (Control.Monad.Trans.Maybe.MaybeT m)
instance (System.Console.Haskeline.MonadException.MonadException m, Control.Monad.Trans.Error.Error e) => System.Console.Haskeline.MonadException.MonadException (Control.Monad.Trans.Error.ErrorT e m)
instance System.Console.Haskeline.MonadException.MonadException m => System.Console.Haskeline.MonadException.MonadException (Control.Monad.Trans.List.ListT m)
instance (GHC.Base.Monoid w, System.Console.Haskeline.MonadException.MonadException m) => System.Console.Haskeline.MonadException.MonadException (Control.Monad.Trans.Writer.Lazy.WriterT w m)
instance (GHC.Base.Monoid w, System.Console.Haskeline.MonadException.MonadException m) => System.Console.Haskeline.MonadException.MonadException (Control.Monad.Trans.RWS.Lazy.RWST r w s m)

module System.Console.Haskeline.Completion

-- | Performs completions from the given line state.
--   
--   The first <a>String</a> argument is the contents of the line to the
--   left of the cursor, reversed. The second <a>String</a> argument is the
--   contents of the line to the right of the cursor.
--   
--   The output <a>String</a> is the unused portion of the left half of the
--   line, reversed.
type CompletionFunc m = (String, String) -> m (String, [Completion])
data Completion
Completion :: String -> String -> Bool -> Completion

-- | Text to insert in line.
[replacement] :: Completion -> String

-- | Text to display when listing alternatives.
[display] :: Completion -> String

-- | Whether this word should be followed by a space, end quote, etc.
[isFinished] :: Completion -> Bool

-- | Disable completion altogether.
noCompletion :: Monad m => CompletionFunc m

-- | Create a finished completion out of the given word.
simpleCompletion :: String -> Completion

-- | A custom <a>CompletionFunc</a> which completes the word immediately to
--   the left of the cursor.
--   
--   A word begins either at the start of the line or after an unescaped
--   whitespace character.
completeWord :: Monad m => Maybe Char -> [Char] -> (String -> m [Completion]) -> CompletionFunc m

-- | A custom <a>CompletionFunc</a> which completes the word immediately to
--   the left of the cursor, and takes into account the line contents to
--   the left of the word.
--   
--   A word begins either at the start of the line or after an unescaped
--   whitespace character.
completeWordWithPrev :: Monad m => Maybe Char -> [Char] -> (String -> String -> m [Completion]) -> CompletionFunc m
completeQuotedWord :: Monad m => Maybe Char -> [Char] -> (String -> m [Completion]) -> CompletionFunc m -> CompletionFunc m
completeFilename :: MonadIO m => CompletionFunc m

-- | List all of the files or folders beginning with this path.
listFiles :: MonadIO m => FilePath -> m [Completion]
filenameWordBreakChars :: String
instance GHC.Show.Show System.Console.Haskeline.Completion.Completion
instance GHC.Classes.Ord System.Console.Haskeline.Completion.Completion
instance GHC.Classes.Eq System.Console.Haskeline.Completion.Completion


-- | A rich user interface for line input in command-line programs.
--   Haskeline is Unicode-aware and runs both on POSIX-compatible systems
--   and on Windows.
--   
--   Users may customize the interface with a <tt>~/.haskeline</tt> file;
--   see <a>http://trac.haskell.org/haskeline/wiki/UserPrefs</a> for more
--   information.
--   
--   An example use of this library for a simple read-eval-print loop
--   (REPL) is the following:
--   
--   <pre>
--   import System.Console.Haskeline
--   
--   main :: IO ()
--   main = runInputT defaultSettings loop
--      where 
--          loop :: InputT IO ()
--          loop = do
--              minput &lt;- getInputLine "% "
--              case minput of
--                  Nothing -&gt; return ()
--                  Just "quit" -&gt; return ()
--                  Just input -&gt; do outputStrLn $ "Input was: " ++ input
--                                   loop
--   </pre>
module System.Console.Haskeline

-- | A monad transformer which carries all of the state and settings
--   relevant to a line-reading application.
data InputT m a

-- | Run a line-reading application. This function should suffice for most
--   applications.
--   
--   This function is equivalent to <tt><a>runInputTBehavior</a>
--   <a>defaultBehavior</a></tt>. It uses terminal-style interaction if
--   <a>stdin</a> is connected to a terminal and has echoing enabled.
--   Otherwise (e.g., if <a>stdin</a> is a pipe), it uses file-style
--   interaction.
--   
--   If it uses terminal-style interaction, <a>Prefs</a> will be read from
--   the user's <tt>~/.haskeline</tt> file (if present). If it uses
--   file-style interaction, <a>Prefs</a> are not relevant and will not be
--   read.
runInputT :: MonadException m => Settings m -> InputT m a -> m a

-- | Returns <a>True</a> if the current session uses terminal-style
--   interaction. (See <a>Behavior</a>.)
haveTerminalUI :: Monad m => InputT m Bool

-- | Map a user interaction by modifying the base monad computation.
mapInputT :: (forall b. m b -> m b) -> InputT m a -> InputT m a

-- | Haskeline has two ways of interacting with the user:
--   
--   <ul>
--   <li>"Terminal-style" interaction provides an rich user interface by
--   connecting to the user's terminal (which may be different than
--   <a>stdin</a> or <a>stdout</a>).</li>
--   <li>"File-style" interaction treats the input as a simple stream of
--   characters, for example when reading from a file or pipe. Input
--   functions (e.g., <tt>getInputLine</tt>) print the prompt to
--   <a>stdout</a>.</li>
--   </ul>
--   
--   A <a>Behavior</a> is a method for deciding at run-time which type of
--   interaction to use.
--   
--   For most applications (e.g., a REPL), <a>defaultBehavior</a> should
--   have the correct effect.
data Behavior

-- | Run a line-reading application according to the given behavior.
--   
--   If it uses terminal-style interaction, <a>Prefs</a> will be read from
--   the user's <tt>~/.haskeline</tt> file (if present). If it uses
--   file-style interaction, <a>Prefs</a> are not relevant and will not be
--   read.
runInputTBehavior :: MonadException m => Behavior -> Settings m -> InputT m a -> m a

-- | Read input from <a>stdin</a>. Use terminal-style interaction if
--   <a>stdin</a> is connected to a terminal and has echoing enabled.
--   Otherwise (e.g., if <a>stdin</a> is a pipe), use file-style
--   interaction.
--   
--   This behavior should suffice for most applications.
defaultBehavior :: Behavior

-- | Use file-style interaction, reading input from the given
--   <a>Handle</a>.
useFileHandle :: Handle -> Behavior

-- | Use file-style interaction, reading input from the given file.
useFile :: FilePath -> Behavior

-- | Use terminal-style interaction whenever possible, even if <a>stdin</a>
--   and/or <a>stdout</a> are not terminals.
--   
--   If it cannot open the user's terminal, use file-style interaction,
--   reading input from <a>stdin</a>.
preferTerm :: Behavior

-- | Reads one line of input. The final newline (if any) is removed. When
--   using terminal-style interaction, this function provides a rich
--   line-editing user interface.
--   
--   If <tt><a>autoAddHistory</a> == <a>True</a></tt> and the line input is
--   nonblank (i.e., is not all spaces), it will be automatically added to
--   the history.
getInputLine :: MonadException m => String -> InputT m (Maybe String)

-- | Reads one line of input and fills the insertion space with initial
--   text. When using terminal-style interaction, this function provides a
--   rich line-editing user interface with the added ability to give the
--   user default values.
--   
--   This function behaves in the exact same manner as <a>getInputLine</a>,
--   except that it pre-populates the input area. The text that resides in
--   the input area is given as a 2-tuple with two <a>String</a>s. The
--   string on the left of the tuple (obtained by calling <a>fst</a>) is
--   what will appear to the left of the cursor and the string on the right
--   (obtained by calling <a>snd</a>) is what will appear to the right of
--   the cursor.
--   
--   Some examples of calling of this function are:
--   
--   <pre>
--   getInputLineWithInitial "prompt&gt; " ("left", "") -- The cursor starts at the end of the line.
--   getInputLineWithInitial "prompt&gt; " ("left ", "right") -- The cursor starts before the second word.
--   </pre>
getInputLineWithInitial :: MonadException m => String -> (String, String) -> InputT m (Maybe String)

-- | Reads one character of input. Ignores non-printable characters.
--   
--   When using terminal-style interaction, the character will be read
--   without waiting for a newline.
--   
--   When using file-style interaction, a newline will be read if it is
--   immediately available after the input character.
getInputChar :: MonadException m => String -> InputT m (Maybe Char)

-- | Reads one line of input, without displaying the input while it is
--   being typed. When using terminal-style interaction, the masking
--   character (if given) will replace each typed character.
--   
--   When using file-style interaction, this function turns off echoing
--   while reading the line of input.
getPassword :: MonadException m => Maybe Char -> String -> InputT m (Maybe String)

-- | Write a Unicode string to the user's standard output.
outputStr :: MonadIO m => String -> InputT m ()

-- | Write a string to the user's standard output, followed by a newline.
outputStrLn :: MonadIO m => String -> InputT m ()

-- | Application-specific customizations to the user interface.
data Settings m
Settings :: CompletionFunc m -> Maybe FilePath -> Bool -> Settings m

-- | Custom tab completion.
[complete] :: Settings m -> CompletionFunc m

-- | Where to read/write the history at the start and end of each line
--   input session.
[historyFile] :: Settings m -> Maybe FilePath

-- | If <a>True</a>, each nonblank line returned by <tt>getInputLine</tt>
--   will be automatically added to the history.
[autoAddHistory] :: Settings m -> Bool

-- | A useful default. In particular:
--   
--   <pre>
--   defaultSettings = Settings {
--             complete = completeFilename,
--             historyFile = Nothing,
--             autoAddHistory = True
--             }
--   </pre>
defaultSettings :: MonadIO m => Settings m

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

-- | <a>Prefs</a> allow the user to customize the terminal-style
--   line-editing interface. They are read by default from
--   <tt>~/.haskeline</tt>; to override that behavior, use <a>readPrefs</a>
--   and <tt>runInputTWithPrefs</tt>.
--   
--   Each line of a <tt>.haskeline</tt> file defines one field of the
--   <a>Prefs</a> datatype; field names are case-insensitive and
--   unparseable lines are ignored. For example:
--   
--   <pre>
--   editMode: Vi
--   completionType: MenuCompletion
--   maxhistorysize: Just 40
--   </pre>
data Prefs

-- | Read <a>Prefs</a> from a given file. If there is an error reading the
--   file, the <a>defaultPrefs</a> will be returned.
readPrefs :: FilePath -> IO Prefs

-- | The default preferences which may be overwritten in the
--   <tt>.haskeline</tt> file.
defaultPrefs :: Prefs

-- | Run a line-reading application. Uses <a>defaultBehavior</a> to
--   determine the interaction behavior.
runInputTWithPrefs :: MonadException m => Prefs -> Settings m -> InputT m a -> m a

-- | Run a line-reading application.
runInputTBehaviorWithPrefs :: MonadException m => Behavior -> Prefs -> Settings m -> InputT m a -> m a

-- | Get the current line input history.
getHistory :: MonadIO m => InputT m History

-- | Set the line input history.
putHistory :: MonadIO m => History -> InputT m ()

-- | Change the current line input history.
modifyHistory :: MonadIO m => (History -> History) -> InputT m ()

-- | If Ctrl-C is pressed during the given action, throw an exception of
--   type <a>Interrupt</a>. For example:
--   
--   <pre>
--   tryAction :: InputT IO ()
--   tryAction = handle (\Interrupt -&gt; outputStrLn "Cancelled.")
--                  $ wrapInterrupt $ someLongAction
--   </pre>
--   
--   The action can handle the interrupt itself; a new <a>Interrupt</a>
--   exception will be thrown every time Ctrl-C is pressed.
--   
--   <pre>
--   tryAction :: InputT IO ()
--   tryAction = wrapInterrupt loop
--       where loop = handle (\Interrupt -&gt; outputStrLn "Cancelled; try again." &gt;&gt; loop)
--                      someLongAction
--   </pre>
--   
--   This behavior differs from GHC's built-in Ctrl-C handling, which may
--   immediately terminate the program after the second time that the user
--   presses Ctrl-C.
withInterrupt :: MonadException m => InputT m a -> InputT m a
data Interrupt
Interrupt :: Interrupt

-- | Catch and handle an exception of type <a>Interrupt</a>.
--   
--   <pre>
--   handleInterrupt f = handle $ \Interrupt -&gt; f
--   </pre>
handleInterrupt :: MonadException m => m a -> m a -> m a


-- | This module provides a stateful, IO-based interface to Haskeline,
--   which may be easier to integrate into some existing programs or
--   libraries.
--   
--   It is strongly recommended to use the safer, monadic API of
--   <a>System.Console.Haskeline</a>, if possible, rather than the explicit
--   state management functions of this module.
--   
--   The equivalent REPL example is:
--   
--   <pre>
--   import System.Console.Haskeline
--   import System.Console.Haskeline.IO
--   import Control.Concurrent
--   
--   main = bracketOnError (initializeInput defaultSettings)
--               cancelInput -- This will only be called if an exception such
--                               -- as a SigINT is received.
--               (\hd -&gt; loop hd &gt;&gt; closeInput hd)
--       where
--           loop :: InputState -&gt; IO ()
--           loop hd = do
--               minput &lt;- queryInput hd (getInputLine "% ")
--               case minput of
--                   Nothing -&gt; return ()
--                   Just "quit" -&gt; return ()
--                   Just input -&gt; do queryInput hd $ outputStrLn
--                                       $ "Input was: " ++ input
--                                    loop hd
--   </pre>
module System.Console.Haskeline.IO
data InputState

-- | Initialize a session of line-oriented user interaction.
initializeInput :: Settings IO -> IO InputState

-- | Finish and clean up the line-oriented user interaction session. Blocks
--   on an existing call to <a>queryInput</a>.
closeInput :: InputState -> IO ()

-- | Cancel and clean up the user interaction session. Does not block on an
--   existing call to <a>queryInput</a>.
cancelInput :: InputState -> IO ()

-- | Run one action (for example, <a>getInputLine</a>) as part of a session
--   of user interaction.
--   
--   For example, multiple calls to <a>queryInput</a> using the same
--   <a>InputState</a> will share the same input history. In constrast,
--   multiple calls to <a>runInputT</a> will use distinct histories unless
--   they share the same history file.
--   
--   This function should not be called on a closed or cancelled
--   <a>InputState</a>.
queryInput :: InputState -> InputT IO a -> IO a
