Unixutils-1.36: A crude interface between Haskell and Unix-like operating systems

System.Unix.Progress

Contents

Description

Control the progress reporting and output of subprocesses.

Synopsis

The Progress Monad

type Progress m a = MonadIO m => StateT ProgressState m aSource

A monad for controlling progress reporting of subprocesses.

data ProgressFlag Source

The flags that control what type of output will be sent to stdout and stderr. Also, the ExceptionOnFail flag controls whether an exception will be thrown if the ExitCode is not ExitSuccess.

quietnessLevels :: [Set ProgressFlag] -> Int -> Set ProgressFlagSource

Create a function that returns the flags used for a given quietness level.

runProgressSource

Arguments

:: MonadIO m 
=> (Int -> Set ProgressFlag) 
-> Progress m a

The progress task to be run

-> m a 

Run the Progress monad with the given flags. The flag set is compute from the current quietness level, <= 0 the most verbose and >= 3 the least.

Process launching

Quietness control

defaultQuietness :: MonadIO m => m IntSource

Look for occurrences of -v and -q in the command line arguments and the current values of environment variables VERBOSITY and QUIETNESS to compute a new value for QUIETNESS. If you want to ignore the current QUIETNESS value say setQuietness 0 >> computeQuietness.

modQuietness :: MonadIO m => (Int -> Int) -> m a -> m aSource

Perform a task with the given quietness level.

quieter :: MonadIO m => Int -> m a -> m aSource

Do an IO task with additional -v or -q arguments so that the progress reporting becomes more or less verbose.

Output stream processing

timeTask :: MonadIO m => m a -> m (a, NominalDiffTime)Source

Run a task and return the elapsed time along with its result.

showElapsed :: MonadIO m => String -> m a -> m aSource

Perform a task, print the elapsed time it took, and return the result.

ePutStr :: MonadIO m => String -> m ()Source

Send a string to stderr.

ePutStrLn :: MonadIO m => String -> m ()Source

ePutStr with a terminating newline.

qPutStr :: MonadIO m => String -> m ()Source

If the current quietness level is less than one print a message. Control the quietness level using quieter.

qPutStrLn :: MonadIO m => String -> m ()Source

qPutStr with a terminating newline.

eMessage :: MonadIO m => String -> a -> m aSource

Print a message and return the second argument unevaluated.

eMessageLn :: MonadIO m => String -> a -> m aSource

eMessage with a terminating newline.

qMessage :: MonadIO m => String -> a -> m aSource

eMessage controlled by the quietness level.

qMessageLn :: MonadIO m => String -> a -> m aSource

qMessage with a terminating newline.

Unit tests

tests :: [Test]Source

Unit tests.

A set of lazyCommand functions for an example set of verbosity levels