git-annex/Types/Messages.hs

58 lines
1.5 KiB
Haskell
Raw Normal View History

{- git-annex Messages data types
-
- Copyright 2012-2018 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Types.Messages where
import qualified Utility.Aeson as Aeson
2015-04-03 23:56:56 +00:00
import Control.Concurrent
import System.Console.Regions (ConsoleRegion)
data OutputType = NormalOutput | QuietOutput | JSONOutput JSONOptions
deriving (Show)
data JSONOptions = JSONOptions
{ jsonProgress :: Bool
, jsonErrorMessages :: Bool
}
deriving (Show)
adjustOutputType :: OutputType -> OutputType -> OutputType
adjustOutputType (JSONOutput old) (JSONOutput new) = JSONOutput $ JSONOptions
{ jsonProgress = jsonProgress old || jsonProgress new
, jsonErrorMessages = jsonErrorMessages old || jsonErrorMessages new
}
adjustOutputType _old new = new
data SideActionBlock = NoBlock | StartBlock | InBlock
deriving (Eq)
data MessageState = MessageState
{ outputType :: OutputType
, concurrentOutputEnabled :: Bool
, sideActionBlock :: SideActionBlock
, implicitMessages :: Bool
, consoleRegion :: Maybe ConsoleRegion
, consoleRegionErrFlag :: Bool
, jsonBuffer :: Maybe Aeson.Object
, promptLock :: MVar () -- left full when not prompting
}
newMessageState :: IO MessageState
newMessageState = do
promptlock <- newMVar ()
return $ MessageState
2015-11-06 16:51:25 +00:00
{ outputType = NormalOutput
, concurrentOutputEnabled = False
2015-11-06 16:51:25 +00:00
, sideActionBlock = NoBlock
, implicitMessages = True
2015-11-06 16:51:25 +00:00
, consoleRegion = Nothing
, consoleRegionErrFlag = False
, jsonBuffer = Nothing
, promptLock = promptlock
2015-11-06 16:51:25 +00:00
}