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




Functions to manage the verbosity of a console program by storing the quietness level in the system environment, specifically in the $QUIETNESS variable. This lets you avoid creating a StateT monad to hold the quietness level. Note that you don't attach a verbosity level to individual message commands, you control the quietness level for entire regions of your program and messages only appear when quietness is less than one.



eMessage :: MonadIO m => String -> b -> m bSource

eMessageLn :: MonadIO m => String -> b -> m bSource

Get/set quietness levels

initialQuietness :: MonadIO m => m IntSource

Compute an initial value for $QUIETNESS by examining the $QUIETNESS and $VERBOSITY variables and counting the -v and -q options on the command line.

quietness :: MonadIO m => m IntSource

Get the current quietness level from the QUIETNESS environment variable.

Do task with modified quietness level

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

Perform a task with the quietness level tansformed by f. Use defaultQuietness >>= modQuietness . const to initialize the -- verbosity for a program.

quieter' :: MonadIO m => (Int -> Int) -> m a -> m aSource

Dummy version of quieter, sometimes you want to strip out all the quieter calls and see how things look, then restore them gradually. Use this to help remember where they were.

Do a task if quietness < 1

qDo :: MonadIO m => m () -> m ()Source

Peform a task only if quietness < 1.

Output to stderr when quietness < 1

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.

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.

Some idioms

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

Print a message at quietness +1 and then do a task at quietness +3. This is a pattern which gives the following behaviors: Normally there is no output. With -v only the messages are printed. With -v -v the messages and the shell commands are printed with dots to show progress. With -v -v -v everything is printed.

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

v1 :: MonadIO m => m a -> m aSource

v2 :: MonadIO m => m a -> m aSource

v3 :: MonadIO m => m a -> m aSource

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

For debugging