chatty-0.5.4.0: Some monad transformers and typeclasses to simplify I/O on a transformer stack.

Safe HaskellSafe-Inferred

Text.Chatty.Printer

Description

Provides a typeclass for all monads that may print text.

Synopsis

Documentation

class Monad m => MonadPrinter m whereSource

A typeclass for all monads that may output strings.

Methods

mprint :: String -> m ()Source

Just print it!

mnoecho :: String -> m ()Source

Print it, except you are IO.

mflush :: m ()Source

Flush the buffer.

mnomask :: String -> m ()Source

Alternative to mprint that does not mask any characters (depends on the carrier).

newtype DeafT m a Source

DeafT discards all output (much like >/dev/null in the shell)

Constructors

Deaf 

Fields

runDeafT :: m a
 

newtype OutRedirT m a Source

Redirects all output to a given handle (much like >filename in the shell)

Constructors

OutRedir 

Fields

runOutRedirT' :: Handle -> m (a, Handle)
 

type OutRedir = OutRedirT IOSource

OutRedirT on a blank IO monad

runOutRedirT :: Functor m => OutRedirT m a -> Handle -> m aSource

Run OutRedirT with a Handle

newtype RecorderT m a Source

Catches all output (much like VAR=$(...) in the shell)

Constructors

Recorder 

Fields

runRecorderT' :: [String] -> m (a, [String])
 

newtype Replayable Source

The recorder state. Use this together with replay, replayM or replay_.

Constructors

Replayable [String] 

replayM :: Monad m => m Replayable -> m StringSource

Replay a recorder state inside a Monad.

replay :: Replayable -> StringSource

Replay a recorder state in a pure context.

replay_ :: Monad m => RecorderT m StringSource

Replay the current recorder state without leaving the recorder.

runRecorder :: Recorder a -> (a, Replayable)Source

Run Recorder and also return its state.

runRecorderT :: (Functor m, Monad m) => RecorderT m a -> m (a, Replayable)Source

Run RecorderT and also return its state.

mprintLn :: MonadPrinter m => String -> m ()Source

Line-terminating alternative to mprint

mnomaskLn :: MonadPrinter m => String -> m ()Source

Line-terminating alternative to mnomask

data DiscardO Source

Redirection target that discards input.

Constructors

DiscardO 

data RecordO Source

Redirection target that records input.

Constructors

RecordO 

class RedirectionTarget t mt a r | t -> mt, t a -> r whereSource

Class for all redirection targets.

Methods

(.>.) :: (Functor m, MonadIO m, MonadPrinter (mt m)) => mt m a -> t -> m rSource

Overwriting redirection.

(.>>.) :: (Functor m, MonadIO m, MonadPrinter (mt m)) => mt m a -> t -> m rSource

Appending redirection.