{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, PackageImports, TypeSynonymInstances, UndecidableInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -- |AptIO is an instance of the RWS monad used to manage the global -- state and output style parameters of clients of the Apt library, -- such as the autobuilder. module IO ( countTasks ) where import Control.Monad.State (MonadIO) import System.Process.Progress (ePutStrLn) import Text.Printf (printf) -- | Perform a list of tasks with log messages. countTasks :: MonadIO m => [(String, m a)] -> m [a] countTasks tasks = mapM (countTask (length tasks)) (zip [1..] tasks) where countTask :: MonadIO m => Int -> (Int, (String, m a)) -> m a countTask count (index, (message, task)) = ePutStrLn (printf "[%2d of %2d] %s:" index count message) >> task