2012-04-27 13:23:52 -04:00
|
|
|
{- git-annex Messages data types
|
|
|
|
-
|
2018-02-19 14:03:23 -04:00
|
|
|
- Copyright 2012-2018 Joey Hess <id@joeyh.name>
|
2012-04-27 13:23:52 -04:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2015-11-04 16:19:00 -04:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2012-04-27 13:23:52 -04:00
|
|
|
module Types.Messages where
|
|
|
|
|
2016-09-09 18:13:55 -04:00
|
|
|
import qualified Data.Aeson as Aeson
|
2015-04-03 19:56:56 -04:00
|
|
|
|
2017-05-11 17:33:18 -04:00
|
|
|
import Control.Concurrent
|
2015-11-04 16:19:00 -04:00
|
|
|
#ifdef WITH_CONCURRENTOUTPUT
|
|
|
|
import System.Console.Regions (ConsoleRegion)
|
|
|
|
#endif
|
|
|
|
|
2018-02-19 14:03:23 -04:00
|
|
|
data OutputType = NormalOutput | QuietOutput | JSONOutput JSONOptions
|
2015-11-04 16:19:00 -04:00
|
|
|
deriving (Show)
|
2012-04-27 13:23:52 -04:00
|
|
|
|
2018-02-19 14:03:23 -04:00
|
|
|
data JSONOptions = JSONOptions
|
|
|
|
{ jsonProgress :: Bool
|
2018-02-19 14:28:17 -04:00
|
|
|
, jsonErrorMessages :: Bool
|
2018-02-19 14:03:23 -04:00
|
|
|
}
|
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
adjustOutputType :: OutputType -> OutputType -> OutputType
|
|
|
|
adjustOutputType (JSONOutput old) (JSONOutput new) = JSONOutput $ JSONOptions
|
|
|
|
{ jsonProgress = jsonProgress old || jsonProgress new
|
2018-02-19 14:28:17 -04:00
|
|
|
, jsonErrorMessages = jsonErrorMessages old || jsonErrorMessages new
|
2018-02-19 14:03:23 -04:00
|
|
|
}
|
|
|
|
adjustOutputType _old new = new
|
|
|
|
|
2012-04-27 13:23:52 -04:00
|
|
|
data SideActionBlock = NoBlock | StartBlock | InBlock
|
2012-11-25 17:54:08 -04:00
|
|
|
deriving (Eq)
|
2012-04-27 13:23:52 -04:00
|
|
|
|
|
|
|
data MessageState = MessageState
|
|
|
|
{ outputType :: OutputType
|
2016-09-09 12:57:42 -04:00
|
|
|
, concurrentOutputEnabled :: Bool
|
2012-04-27 13:23:52 -04:00
|
|
|
, sideActionBlock :: SideActionBlock
|
2016-01-20 14:07:13 -04:00
|
|
|
, implicitMessages :: Bool
|
2015-11-06 12:51:25 -04:00
|
|
|
#ifdef WITH_CONCURRENTOUTPUT
|
2015-11-04 16:19:00 -04:00
|
|
|
, consoleRegion :: Maybe ConsoleRegion
|
|
|
|
, consoleRegionErrFlag :: Bool
|
2015-11-06 12:51:25 -04:00
|
|
|
#endif
|
2016-09-09 18:13:55 -04:00
|
|
|
, jsonBuffer :: Maybe Aeson.Object
|
2017-05-11 17:33:18 -04:00
|
|
|
, promptLock :: MVar () -- left full when not prompting
|
2012-04-27 13:23:52 -04:00
|
|
|
}
|
|
|
|
|
2017-05-11 17:33:18 -04:00
|
|
|
newMessageState :: IO MessageState
|
|
|
|
newMessageState = do
|
|
|
|
promptlock <- newMVar ()
|
|
|
|
return $ MessageState
|
2015-11-06 12:51:25 -04:00
|
|
|
{ outputType = NormalOutput
|
2016-09-09 12:57:42 -04:00
|
|
|
, concurrentOutputEnabled = False
|
2015-11-06 12:51:25 -04:00
|
|
|
, sideActionBlock = NoBlock
|
2016-01-20 14:07:13 -04:00
|
|
|
, implicitMessages = True
|
2015-11-06 12:51:25 -04:00
|
|
|
#ifdef WITH_CONCURRENTOUTPUT
|
|
|
|
, consoleRegion = Nothing
|
|
|
|
, consoleRegionErrFlag = False
|
|
|
|
#endif
|
2016-09-09 18:13:55 -04:00
|
|
|
, jsonBuffer = Nothing
|
2017-05-11 17:33:18 -04:00
|
|
|
, promptLock = promptlock
|
2015-11-06 12:51:25 -04:00
|
|
|
}
|